MessageHandler.c 684 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382
  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[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_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 ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  73. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  74. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  75. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  76. static int TransactionMessageAttemptsValue = 0;
  77. static int TransactionMessageRetryIntervalValue = 0;
  78. static int TempMeterValueInterval = 0;
  79. static struct OCPPAuthLocalElemet
  80. {
  81. int listVersionInt;
  82. char idTagstr[20];
  83. char parentIdTag[20];
  84. char expiryDate[30];
  85. char idTagstatus[16];
  86. }idTagQuery;
  87. //=============================================
  88. // OCPP HeartBeat Response Not Receive Counts
  89. //============================================
  90. static int HeartBeatWithNOResponse = 0;
  91. static int HeartBeatCountPerHour = 0;
  92. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  93. extern int GetTransactionQueueNum(void);
  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[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  112. unsigned int StartTransaction;
  113. unsigned int StopTransaction;
  114. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  115. }clientTime;
  116. typedef union
  117. {
  118. //Operations Initiated by Central System
  119. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_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. }
  1892. //==========================================
  1893. // Init all share memory
  1894. //==========================================
  1895. int InitShareMemory()
  1896. {
  1897. int result = PASS;
  1898. int MeterSMId;
  1899. //creat ShmSysConfigAndInfo
  1900. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1901. {
  1902. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1903. result = FAIL;
  1904. }
  1905. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1906. {
  1907. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1908. result = FAIL;
  1909. }
  1910. else
  1911. {}
  1912. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1913. {
  1914. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1915. result = FAIL;
  1916. }
  1917. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1918. {
  1919. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1920. result = FAIL;
  1921. }
  1922. else
  1923. {}
  1924. //creat ShmPsuData
  1925. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1926. {
  1927. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1928. result = FAIL;
  1929. }
  1930. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1931. {
  1932. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1933. result = FAIL;
  1934. }
  1935. else
  1936. {}
  1937. //creat ShmOCPP16Data
  1938. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1939. {
  1940. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1941. result = FAIL;
  1942. }
  1943. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1944. {
  1945. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1946. result = FAIL;
  1947. }
  1948. else
  1949. {}
  1950. /****************************** For Initial Settings************************************************/
  1951. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1952. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1953. // allocate Configuration memory address
  1954. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1955. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1956. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1957. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1958. //offline MeterValue Interval
  1959. TempMeterValueInterval = 0;
  1960. return result;
  1961. }
  1962. int ProcessShareMemory()
  1963. {
  1964. if(InitShareMemory() == FAIL)
  1965. {
  1966. DEBUG_ERROR("InitShareMemory NG\n");
  1967. if(ShmStatusCodeData!=NULL)
  1968. {
  1969. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1970. }
  1971. sleep(5);
  1972. return FAIL;
  1973. }
  1974. return PASS;
  1975. }
  1976. //---------------------common routine---------------------------//
  1977. int isOFFline(void)
  1978. {
  1979. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1980. {
  1981. if(TempMeterValueInterval >= 2 )
  1982. {
  1983. TempMeterValueInterval = 0;
  1984. return TRUE;
  1985. }
  1986. else
  1987. {
  1988. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1989. return FALSE;
  1990. }
  1991. }
  1992. else
  1993. {
  1994. return FALSE;
  1995. }
  1996. }
  1997. //---------------------------------------------
  1998. // new:
  1999. // enum SYSTEM_STATUS
  2000. // {
  2001. // SYS_MODE_BOOTING = 0,
  2002. // SYS_MODE_IDLE = 1,
  2003. // SYS_MODE_AUTHORIZING = 2,
  2004. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2005. // SYS_MODE_REASSIGN = 4,
  2006. // SYS_MODE_PREPARING = 5,
  2007. // SYS_MODE_PREPARE_FOR_EV = 6,
  2008. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2009. // SYS_MODE_CHARGING = 8,
  2010. // SYS_MODE_TERMINATING = 9,
  2011. // SYS_MODE_COMPLETE = 10,
  2012. // SYS_MODE_ALARM = 11,
  2013. // SYS_MODE_FAULT = 12,
  2014. // SYS_MODE_RESERVATION = 13,
  2015. // SYS_MODE_BOOKING = 14,
  2016. // SYS_MODE_MAINTAIN = 15,
  2017. // SYS_MODE_DEBUG = 16,
  2018. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2019. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2020. // SYS_MODE_UPDATE = 19
  2021. // };
  2022. //
  2023. //
  2024. //-----------------------------------------
  2025. void CheckSystemValue(void)
  2026. {
  2027. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2028. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2029. char filenmae[100]={0};
  2030. char str[100]={0};
  2031. int tempIndex = 0;
  2032. //===============================
  2033. // send Heartbeat
  2034. //===============================
  2035. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2036. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2037. {
  2038. clientTime.Heartbeat=time((time_t*)NULL);
  2039. if(server_sign == TRUE)
  2040. {
  2041. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2042. }
  2043. else
  2044. {
  2045. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2046. }
  2047. }
  2048. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2049. {
  2050. //parameter for test
  2051. sendHeartbeatRequest(0);
  2052. //==============================================
  2053. // Reset Waiting Time
  2054. //==============================================
  2055. clientTime.Heartbeat=time((time_t*)NULL);
  2056. HeartBeatWithNOResponse = 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. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2095. }
  2096. //==============================================
  2097. // Charger start transaction
  2098. //==============================================
  2099. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2100. {
  2101. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2102. sendStartTransactionRequest(gun_index);
  2103. clientTime.StartTransaction = time((time_t*)NULL);
  2104. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2105. }
  2106. //==============================================
  2107. // Charger stop transaction
  2108. //==============================================
  2109. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2110. {
  2111. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2112. sendStopTransactionRequest(gun_index);
  2113. clientTime.StopTransaction = time((time_t*)NULL);
  2114. }
  2115. //==============================================
  2116. // Charger status report
  2117. //==============================================
  2118. //--- Check Mode Change ---//
  2119. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2120. if(gunType[gun_index] == 'J')
  2121. {
  2122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2123. {
  2124. tempIndex = ((gun_index==2) ? 1: 0);
  2125. }
  2126. else
  2127. {
  2128. tempIndex = gun_index;
  2129. }
  2130. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2131. {
  2132. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2133. {
  2134. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2135. {
  2136. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2137. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2138. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2139. statusModeChage[gun_index] = TRUE;
  2140. }
  2141. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2142. {
  2143. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2144. if((access(filenmae,F_OK))!=-1)
  2145. {
  2146. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2147. sprintf(str,"rm -f %s",filenmae);
  2148. system(str);
  2149. }
  2150. }
  2151. #if 1 // for TempStopTransaction
  2152. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2153. {
  2154. checkTempStopTransaction(gun_index);
  2155. }
  2156. #endif
  2157. }
  2158. }
  2159. }
  2160. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2161. {
  2162. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2163. {
  2164. tempIndex = ((gun_index==2) ? 1: 0);
  2165. }
  2166. else
  2167. {
  2168. tempIndex = gun_index;
  2169. }
  2170. for (int index = 0; index < CCS_QUANTITY; index++)
  2171. {
  2172. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2173. {
  2174. 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]*/ )
  2175. {
  2176. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2177. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2178. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2179. statusModeChage[gun_index] = TRUE;
  2180. }
  2181. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2182. {
  2183. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2184. if((access(filenmae,F_OK))!=-1)
  2185. {
  2186. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2187. sprintf(str,"rm -f %s",filenmae);
  2188. system(str);
  2189. }
  2190. }
  2191. #if 1 // for TempStopTransaction
  2192. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2193. {
  2194. checkTempStopTransaction(gun_index);
  2195. }
  2196. #endif
  2197. }
  2198. }
  2199. }
  2200. else if(gunType[gun_index] == 'G')
  2201. {
  2202. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2203. {
  2204. tempIndex = ((gun_index==2) ? 1: 0);
  2205. }
  2206. else
  2207. {
  2208. tempIndex = gun_index;
  2209. }
  2210. for (int index = 0; index < GB_QUANTITY; index++)
  2211. {
  2212. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2213. {
  2214. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2215. {
  2216. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2217. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2218. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2219. statusModeChage[gun_index] = TRUE;
  2220. }
  2221. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2222. {
  2223. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2224. if((access(filenmae,F_OK))!=-1)
  2225. {
  2226. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2227. sprintf(str,"rm -f %s",filenmae);
  2228. system(str);
  2229. }
  2230. }
  2231. #if 1 // for TempStopTransaction
  2232. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2233. {
  2234. checkTempStopTransaction(gun_index);
  2235. }
  2236. #endif
  2237. }
  2238. }
  2239. }
  2240. else
  2241. {
  2242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2243. {
  2244. tempIndex = 2;
  2245. }
  2246. else
  2247. {
  2248. tempIndex = gun_index;
  2249. }
  2250. for (int index = 0; index < AC_QUANTITY; index++)
  2251. {
  2252. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2253. {
  2254. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2255. {
  2256. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2257. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2258. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2259. statusModeChage[gun_index] = TRUE;
  2260. }
  2261. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2262. {
  2263. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2264. if((access(filenmae,F_OK))!=-1)
  2265. {
  2266. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2267. sprintf(str,"rm -f %s",filenmae);
  2268. system(str);
  2269. }
  2270. }
  2271. #if 1 // for TempStopTransaction
  2272. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2273. {
  2274. checkTempStopTransaction(gun_index);
  2275. }
  2276. #endif
  2277. }
  2278. }// END
  2279. }
  2280. if(isWebsocketSendable &&
  2281. (((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)))) )
  2282. {
  2283. if(SystemInitial > 0)
  2284. SystemInitial -= 1;
  2285. sendStatusNotificationRequest(gun_index);
  2286. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2287. statusModeChage[gun_index] = FALSE;
  2288. }
  2289. //==============================================
  2290. // Meter report
  2291. //==============================================
  2292. if(cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2293. {
  2294. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2295. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2296. }
  2297. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2298. (((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)))
  2299. {
  2300. //check Transaction active
  2301. if(gunType[gun_index] == 'J')
  2302. {
  2303. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2304. {
  2305. tempIndex = ((gun_index==2) ? 1: 0);
  2306. }
  2307. else
  2308. {
  2309. tempIndex = gun_index;
  2310. }
  2311. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2312. {
  2313. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2314. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2315. {
  2316. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2317. {
  2318. reqSampleMeter[gun_index] = 1;
  2319. }
  2320. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2321. {
  2322. reqClockAlignMeter[gun_index] = 1;
  2323. }
  2324. }
  2325. }// End for CHAdeMO
  2326. }
  2327. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2328. {
  2329. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2330. {
  2331. tempIndex = ((gun_index==2) ? 1: 0);
  2332. }
  2333. else
  2334. {
  2335. tempIndex = gun_index;
  2336. }
  2337. for (int index = 0; index < CCS_QUANTITY; index++)
  2338. {
  2339. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2340. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2341. {
  2342. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2343. {
  2344. reqSampleMeter[gun_index] = 1;
  2345. }
  2346. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2347. {
  2348. reqClockAlignMeter[gun_index] = 1;
  2349. }
  2350. }
  2351. } // End for CCS
  2352. }
  2353. else if(gunType[gun_index] == 'G')
  2354. {
  2355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2356. {
  2357. tempIndex = ((gun_index==2) ? 1: 0);
  2358. }
  2359. else
  2360. {
  2361. tempIndex = gun_index;
  2362. }
  2363. for (int index = 0; index < GB_QUANTITY; index++)
  2364. {
  2365. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2366. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2367. {
  2368. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2369. {
  2370. reqSampleMeter[gun_index] = 1;
  2371. }
  2372. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2373. {
  2374. reqClockAlignMeter[gun_index] = 1;
  2375. }
  2376. }
  2377. }// End for GB
  2378. }
  2379. else
  2380. {
  2381. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2382. {
  2383. tempIndex = 2;
  2384. }
  2385. else
  2386. {
  2387. tempIndex = gun_index;
  2388. }
  2389. for (int index = 0; index < AC_QUANTITY; index++)
  2390. {
  2391. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2392. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2393. {
  2394. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2395. {
  2396. reqSampleMeter[gun_index] = 1;
  2397. }
  2398. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2399. {
  2400. reqClockAlignMeter[gun_index] = 1;
  2401. }
  2402. }
  2403. }//End for AC
  2404. }
  2405. if(reqSampleMeter[gun_index] == 1)
  2406. {
  2407. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2408. storeTempStopTransaction(gun_index);
  2409. }
  2410. else if(reqClockAlignMeter[gun_index] == 1)
  2411. {
  2412. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2413. }
  2414. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2415. sleep(1);
  2416. }
  2417. //==============================================
  2418. // Check Connector reserved
  2419. //==============================================
  2420. //===============================
  2421. // Check if Reserve is expired
  2422. //===============================
  2423. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2424. {
  2425. double diff_t;
  2426. struct tm tp;
  2427. // current time
  2428. time_t t = time(NULL);
  2429. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2430. tp.tm_isdst = -1;
  2431. time_t utc = mktime(&tp);
  2432. diff_t = difftime(utc, t);
  2433. if(diff_t <= 0)
  2434. {
  2435. DEBUG_INFO("reserve expired.\n");
  2436. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2437. }
  2438. }//END OF Check if Reserve is expired
  2439. //==========================================
  2440. // csu trigger FirmwareStatusNotificationReq
  2441. //==========================================
  2442. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2443. {
  2444. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2445. }
  2446. //==========================================
  2447. // csu trigger CancelReservationConf
  2448. //==========================================
  2449. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2450. {
  2451. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2452. }
  2453. //==========================================
  2454. // csu trigger ChangeAvailabilityConf
  2455. //==========================================
  2456. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2457. {
  2458. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2459. }
  2460. //==========================================
  2461. // csu trigger UnlockConnectorConf
  2462. //==========================================
  2463. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2464. {
  2465. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2466. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2467. }
  2468. //==========================================
  2469. // csu trigger ReserveNowConf
  2470. //==========================================
  2471. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2472. {
  2473. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2474. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2475. }
  2476. //==========================================
  2477. // csu trigger DataTransferReq
  2478. //==========================================
  2479. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2480. {
  2481. sendDataTransferRequest(gun_index);
  2482. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2483. }
  2484. }
  2485. }
  2486. //==========================================
  2487. // send request routine
  2488. //==========================================
  2489. int sendAuthorizeRequest(int gun_index)
  2490. {
  2491. mtrace();
  2492. int result = FAIL;
  2493. char message[100]={0};
  2494. char guid[37];
  2495. char tempdata[65]={0};
  2496. DEBUG_INFO("sendAuthorizeRequest...\n");
  2497. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2498. //Local Authorize
  2499. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2500. {
  2501. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2502. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2503. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2504. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2505. result = PASS;
  2506. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2507. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2508. authorizeRetryTimes = 0;
  2509. return result;
  2510. }
  2511. 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))||
  2512. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2513. {
  2514. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2515. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2516. {
  2517. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2518. {
  2519. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2520. }
  2521. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2522. {
  2523. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2524. }
  2525. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2526. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2527. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2528. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2529. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2530. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2531. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2532. authorizeRetryTimes = 0;
  2533. return result;
  2534. }
  2535. else
  2536. {
  2537. DEBUG_INFO("offline Local Authorization get result !!!!\n");
  2538. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2539. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2540. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2541. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2542. else
  2543. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2544. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2545. result = PASS;
  2546. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2547. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2548. authorizeRetryTimes = 0;
  2549. return result;
  2550. }
  2551. }
  2552. //initailize struct Authorize
  2553. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2554. //get data from shared memory
  2555. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2556. random_uuid(guid);
  2557. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2558. LWS_Send(message);
  2559. sprintf(tempdata, "Authorize,%d", gun_index);
  2560. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2561. {
  2562. result = PASS;
  2563. DEBUG_INFO("Authorize mapItem pass\n");
  2564. }
  2565. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2566. return result;
  2567. }
  2568. int sendBootNotificationRequest(void)
  2569. {
  2570. mtrace();
  2571. int result = FAIL;
  2572. char message[500]={0}, payload[700]={0};
  2573. char guid[37]={0};
  2574. char tempdata[65]={0};
  2575. /*
  2576. int IsGunCharging = FALSE;
  2577. //check Transaction active
  2578. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2579. {
  2580. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2581. {
  2582. IsGunCharging = TRUE;
  2583. }
  2584. }
  2585. for (int index = 0; index < CCS_QUANTITY; index++)
  2586. {
  2587. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2588. {
  2589. IsGunCharging = TRUE;
  2590. }
  2591. }
  2592. for (int index = 0; index < GB_QUANTITY; index++)
  2593. {
  2594. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2595. {
  2596. IsGunCharging = TRUE;
  2597. }
  2598. }
  2599. for (int index = 0; index < AC_QUANTITY; index++)
  2600. {
  2601. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2602. {
  2603. IsGunCharging = TRUE;
  2604. }
  2605. }
  2606. if(IsGunCharging == TRUE)
  2607. {
  2608. server_sign = TRUE;
  2609. return result;
  2610. }
  2611. */
  2612. // Fill BootNotification fields
  2613. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2614. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2615. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2616. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2617. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2618. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2619. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2620. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2621. ShmOCPP16Data->ChargeBoxId
  2622. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2623. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2624. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2625. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2626. ,ShmOCPP16Data->BootNotification.CpIccid
  2627. ,ShmOCPP16Data->BootNotification.CpImsi);
  2628. random_uuid(guid);
  2629. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2630. LWS_Send(message);
  2631. sprintf(tempdata, "BootNotification,0");
  2632. 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*/)
  2633. {
  2634. result = PASS;
  2635. }
  2636. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2637. strcpy(queuedata,message);
  2638. return result;
  2639. }
  2640. int sendDataTransferRequest(int gun_index)
  2641. {
  2642. mtrace();
  2643. char message[1000]={0};
  2644. char guid[37]={0};
  2645. char tempdata[65]={0};
  2646. int result = FAIL;
  2647. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2648. random_uuid(guid);
  2649. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2650. MESSAGE_TYPE_CALL,
  2651. guid,
  2652. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2653. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2654. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2655. LWS_Send(message);
  2656. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2657. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2658. {
  2659. result = PASS;
  2660. DEBUG_INFO("DataTransfer mapItem pass\n");
  2661. }
  2662. return result;
  2663. }
  2664. int sendDiagnosticsStatusNotificationRequest(char *status)
  2665. {
  2666. mtrace();
  2667. int result = FAIL;
  2668. char message[110]={0};
  2669. char guid[37]={0};
  2670. char tempdata[65]={0};
  2671. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2672. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2673. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2674. random_uuid(guid);
  2675. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2676. LWS_SendNow(message);
  2677. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2678. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2679. {
  2680. result = PASS;
  2681. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2682. }
  2683. //#ifdef SystemLogMessage
  2684. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2685. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2686. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2687. //#endif
  2688. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2689. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2690. //record status
  2691. if(strcmp(status,"Idle")==0)
  2692. {
  2693. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2694. }
  2695. else if(strcmp(status,"Uploaded")==0)
  2696. {
  2697. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2698. }
  2699. else if(strcmp(status,"UploadFailed")==0)
  2700. {
  2701. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2702. }
  2703. else if(strcmp(status,"Uploading")==0)
  2704. {
  2705. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2706. }
  2707. return result;
  2708. }
  2709. int sendFirmwareStatusNotificationRequest(char *status)
  2710. {
  2711. mtrace();
  2712. int result = FAIL;
  2713. char message[110]={0};
  2714. char guid[37]={0};
  2715. char tempdata[65]={0};
  2716. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2717. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2718. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2719. random_uuid(guid);
  2720. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2721. LWS_SendNow(message);
  2722. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2723. 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*/)
  2724. {
  2725. result = PASS;
  2726. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2727. }
  2728. //#ifdef SystemLogMessage
  2729. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2730. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2731. //#endif
  2732. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2733. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2734. //record status
  2735. if(strcmp(status,"Downloaded")==0)
  2736. {
  2737. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2738. }
  2739. else if(strcmp(status,"DownloadFailed")==0)
  2740. {
  2741. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2742. }
  2743. else if(strcmp(status,"Downloading")==0)
  2744. {
  2745. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2746. }
  2747. else if(strcmp(status,"Idle")==0)
  2748. {
  2749. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2750. }
  2751. else if(strcmp(status,"InstallationFailed")==0)
  2752. {
  2753. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2754. }
  2755. else if(strcmp(status,"Installing")==0)
  2756. {
  2757. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2758. }
  2759. else if(strcmp(status,"Installed")==0)
  2760. {
  2761. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2762. }
  2763. return result;
  2764. }
  2765. int sendHeartbeatRequest(int gun_index)
  2766. {
  2767. mtrace();
  2768. int result = FAIL;
  2769. char message[80]={0};
  2770. char guid[37]={0};
  2771. char tempdata[65]={0};
  2772. random_uuid(guid);
  2773. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2774. , MESSAGE_TYPE_CALL
  2775. , guid );
  2776. LWS_Send(message);
  2777. sprintf(tempdata, "Heartbeat,%d", 0);
  2778. 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*/)
  2779. {
  2780. result = PASS;
  2781. }
  2782. return result;
  2783. }
  2784. int sendStartTransactionRequest(int gun_index)
  2785. {
  2786. mtrace();
  2787. int result = FAIL;
  2788. char message[250]={0};
  2789. char guid[37]={0};
  2790. struct timeval tmnow;
  2791. struct tm *tm;
  2792. char buf[28];//, usec_buf[6];
  2793. char tempdata[65]={0};
  2794. int tempIndex = 0;
  2795. DEBUG_INFO("sendStartTransactionRequest...\n");
  2796. gettimeofday(&tmnow, NULL);
  2797. time_t t;
  2798. t = time(NULL);
  2799. /*UTC time and date*/
  2800. tm = gmtime(&t);
  2801. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2802. #if 0 // remove temporally
  2803. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2804. strcat(buf,".");
  2805. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2806. strcat(buf,usec_buf);
  2807. #endif
  2808. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2809. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2810. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2811. // clear StartTransaction Response
  2812. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2813. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2814. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2815. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2816. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2817. if(gunType[gun_index] == 'J')
  2818. {
  2819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2820. {
  2821. tempIndex = ((gun_index==2) ? 1: 0);
  2822. }
  2823. else
  2824. {
  2825. tempIndex = gun_index;
  2826. }
  2827. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2828. {
  2829. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2830. {
  2831. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2832. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2833. }
  2834. }
  2835. }
  2836. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2837. {
  2838. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2839. {
  2840. tempIndex = ((gun_index==2) ? 1: 0);
  2841. }
  2842. else
  2843. {
  2844. tempIndex = gun_index;
  2845. }
  2846. for (int index = 0; index < CCS_QUANTITY; index++)
  2847. {
  2848. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2849. {
  2850. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2851. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2852. }
  2853. }
  2854. }
  2855. else if(gunType[gun_index] == 'G')
  2856. {
  2857. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2858. {
  2859. tempIndex = ((gun_index==2) ? 1: 0);
  2860. }
  2861. else
  2862. {
  2863. tempIndex = gun_index;
  2864. }
  2865. for (int index = 0; index < GB_QUANTITY; index++)
  2866. {
  2867. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2868. {
  2869. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2870. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2871. }
  2872. }
  2873. }
  2874. else
  2875. {
  2876. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2877. {
  2878. tempIndex = 2;
  2879. }
  2880. else
  2881. {
  2882. tempIndex = gun_index;
  2883. }
  2884. for (int index = 0; index < AC_QUANTITY; index++)
  2885. {
  2886. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2887. {
  2888. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2889. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2890. }
  2891. }
  2892. }
  2893. random_uuid(guid);
  2894. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2895. {
  2896. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2897. , gun_index +1
  2898. , MESSAGE_TYPE_CALL
  2899. , guid
  2900. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2901. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2902. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2903. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2904. }
  2905. else
  2906. {
  2907. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2908. , gun_index +1
  2909. , MESSAGE_TYPE_CALL
  2910. , guid
  2911. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2912. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2913. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2914. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2915. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2916. }
  2917. #if 1
  2918. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2919. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2920. {
  2921. result = PASS;
  2922. }
  2923. #endif
  2924. strcpy(queuedata, message);
  2925. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2926. /*
  2927. if(GetTransactionQueueNum() == 1)
  2928. {
  2929. LWS_Send(message + 2);
  2930. }*/
  2931. return result;
  2932. }
  2933. int sendStatusNotificationRequest(int gun_index)
  2934. {
  2935. mtrace();
  2936. int result = FAIL;
  2937. char message[600]={0};
  2938. char guid[37];
  2939. int currentStatus = 0;
  2940. struct timeval tmnow;
  2941. struct tm *tm;
  2942. char buf[28];//, usec_buf[6];
  2943. char tempdata[65]={0};
  2944. int tempIndex = 0;
  2945. gettimeofday(&tmnow, NULL);
  2946. time_t t;
  2947. t = time(NULL);
  2948. /*UTC time and date*/
  2949. tm = gmtime(&t);
  2950. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2951. #if 0 // remove temporally
  2952. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2953. strcat(buf,".");
  2954. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2955. strcat(buf,usec_buf);
  2956. #endif
  2957. printf("%s",buf);
  2958. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2959. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2960. // it's option
  2961. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2962. /*
  2963. enum _SYSTEM_STATUS
  2964. {
  2965. S_BOOTING = 0,
  2966. S_IDLE, = 1
  2967. S_AUTHORIZING, =2
  2968. S_REASSIGN_CHECK, =3
  2969. S_REASSIGN, =4
  2970. S_PRECHARGE, =5
  2971. S_PREPARING_FOR_EV, =6
  2972. S_PREPARING_FOR_EVSE, =7
  2973. S_CHARGING, =8
  2974. S_TERMINATING, =9
  2975. S_COMPLETE, =10
  2976. S_ALARM, =11
  2977. S_FAULT =12
  2978. }
  2979. */
  2980. //check Transaction active
  2981. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2982. if(gunType[gun_index] == 'J')
  2983. {
  2984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2985. {
  2986. tempIndex = ((gun_index==2) ? 1: 0);
  2987. }
  2988. else
  2989. {
  2990. tempIndex = gun_index;
  2991. }
  2992. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2993. {
  2994. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2995. {
  2996. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2997. {
  2998. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2999. {
  3000. currentStatus = 1; //OCPP Status: Preparing
  3001. }
  3002. else
  3003. {
  3004. currentStatus = 0; //OCPP Status: Available
  3005. }
  3006. }
  3007. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3008. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3009. ) //S_PRECHARGE
  3010. {
  3011. currentStatus = 1; //OCPP Status: Preparing
  3012. }
  3013. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3014. {
  3015. currentStatus = 2; //OCPP Status: Charging
  3016. }
  3017. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3018. {
  3019. currentStatus = 5; //OCPP Status: Finishing
  3020. }
  3021. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3022. {
  3023. currentStatus = 4; //OCPP Status: SuspendedEV
  3024. }
  3025. 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
  3026. {
  3027. currentStatus = 7; //OCPP Status: Unavailable
  3028. }
  3029. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3030. {
  3031. currentStatus = 8; //OCPP Status: Faulted
  3032. }
  3033. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3034. {
  3035. currentStatus = 6; //OCPP Status: Reserved
  3036. }
  3037. } //end of the same index
  3038. }//end of for CHAdeMO_QUANTITY
  3039. }
  3040. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3041. {
  3042. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3043. {
  3044. tempIndex = ((gun_index==2) ? 1: 0);
  3045. }
  3046. else
  3047. {
  3048. tempIndex = gun_index;
  3049. }
  3050. for (int index = 0; index < CCS_QUANTITY; index++)
  3051. {
  3052. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3053. {
  3054. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3055. {
  3056. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3057. {
  3058. currentStatus = 1; //OCPP Status: Preparing
  3059. }
  3060. else
  3061. {
  3062. currentStatus = 0; //OCPP Status: Available
  3063. }
  3064. }
  3065. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3066. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3067. ) //S_PRECHARGE
  3068. {
  3069. currentStatus = 1; //OCPP Status: Preparing
  3070. }
  3071. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3072. {
  3073. currentStatus = 2; //OCPP Status: Charging
  3074. }
  3075. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3076. {
  3077. currentStatus = 5; //OCPP Status: Finishing
  3078. }
  3079. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3080. {
  3081. currentStatus = 4; //OCPP Status: SuspendedEV
  3082. }
  3083. 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
  3084. {
  3085. currentStatus = 7; //OCPP Status : Unavailable
  3086. }
  3087. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3088. {
  3089. currentStatus = 8; //OCPP Status: Faulted
  3090. }
  3091. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3092. {
  3093. currentStatus = 6; //OCPP Status: Reserved
  3094. }
  3095. } //end of the same index
  3096. } // end of for CCS_QUANTITY
  3097. }
  3098. else if(gunType[gun_index] == 'G')
  3099. {
  3100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3101. {
  3102. tempIndex = ((gun_index==2) ? 1: 0);
  3103. }
  3104. else
  3105. {
  3106. tempIndex = gun_index;
  3107. }
  3108. for (int index = 0; index < GB_QUANTITY; index++)
  3109. {
  3110. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3111. {
  3112. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3113. {
  3114. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3115. {
  3116. currentStatus = 1; //OCPP Status: Preparing
  3117. }
  3118. else
  3119. {
  3120. currentStatus = 0; //OCPP Status: Available
  3121. }
  3122. }
  3123. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3124. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3125. ) //S_PRECHARGE
  3126. {
  3127. currentStatus = 1; //OCPP Status: Preparing
  3128. }
  3129. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3130. {
  3131. currentStatus = 2; //OCPP Status: Charging
  3132. }
  3133. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3134. {
  3135. currentStatus = 5; //OCPP Status: Finishing
  3136. }
  3137. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3138. {
  3139. currentStatus = 4; //OCPP Status: SuspendedEV
  3140. }
  3141. 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
  3142. {
  3143. currentStatus = 7; //OCPP Status: Unavailable
  3144. }
  3145. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3146. {
  3147. currentStatus = 8; //OCPP Status: Faulted
  3148. }
  3149. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3150. {
  3151. currentStatus = 6; //OCPP Status: Reserved
  3152. }
  3153. } //end of the same index
  3154. } // end of for GB_QUANTITY
  3155. }
  3156. else
  3157. {
  3158. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3159. {
  3160. tempIndex = 2;
  3161. }
  3162. else
  3163. {
  3164. tempIndex = gun_index;
  3165. }
  3166. for (int index = 0; index < AC_QUANTITY; index++)
  3167. {
  3168. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3169. {
  3170. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3171. {
  3172. 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))
  3173. {
  3174. currentStatus = 1; //OCPP Status: Preparing
  3175. }
  3176. else
  3177. {
  3178. currentStatus = 0; //OCPP Status: Available
  3179. }
  3180. }
  3181. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3182. {
  3183. currentStatus = 1; //OCPP Status: Preparing
  3184. }
  3185. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3186. {
  3187. currentStatus = 2; //OCPP Status: Charging
  3188. }
  3189. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3190. {
  3191. currentStatus = 5; //OCPP Status: Finishing
  3192. }
  3193. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3194. {
  3195. currentStatus = 4; //OCPP Status: SuspendedEV
  3196. }
  3197. 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
  3198. {
  3199. currentStatus = 7; //OCPP Status: Unavailable
  3200. }
  3201. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3202. {
  3203. currentStatus = 8; //OCPP Status: Faulted
  3204. }
  3205. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3206. {
  3207. currentStatus = 6; //OCPP Status: Reserved
  3208. }
  3209. }//end of the same index
  3210. }//end of for AC_QUANTITY
  3211. }
  3212. //it's option
  3213. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3214. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3215. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3216. random_uuid(guid);
  3217. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3218. , MESSAGE_TYPE_CALL
  3219. , guid
  3220. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3221. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3222. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3223. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3224. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3225. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3226. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3227. if((server_sign == TRUE))
  3228. {
  3229. LWS_Send(message);
  3230. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3231. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3232. {
  3233. //DEBUG_ERROR("statusNotification mapitem pass");
  3234. result = PASS;
  3235. }
  3236. }
  3237. else
  3238. {
  3239. result = PASS;
  3240. }
  3241. return result;
  3242. }
  3243. int sendStopTransactionRequest(int gun_index)
  3244. {
  3245. mtrace();
  3246. int result = FAIL;
  3247. //char message[1500]={0};
  3248. char guid[37]={0};
  3249. char tempdata[65]={0};
  3250. int tempIndex = 0;
  3251. char TempStopTransaction[256];
  3252. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3253. //int idx_sample=0;
  3254. DEBUG_ERROR("sendStopTransactionRequest \n");
  3255. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3256. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3257. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3258. if(gunType[gun_index] == 'J')
  3259. {
  3260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3261. {
  3262. tempIndex = ((gun_index==2) ? 1: 0);
  3263. }
  3264. else
  3265. {
  3266. tempIndex = gun_index;
  3267. }
  3268. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3269. {
  3270. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3271. {
  3272. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3273. }
  3274. }// END OF CHAdeMO_QUANTITY
  3275. }
  3276. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3277. {
  3278. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3279. {
  3280. tempIndex = ((gun_index==2) ? 1: 0);
  3281. }
  3282. else
  3283. {
  3284. tempIndex = gun_index;
  3285. }
  3286. for (int index = 0; index < CCS_QUANTITY; index++)
  3287. {
  3288. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3289. {
  3290. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3291. }
  3292. }// END OF CCS_QUANTITY
  3293. }
  3294. else if(gunType[gun_index] == 'G')
  3295. {
  3296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3297. {
  3298. tempIndex = ((gun_index==2) ? 1: 0);
  3299. }
  3300. else
  3301. {
  3302. tempIndex = gun_index;
  3303. }
  3304. for (int index = 0; index < GB_QUANTITY; index++)
  3305. {
  3306. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3307. {
  3308. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3309. }
  3310. }// END OF GB_QUANTITY
  3311. }
  3312. else
  3313. {
  3314. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3315. {
  3316. tempIndex = 2;
  3317. }
  3318. else
  3319. {
  3320. tempIndex = gun_index;
  3321. }
  3322. for (int index = 0; index < AC_QUANTITY; index++)
  3323. {
  3324. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3325. {
  3326. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3327. }
  3328. }// END OF AC_QUANTITY
  3329. }
  3330. //====================================== Stop Transaction Time =====================================================
  3331. struct timeval tmnow;
  3332. struct tm *tm;
  3333. char buf[28];//, usec_buf[6];
  3334. gettimeofday(&tmnow, NULL);
  3335. time_t t;
  3336. t = time(NULL);
  3337. /*UTC time and date*/
  3338. tm = gmtime(&t);
  3339. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3341. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3342. random_uuid(guid);
  3343. /***********************************transactionData******************************************************/
  3344. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3346. //=================================
  3347. // Transaction_Begin
  3348. //=================================
  3349. //============================================ Energy.Active.Import.Interval ================================
  3350. //idx_sample=0;
  3351. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3353. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3354. 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*/]);
  3355. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3356. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3357. {
  3358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3359. }
  3360. else
  3361. {
  3362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3363. }
  3364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3366. //=================================
  3367. // Transaction_End
  3368. //=================================
  3369. // ================================= Current.Import L1 ===============================================
  3370. //idx_sample=1;
  3371. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3372. if(gunType[gun_index] == 'J')
  3373. {
  3374. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3375. {
  3376. tempIndex = ((gun_index==2) ? 1: 0);
  3377. }
  3378. else
  3379. {
  3380. tempIndex = gun_index;
  3381. }
  3382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3383. {
  3384. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3385. {
  3386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3387. }
  3388. }// End of for CHAdeMO_QUANTITY
  3389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3390. }
  3391. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3392. {
  3393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3394. {
  3395. tempIndex = ((gun_index==2) ? 1: 0);
  3396. }
  3397. else
  3398. {
  3399. tempIndex = gun_index;
  3400. }
  3401. for (int index = 0; index < CCS_QUANTITY; index++)
  3402. {
  3403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3404. {
  3405. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3406. }
  3407. }// End of for CCS_QUANTITY
  3408. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3409. }
  3410. else if(gunType[gun_index] == 'G')
  3411. {
  3412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3413. {
  3414. tempIndex = ((gun_index==2) ? 1: 0);
  3415. }
  3416. else
  3417. {
  3418. tempIndex = gun_index;
  3419. }
  3420. for (int index = 0; index < GB_QUANTITY; index++)
  3421. {
  3422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3423. {
  3424. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3425. }
  3426. }// End of for GB_QUANTITY
  3427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3428. }
  3429. else
  3430. {
  3431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3432. {
  3433. tempIndex = 2;
  3434. }
  3435. else
  3436. {
  3437. tempIndex = gun_index;
  3438. }
  3439. for (int index = 0; index < AC_QUANTITY; index++)
  3440. {
  3441. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3442. {
  3443. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3444. }
  3445. }// End of for AC_QUANTITY
  3446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3447. }
  3448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3453. // ================================= Energy.Active.Import.Interval ==============================================
  3454. //idx_sample=2;
  3455. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3456. if(gunType[gun_index] == 'J')
  3457. {
  3458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3459. {
  3460. tempIndex = ((gun_index==2) ? 1: 0);
  3461. }
  3462. else
  3463. {
  3464. tempIndex = gun_index;
  3465. }
  3466. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3467. {
  3468. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3469. {
  3470. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3471. }
  3472. }// END OF CHAdeMO_QUANTITY
  3473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3474. }
  3475. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3476. {
  3477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3478. {
  3479. tempIndex = ((gun_index==2) ? 1: 0);
  3480. }
  3481. else
  3482. {
  3483. tempIndex = gun_index;
  3484. }
  3485. for (int index = 0; index < CCS_QUANTITY; index++)
  3486. {
  3487. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3488. {
  3489. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3490. }
  3491. }// END OF CCS_QUANTITY
  3492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3493. }
  3494. else if(gunType[gun_index] == 'G')
  3495. {
  3496. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3497. {
  3498. tempIndex = ((gun_index==2) ? 1: 0);
  3499. }
  3500. else
  3501. {
  3502. tempIndex = gun_index;
  3503. }
  3504. for (int index = 0; index < GB_QUANTITY; index++)
  3505. {
  3506. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3507. {
  3508. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3509. }
  3510. }// END OF GB_QUANTITY
  3511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3512. }
  3513. else
  3514. {
  3515. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3516. {
  3517. tempIndex = 2;
  3518. }
  3519. else
  3520. {
  3521. tempIndex = gun_index;
  3522. }
  3523. for (int index = 0; index < AC_QUANTITY; index++)
  3524. {
  3525. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3526. {
  3527. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3528. }
  3529. }// END OF AC_QUANTITY
  3530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3531. }
  3532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3537. //=================================== Power.Active.Import ==================================================
  3538. //idx_sample=3;
  3539. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3540. if(gunType[gun_index] == 'J')
  3541. {
  3542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3543. {
  3544. tempIndex = ((gun_index==2) ? 1: 0);
  3545. }
  3546. else
  3547. {
  3548. tempIndex = gun_index;
  3549. }
  3550. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3551. {
  3552. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3553. {
  3554. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3555. }
  3556. } // End for CHAdeMO_QUANTITY
  3557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3558. }
  3559. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3560. {
  3561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3562. {
  3563. tempIndex = ((gun_index==2) ? 1: 0);
  3564. }
  3565. else
  3566. {
  3567. tempIndex = gun_index;
  3568. }
  3569. for (int index = 0; index < CCS_QUANTITY; index++)
  3570. {
  3571. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3572. {
  3573. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3574. }
  3575. } // END for CCS_QUANTITY
  3576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3577. }
  3578. else if(gunType[gun_index] == 'G')
  3579. {
  3580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3581. {
  3582. tempIndex = ((gun_index==2) ? 1: 0);
  3583. }
  3584. else
  3585. {
  3586. tempIndex = gun_index;
  3587. }
  3588. for (int index = 0; index < GB_QUANTITY; index++)
  3589. {
  3590. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3591. {
  3592. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3593. }
  3594. }// END for GB_QUANTITY
  3595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3596. }
  3597. else
  3598. {
  3599. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3600. {
  3601. tempIndex = 2;
  3602. }
  3603. else
  3604. {
  3605. tempIndex = gun_index;
  3606. }
  3607. for (int index = 0; index < AC_QUANTITY; index++)
  3608. {
  3609. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3610. {
  3611. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3612. }
  3613. } // END for AC_QUANTITY
  3614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3615. }
  3616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3621. //============================ Voltage L1 ====================================
  3622. //idx_sample=4;
  3623. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3624. if(gunType[gun_index] == 'J')
  3625. {
  3626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3627. {
  3628. tempIndex = ((gun_index==2) ? 1: 0);
  3629. }
  3630. else
  3631. {
  3632. tempIndex = gun_index;
  3633. }
  3634. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3635. {
  3636. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3637. {
  3638. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3639. }
  3640. } // END OF FOR CHAdeMO_QUANTITY
  3641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3642. }
  3643. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3644. {
  3645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3646. {
  3647. tempIndex = ((gun_index==2) ? 1: 0);
  3648. }
  3649. else
  3650. {
  3651. tempIndex = gun_index;
  3652. }
  3653. for (int index = 0; index < CCS_QUANTITY; index++)
  3654. {
  3655. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3656. {
  3657. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3658. }
  3659. } // END OF FOR CCS_QUANTITY
  3660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3661. }
  3662. else if(gunType[gun_index] == 'G')
  3663. {
  3664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3665. {
  3666. tempIndex = ((gun_index==2) ? 1: 0);
  3667. }
  3668. else
  3669. {
  3670. tempIndex = gun_index;
  3671. }
  3672. for (int index = 0; index < GB_QUANTITY; index++)
  3673. {
  3674. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3675. {
  3676. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3677. }
  3678. } // END OF FOR GB_QUANTITY
  3679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3680. }
  3681. else
  3682. {
  3683. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3684. {
  3685. tempIndex = 2;
  3686. }
  3687. else
  3688. {
  3689. tempIndex = gun_index;
  3690. }
  3691. for (int index = 0; index < AC_QUANTITY; index++)
  3692. {
  3693. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3694. {
  3695. 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
  3696. }
  3697. } // END OF FOR AC_QUANTITY
  3698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3699. }
  3700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3703. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3705. //====================== SoC ================================
  3706. //idx_sample=5;
  3707. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3708. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3709. {
  3710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3711. {
  3712. tempIndex = ((gun_index==2) ? 1: 0);
  3713. }
  3714. else
  3715. {
  3716. tempIndex = gun_index;
  3717. }
  3718. if(gunType[gun_index] == 'J')
  3719. {
  3720. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3721. {
  3722. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3723. {
  3724. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3725. }
  3726. }
  3727. }
  3728. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3729. {
  3730. for (int index = 0; index < CCS_QUANTITY; index++)
  3731. {
  3732. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3733. {
  3734. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3735. }
  3736. }
  3737. }
  3738. else if(gunType[gun_index] == 'G')
  3739. {
  3740. for (int index = 0; index < GB_QUANTITY; index++)
  3741. {
  3742. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3743. {
  3744. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3745. }
  3746. }
  3747. }
  3748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3754. } // END FOR DC CASE
  3755. // ================================= Current.Import L2 ===============================================
  3756. //idx_sample=6;
  3757. // AC 3 phse L2 current
  3758. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3759. {
  3760. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3761. {
  3762. tempIndex = 2;
  3763. }
  3764. else
  3765. {
  3766. tempIndex = gun_index;
  3767. }
  3768. for (int index = 0; index < AC_QUANTITY; index++)
  3769. {
  3770. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3771. {
  3772. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3773. }
  3774. }// End of for AC_QUANTITY
  3775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3776. }
  3777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3781. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3782. // ================================= Current.Import L3 ===============================================
  3783. //idx_sample=7;
  3784. // AC 3 phse L3 current
  3785. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3786. {
  3787. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3788. {
  3789. tempIndex = 2;
  3790. }
  3791. else
  3792. {
  3793. tempIndex = gun_index;
  3794. }
  3795. for (int index = 0; index < AC_QUANTITY; index++)
  3796. {
  3797. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3798. {
  3799. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3800. }
  3801. }// End of for AC_QUANTITY
  3802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3803. }
  3804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3807. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3809. //============================ Voltage L2 ====================================
  3810. //idx_sample=8;
  3811. // AC 3 phse L2 voltage
  3812. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3813. {
  3814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3815. {
  3816. tempIndex = 2;
  3817. }
  3818. else
  3819. {
  3820. tempIndex = gun_index;
  3821. }
  3822. for (int index = 0; index < AC_QUANTITY; index++)
  3823. {
  3824. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3825. {
  3826. 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
  3827. }
  3828. } // END OF FOR AC_QUANTITY
  3829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3830. }
  3831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3836. //============================ Voltage L3 ====================================
  3837. //idx_sample=8;
  3838. // AC 3 phse L3 voltage
  3839. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3840. {
  3841. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3842. {
  3843. tempIndex = 2;
  3844. }
  3845. else
  3846. {
  3847. tempIndex = gun_index;
  3848. }
  3849. for (int index = 0; index < AC_QUANTITY; index++)
  3850. {
  3851. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3852. {
  3853. 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
  3854. }
  3855. } // END OF FOR AC_QUANTITY
  3856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3857. }
  3858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3859. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3860. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3863. //================================================ Message create ====================================================
  3864. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3865. {
  3866. 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\"}]}]}]"
  3867. ,gun_index+1
  3868. ,MESSAGE_TYPE_CALL
  3869. ,guid
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3875. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3918. );
  3919. }
  3920. else
  3921. {
  3922. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3923. {
  3924. 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\"}]}]}]"
  3925. ,gun_index+1
  3926. ,MESSAGE_TYPE_CALL
  3927. ,guid
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3933. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3969. );
  3970. }
  3971. else
  3972. {
  3973. 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\"}]}]}]"
  3974. ,gun_index+1
  3975. ,MESSAGE_TYPE_CALL
  3976. ,guid
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3982. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  4019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  4020. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  4021. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  4022. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  4023. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  4024. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  4025. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  4026. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  4027. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  4028. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  4029. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  4030. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  4031. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  4032. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  4033. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  4034. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  4035. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  4036. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  4037. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  4038. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  4039. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  4040. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  4041. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  4042. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  4043. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  4044. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  4045. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  4046. );
  4047. }
  4048. }
  4049. #if 1 // for TempStopTransaction
  4050. //Delete TempStopTransaction
  4051. if((access(TempStopTransaction,F_OK))!=-1)
  4052. {
  4053. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4054. }
  4055. #endif
  4056. #if 1
  4057. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4058. if(hashmap_operation(0, guid, tempdata) == 1)
  4059. {
  4060. result = PASS;
  4061. DEBUG_INFO("StopTransaction mapitem pass\n");
  4062. }
  4063. #endif
  4064. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4065. /*
  4066. if(GetTransactionQueueNum() == 1)
  4067. {
  4068. LWS_Send(queuedata+2);
  4069. }*/
  4070. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4071. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4072. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4073. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4074. {
  4075. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4076. }
  4077. //for test
  4078. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4079. return result;
  4080. }
  4081. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4082. {
  4083. mtrace();
  4084. int result = FAIL;
  4085. char guid[37]={0};
  4086. char tempdata[65]={0};
  4087. int tempIndex = 0;
  4088. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4089. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4090. //set value
  4091. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4092. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4093. random_uuid(guid);
  4094. //UTC Date time
  4095. struct timeval tmnow;
  4096. struct tm *tm;
  4097. char buf[28];//, usec_buf[6];
  4098. gettimeofday(&tmnow, NULL);
  4099. time_t t;
  4100. t = time(NULL);
  4101. /*UTC time and date*/
  4102. tm = gmtime(&t);
  4103. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4104. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4105. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4106. //idx_sample=0;
  4107. //********************************(1)Current.Import L1************************************************/
  4108. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4109. if(gunType[gun_index] == 'J')
  4110. {
  4111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4112. {
  4113. tempIndex = ((gun_index==2) ? 1: 0);
  4114. }
  4115. else
  4116. {
  4117. tempIndex = gun_index;
  4118. }
  4119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4120. {
  4121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4122. {
  4123. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4124. }
  4125. }
  4126. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4127. }
  4128. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4129. {
  4130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4131. {
  4132. tempIndex = ((gun_index==2) ? 1: 0);
  4133. }
  4134. else
  4135. {
  4136. tempIndex = gun_index;
  4137. }
  4138. for (int index = 0; index < CCS_QUANTITY; index++)
  4139. {
  4140. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4141. {
  4142. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4143. }
  4144. }
  4145. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4146. }
  4147. else if(gunType[gun_index] == 'G')
  4148. {
  4149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4150. {
  4151. tempIndex = ((gun_index==2) ? 1: 0);
  4152. }
  4153. else
  4154. {
  4155. tempIndex = gun_index;
  4156. }
  4157. for (int index = 0; index < GB_QUANTITY; index++)
  4158. {
  4159. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4160. {
  4161. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4162. }
  4163. }
  4164. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4165. }
  4166. else
  4167. {
  4168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4169. {
  4170. tempIndex = 2;
  4171. }
  4172. else
  4173. {
  4174. tempIndex = gun_index;
  4175. }
  4176. for (int index = 0; index < AC_QUANTITY; index++)
  4177. {
  4178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4179. {
  4180. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4181. }
  4182. }
  4183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4184. }
  4185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4190. //idx_sample=1;
  4191. //********************************(2)Energy.Active.Import.Register ************************************************/
  4192. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4193. if(gunType[gun_index] == 'J')
  4194. {
  4195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4196. {
  4197. tempIndex = ((gun_index==2) ? 1: 0);
  4198. }
  4199. else
  4200. {
  4201. tempIndex = gun_index;
  4202. }
  4203. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4204. {
  4205. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4206. {
  4207. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4208. }
  4209. }
  4210. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4211. }
  4212. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4213. {
  4214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4215. {
  4216. tempIndex = ((gun_index==2) ? 1: 0);
  4217. }
  4218. else
  4219. {
  4220. tempIndex = gun_index;
  4221. }
  4222. for (int index = 0; index < CCS_QUANTITY; index++)
  4223. {
  4224. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4225. {
  4226. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4227. }
  4228. }
  4229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4230. }
  4231. else if(gunType[gun_index] == 'G')
  4232. {
  4233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4234. {
  4235. tempIndex = ((gun_index==2) ? 1: 0);
  4236. }
  4237. else
  4238. {
  4239. tempIndex = gun_index;
  4240. }
  4241. for (int index = 0; index < GB_QUANTITY; index++)
  4242. {
  4243. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4244. {
  4245. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4246. }
  4247. }
  4248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4249. }
  4250. else
  4251. {
  4252. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4253. {
  4254. tempIndex = 2;
  4255. }
  4256. else
  4257. {
  4258. tempIndex = gun_index;
  4259. }
  4260. for (int index = 0; index < AC_QUANTITY; index++)
  4261. {
  4262. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4263. {
  4264. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4265. }
  4266. }
  4267. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4268. }
  4269. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4270. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4271. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4272. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4273. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4274. //idx_sample=2;
  4275. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4276. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4277. if(gunType[gun_index] == 'J')
  4278. {
  4279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4280. {
  4281. tempIndex = ((gun_index==2) ? 1: 0);
  4282. }
  4283. else
  4284. {
  4285. tempIndex = gun_index;
  4286. }
  4287. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4288. {
  4289. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4290. {
  4291. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4292. }
  4293. } // END OF FOR CHAdeMO_QUANTITY
  4294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4295. }
  4296. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4297. {
  4298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4299. {
  4300. tempIndex = ((gun_index==2) ? 1: 0);
  4301. }
  4302. else
  4303. {
  4304. tempIndex = gun_index;
  4305. }
  4306. for (int index = 0; index < CCS_QUANTITY; index++)
  4307. {
  4308. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4309. {
  4310. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4311. }
  4312. } // END OF CCS_QUANTITY
  4313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4314. }
  4315. else if(gunType[gun_index] == 'G')
  4316. {
  4317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4318. {
  4319. tempIndex = ((gun_index==2) ? 1: 0);
  4320. }
  4321. else
  4322. {
  4323. tempIndex = gun_index;
  4324. }
  4325. for (int index = 0; index < GB_QUANTITY; index++)
  4326. {
  4327. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4328. {
  4329. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4330. }
  4331. } // END OF GB_QUANTITY
  4332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4333. }
  4334. else
  4335. {
  4336. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4337. {
  4338. tempIndex = 2;
  4339. }
  4340. else
  4341. {
  4342. tempIndex = gun_index;
  4343. }
  4344. for (int index = 0; index < AC_QUANTITY; index++)
  4345. {
  4346. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4347. {
  4348. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4349. }
  4350. }
  4351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4352. }
  4353. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4354. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4355. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4356. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4357. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4358. //idx_sample=3;
  4359. //********************************(4)Power.Active.Import************************************************/
  4360. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4361. if(gunType[gun_index] == 'J')
  4362. {
  4363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4364. {
  4365. tempIndex = ((gun_index==2) ? 1: 0);
  4366. }
  4367. else
  4368. {
  4369. tempIndex = gun_index;
  4370. }
  4371. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4372. {
  4373. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4374. {
  4375. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4376. }
  4377. } // END OF FOR
  4378. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4379. }
  4380. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  4391. {
  4392. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4393. {
  4394. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4395. }
  4396. }
  4397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4398. }
  4399. else if(gunType[gun_index] == 'G')
  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 < GB_QUANTITY; index++)
  4410. {
  4411. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4412. {
  4413. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4414. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4415. }
  4416. }
  4417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4418. }
  4419. else
  4420. {
  4421. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4422. {
  4423. tempIndex = 2;
  4424. }
  4425. else
  4426. {
  4427. tempIndex = gun_index;
  4428. }
  4429. for (int index = 0; index < AC_QUANTITY; index++)
  4430. {
  4431. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4432. {
  4433. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4434. }
  4435. }
  4436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4437. }
  4438. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4440. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4441. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4442. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4443. //idx_sample=4;
  4444. //***********************************************(5)VOLTAGE L1******************************************************/
  4445. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4446. if(gunType[gun_index] == 'J')
  4447. {
  4448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4449. {
  4450. tempIndex = ((gun_index==2) ? 1: 0);
  4451. }
  4452. else
  4453. {
  4454. tempIndex = gun_index;
  4455. }
  4456. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4457. {
  4458. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4459. {
  4460. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4461. }
  4462. }
  4463. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4464. }
  4465. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4466. {
  4467. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4468. {
  4469. tempIndex = ((gun_index==2) ? 1: 0);
  4470. }
  4471. else
  4472. {
  4473. tempIndex = gun_index;
  4474. }
  4475. for (int index = 0; index < CCS_QUANTITY; index++)
  4476. {
  4477. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4478. {
  4479. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4480. }
  4481. }
  4482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4483. }
  4484. else if(gunType[gun_index] == 'G')
  4485. {
  4486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4487. {
  4488. tempIndex = ((gun_index==2) ? 1: 0);
  4489. }
  4490. else
  4491. {
  4492. tempIndex = gun_index;
  4493. }
  4494. for (int index = 0; index < GB_QUANTITY; index++)
  4495. {
  4496. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4497. {
  4498. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4499. }
  4500. }
  4501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4502. }
  4503. else
  4504. {
  4505. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4506. {
  4507. tempIndex = 2;
  4508. }
  4509. else
  4510. {
  4511. tempIndex = gun_index;
  4512. }
  4513. for (int index = 0; index < AC_QUANTITY; index++)
  4514. {
  4515. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4516. {
  4517. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4518. }
  4519. }
  4520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4521. }
  4522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4524. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4527. //***********************************************(6)SOC******************************************************/
  4528. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4529. {
  4530. //idx_sample=5;
  4531. //sampledValue = NULL;
  4532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4533. {
  4534. tempIndex = ((gun_index==2) ? 1: 0);
  4535. }
  4536. else
  4537. {
  4538. tempIndex = gun_index;
  4539. }
  4540. if(gunType[gun_index] == 'J')
  4541. {
  4542. //tempIndex = ((gun_index==2) ? 1: 0);
  4543. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4544. {
  4545. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4546. {
  4547. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4548. }
  4549. }
  4550. }
  4551. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4552. {
  4553. //tempIndex = ((gun_index==2) ? 1: 0);
  4554. for (int index = 0; index < CCS_QUANTITY; index++)
  4555. {
  4556. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4557. {
  4558. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4559. }
  4560. }
  4561. }
  4562. else if(gunType[gun_index] == 'G')
  4563. {
  4564. //tempIndex = ((gun_index==2) ? 1: 0);
  4565. for (int index = 0; index < GB_QUANTITY; index++)
  4566. {
  4567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4568. {
  4569. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4570. }
  4571. }
  4572. }
  4573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4579. }
  4580. //********************************(7)Current.Import L2************************************************/
  4581. // Only for AC 3 phase
  4582. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4583. {
  4584. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4585. {
  4586. tempIndex = 2;
  4587. }
  4588. else
  4589. {
  4590. tempIndex = gun_index;
  4591. }
  4592. for (int index = 0; index < AC_QUANTITY; index++)
  4593. {
  4594. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4595. {
  4596. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4597. }
  4598. }
  4599. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4600. }
  4601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4606. //********************************(8)Current.Import L3************************************************/
  4607. // Only for AC 3 phase
  4608. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4609. {
  4610. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4611. {
  4612. tempIndex = 2;
  4613. }
  4614. else
  4615. {
  4616. tempIndex = gun_index;
  4617. }
  4618. for (int index = 0; index < AC_QUANTITY; index++)
  4619. {
  4620. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4621. {
  4622. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4623. }
  4624. }
  4625. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4626. }
  4627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4630. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4632. //***********************************************(9)VOLTAGE L2******************************************************/
  4633. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4634. {
  4635. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4636. {
  4637. tempIndex = 2;
  4638. }
  4639. else
  4640. {
  4641. tempIndex = gun_index;
  4642. }
  4643. for (int index = 0; index < AC_QUANTITY; index++)
  4644. {
  4645. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4646. {
  4647. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4648. }
  4649. }
  4650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4651. }
  4652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4657. //***********************************************(10)VOLTAGE L3******************************************************/
  4658. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4659. {
  4660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4661. {
  4662. tempIndex = 2;
  4663. }
  4664. else
  4665. {
  4666. tempIndex = gun_index;
  4667. }
  4668. for (int index = 0; index < AC_QUANTITY; index++)
  4669. {
  4670. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4671. {
  4672. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4673. }
  4674. }
  4675. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4676. }
  4677. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4678. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4679. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4682. // Message create ====================================================================================================
  4683. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4684. {
  4685. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4686. ,gun_index + 1
  4687. ,MESSAGE_TYPE_CALL
  4688. ,guid
  4689. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4690. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4691. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4734. );
  4735. }
  4736. else
  4737. {
  4738. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4739. {
  4740. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4741. ,gun_index + 1
  4742. ,MESSAGE_TYPE_CALL
  4743. ,guid
  4744. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4745. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4746. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4758. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4759. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4760. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4782. );
  4783. }
  4784. else
  4785. {
  4786. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"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\"}]}]}]"
  4787. ,gun_index + 1
  4788. ,MESSAGE_TYPE_CALL
  4789. ,guid
  4790. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4791. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4792. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4832. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4833. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4834. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4835. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4836. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4837. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4838. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4839. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4840. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4841. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4842. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4843. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4844. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4845. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4846. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4847. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4848. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4849. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4850. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4851. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4852. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4853. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4854. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4855. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4856. );
  4857. }
  4858. }
  4859. // Put request guid to hash map
  4860. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4861. 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*/)
  4862. {
  4863. result = PASS;
  4864. DEBUG_INFO("MeterValues mapitem pass\n");
  4865. }
  4866. if(dataType != ReadingContext_Trigger)
  4867. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4868. else
  4869. LWS_Send(queuedata +2);
  4870. /*
  4871. if(GetTransactionQueueNum() == 1)
  4872. {
  4873. LWS_Send(queuedata +2);
  4874. }*/
  4875. return result;
  4876. }
  4877. //==========================================
  4878. // send confirm routine
  4879. //==========================================
  4880. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4881. {
  4882. mtrace();
  4883. int result = FAIL;
  4884. char message[100]={0};
  4885. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4886. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4887. LWS_Send(message);
  4888. result = TRUE;
  4889. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4890. return result;
  4891. }
  4892. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4893. {
  4894. mtrace();
  4895. int result = FAIL;
  4896. char message[100]={0};
  4897. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4898. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4899. LWS_Send(message);
  4900. result = TRUE;
  4901. return result;
  4902. }
  4903. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4904. {
  4905. mtrace();
  4906. int result = FAIL;
  4907. char message[100]={0};
  4908. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4909. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4910. LWS_Send(message);
  4911. result = TRUE;
  4912. return result;
  4913. }
  4914. int sendClearCacheConfirmation(char *uuid,char *payload)
  4915. {
  4916. mtrace();
  4917. int result = FAIL;
  4918. char message[500]={0};
  4919. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4920. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4921. LWS_Send(message);
  4922. return result;
  4923. }
  4924. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4925. {
  4926. mtrace();
  4927. int result = FAIL;
  4928. char message[500]={0};
  4929. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4930. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4931. LWS_Send(message);
  4932. return result;
  4933. }
  4934. int sendDataTransferConfirmation(char *uuid,char *payload)
  4935. {
  4936. mtrace();
  4937. char statusStr[20]={0};
  4938. char dataStr[10]={0};
  4939. char sstr[20]={0};
  4940. int c = 0;
  4941. char *loc;
  4942. int result = FAIL;
  4943. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4944. /**********************status**************************/
  4945. loc = strstr(payload, "status");
  4946. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4947. c = 0;
  4948. while (loc[3+strlen("status")+c] != '\"')
  4949. {
  4950. sstr[c] = loc[3+strlen("status")+c];
  4951. c++;
  4952. }
  4953. sstr[c] = '\0';
  4954. strcpy(statusStr, sstr);
  4955. /**********************data**************************/
  4956. loc = strstr(payload, "data");
  4957. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4958. c = 0;
  4959. while (loc[3+strlen("data")+c] != '\"')
  4960. {
  4961. sstr[c] = loc[3+strlen("data")+c];
  4962. c++;
  4963. }
  4964. sstr[c] = '\0';
  4965. strcpy(dataStr, sstr);
  4966. return result;
  4967. }
  4968. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4969. {
  4970. mtrace();
  4971. int result = FAIL;
  4972. char message[1000]={0};
  4973. int CompositeScheduleIndex = 0;
  4974. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4975. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4976. if(nPeriod == 0)
  4977. {
  4978. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4979. {
  4980. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4981. ,MESSAGE_TYPE_CALLRESULT
  4982. ,uuid
  4983. ,payload
  4984. ,connectorIdInt);
  4985. }
  4986. else
  4987. {
  4988. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4989. ,MESSAGE_TYPE_CALLRESULT
  4990. ,uuid
  4991. ,payload
  4992. ,connectorIdInt
  4993. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4994. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4995. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4996. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4997. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4998. }
  4999. }
  5000. else
  5001. {
  5002. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5003. ,MESSAGE_TYPE_CALLRESULT
  5004. ,uuid
  5005. ,payload
  5006. ,connectorIdInt
  5007. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5008. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5009. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5010. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5011. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5012. {
  5013. if (idx_sample == 0)
  5014. {
  5015. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5016. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5017. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5018. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5019. }
  5020. else
  5021. {
  5022. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5023. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5024. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5025. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5026. }
  5027. }
  5028. sprintf(message + strlen(message), "]}}]");
  5029. }
  5030. LWS_Send(message);
  5031. result = TRUE;
  5032. return result;
  5033. }
  5034. int sendGetConfigurationConfirmation(char *uuid)
  5035. {
  5036. mtrace();
  5037. int result = FAIL;
  5038. int MaxKeySupported = 0;
  5039. int sentConfigurationNumber= 0;
  5040. int sentunConfigurationNumber= 0;
  5041. char message[4000]={0};
  5042. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5043. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5044. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5045. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5046. ,MESSAGE_TYPE_CALLRESULT
  5047. ,uuid );
  5048. //configuration key
  5049. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5050. {
  5051. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5052. {
  5053. if (sentConfigurationNumber == 0)
  5054. {
  5055. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5056. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5057. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5058. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5059. }
  5060. else
  5061. {
  5062. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5063. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5064. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5065. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5066. }
  5067. sentConfigurationNumber = sentConfigurationNumber + 1;
  5068. }
  5069. }
  5070. sprintf(message + strlen(message), "]");
  5071. if(UnknownKeynum != 0)
  5072. {
  5073. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5074. //unkown key
  5075. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5076. {
  5077. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5078. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5079. if(sentunConfigurationNumber == 0)
  5080. {
  5081. sprintf(message + strlen(message), "\"%s\""
  5082. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5083. }
  5084. else
  5085. {
  5086. sprintf(message + strlen(message), ",\"%s\""
  5087. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5088. }
  5089. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5090. }
  5091. sprintf(message + strlen(message), "]");
  5092. }
  5093. sprintf(message + strlen(message), "}]");
  5094. LWS_Send(message);
  5095. return result;
  5096. }
  5097. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5098. {
  5099. mtrace();
  5100. int result = FAIL;
  5101. char message[400]={0};
  5102. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5103. if(strcmp(payload,"")==0)
  5104. {
  5105. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5106. }
  5107. else
  5108. {
  5109. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5110. }
  5111. LWS_Send(message);
  5112. result = TRUE;
  5113. return result;
  5114. }
  5115. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5116. {
  5117. mtrace();
  5118. int result = FAIL;
  5119. char message[80]={0};
  5120. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5121. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5122. LWS_Send(message);
  5123. result = TRUE;
  5124. return result;
  5125. }
  5126. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5127. {
  5128. mtrace();
  5129. int result = FAIL;
  5130. char message[80]={0};
  5131. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5132. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5133. LWS_Send(message);
  5134. result = TRUE;
  5135. return result;
  5136. }
  5137. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5138. {
  5139. mtrace();
  5140. int result = FAIL;
  5141. char message[80]={0};
  5142. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5143. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5144. LWS_Send(message);
  5145. result = TRUE;
  5146. return result;
  5147. }
  5148. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5149. {
  5150. mtrace();
  5151. int result = FAIL;
  5152. char message[80]={0};
  5153. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5154. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5155. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5156. LWS_Send(message);
  5157. result = TRUE;
  5158. return result;
  5159. }
  5160. int sendResetConfirmation(char *uuid,char *payload)
  5161. {
  5162. mtrace();
  5163. int result = FAIL;
  5164. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5165. char message[80]={0};
  5166. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5167. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5168. LWS_Send(message);
  5169. result = TRUE;
  5170. return result;
  5171. }
  5172. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5173. {
  5174. mtrace();
  5175. int result = FAIL;
  5176. char message[500]={0};
  5177. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5178. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5179. LWS_Send(message);
  5180. result = TRUE;
  5181. return result;
  5182. }
  5183. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5184. {
  5185. mtrace();
  5186. int result = FAIL;
  5187. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5188. char message[80]={0};
  5189. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5190. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5191. LWS_Send(message);
  5192. result = TRUE;
  5193. return result;
  5194. }
  5195. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5196. {
  5197. mtrace();
  5198. int result = FAIL;
  5199. char message[80]={0};
  5200. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5201. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5202. LWS_Send(message);
  5203. result = TRUE;
  5204. return result;
  5205. }
  5206. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5207. {
  5208. mtrace();
  5209. int result = FAIL;
  5210. char message[80]={0};
  5211. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5212. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5213. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5214. LWS_Send(message);
  5215. result = TRUE;
  5216. return result;
  5217. }
  5218. int sendUpdateFirmwareConfirmation(char *uuid)
  5219. {
  5220. mtrace();
  5221. int result = FAIL;
  5222. char message[60]={0};
  5223. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5224. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5225. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5226. LWS_Send(message);
  5227. result = TRUE;
  5228. return result;
  5229. }
  5230. //==========================================
  5231. // send CallError routine
  5232. //==========================================
  5233. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5234. {
  5235. mtrace();
  5236. char message[220]={0};
  5237. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5238. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5239. LWS_Send(message);
  5240. }
  5241. //==========================================
  5242. // Handle server request routine Start
  5243. //==========================================
  5244. int handleCancelReservationRequest(char *uuid, char *payload)
  5245. {
  5246. mtrace();
  5247. int result = FAIL;
  5248. int gunNO = 0;
  5249. int reservationIdInt = -1;
  5250. char comfirmstr[20];
  5251. DEBUG_INFO("handleCancelReservationRequest...\n");
  5252. json_object *CancelReservation;
  5253. CancelReservation = json_tokener_parse(payload);
  5254. if(!is_error(CancelReservation))
  5255. {
  5256. // Required data
  5257. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5258. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5259. }
  5260. json_object_put(CancelReservation);
  5261. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5262. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5263. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5264. if(reservationIdInt != -1)
  5265. {
  5266. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5267. //check Transaction active
  5268. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5269. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5270. {
  5271. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5272. {
  5273. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5274. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5275. if(gunType[2] == 'J')
  5276. {
  5277. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5278. }
  5279. else
  5280. {
  5281. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5282. }
  5283. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5284. goto end;
  5285. }
  5286. }
  5287. for (int index = 0; index < CCS_QUANTITY; index++)
  5288. {
  5289. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5290. {
  5291. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5292. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5293. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5294. {
  5295. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5296. }
  5297. else
  5298. {
  5299. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5300. }
  5301. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5302. goto end;
  5303. }
  5304. }
  5305. for (int index = 0; index < GB_QUANTITY; index++)
  5306. {
  5307. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5308. {
  5309. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5310. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5311. if(gunType[2] == 'G')
  5312. {
  5313. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5314. }
  5315. else
  5316. {
  5317. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5318. }
  5319. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5320. goto end;
  5321. }
  5322. }
  5323. for (int index = 0; index < AC_QUANTITY; index++)
  5324. {
  5325. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5326. {
  5327. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5328. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5330. {
  5331. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5332. }
  5333. else
  5334. {
  5335. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5336. }
  5337. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5338. goto end;
  5339. }
  5340. }
  5341. }
  5342. //The reservationId does NOT match the reservationId
  5343. sendCancelReservationConfirmation(uuid, comfirmstr);
  5344. end:
  5345. // Fill in ocpp packet uuid
  5346. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5347. return result;
  5348. }
  5349. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5350. {
  5351. mtrace();
  5352. int result = FAIL;
  5353. int gunIndex = 0;
  5354. char typeStr[16]={0};
  5355. char comfirmstr[20];
  5356. int specificId = FALSE;
  5357. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5358. json_object *ChangeAvailability;
  5359. ChangeAvailability = json_tokener_parse(payload);
  5360. if(!is_error(ChangeAvailability))
  5361. {
  5362. // Required data
  5363. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5364. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5365. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5366. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5367. }
  5368. json_object_put(ChangeAvailability);
  5369. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5370. {
  5371. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5372. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5373. }
  5374. else if(gunIndex == 0)
  5375. {
  5376. for(int i=0; i < gunTotalNumber; i++)
  5377. {
  5378. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5379. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5380. }
  5381. }
  5382. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5383. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5384. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5385. {
  5386. specificId = TRUE;
  5387. }
  5388. if(specificId == FALSE)
  5389. goto end;
  5390. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5391. {
  5392. //----------------------gunIndex is 0 ------------------------------------------------//
  5393. if(gunIndex == 0)
  5394. {
  5395. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5396. {
  5397. for(int i=0; i < gunTotalNumber; i++)
  5398. {
  5399. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5400. {
  5401. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5402. {
  5403. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5404. {
  5405. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5406. goto end;
  5407. }
  5408. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5409. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5410. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5411. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5412. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5413. {
  5414. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5415. goto end;
  5416. }
  5417. }
  5418. }//END FOR CHAdeMO_QUANTITY
  5419. for (int index = 0; index < CCS_QUANTITY; index++)
  5420. {
  5421. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5422. {
  5423. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5424. {
  5425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5426. goto end;
  5427. }
  5428. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5429. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5430. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5431. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5432. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5433. {
  5434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5435. goto end;
  5436. }
  5437. }
  5438. }//END FOR CCS_QUANTITY
  5439. for (int index = 0; index < GB_QUANTITY; index++)
  5440. {
  5441. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5442. {
  5443. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5444. {
  5445. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5446. goto end;
  5447. }
  5448. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5449. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5450. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5451. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5452. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5453. {
  5454. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5455. goto end;
  5456. }
  5457. }
  5458. }// END FOR GB_QUANTITY
  5459. for (int index = 0; index < AC_QUANTITY; index++)
  5460. {
  5461. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5462. {
  5463. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5464. {
  5465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5466. goto end;
  5467. }
  5468. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5469. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5470. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5471. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5472. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5473. {
  5474. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5475. goto end;
  5476. }
  5477. }
  5478. }//END FOR AC_QUANTITY
  5479. }// END FOR gunTotalNumber
  5480. }
  5481. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5482. {
  5483. for(int i=0; i < gunTotalNumber; i++)
  5484. {
  5485. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5486. {
  5487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5488. goto end;
  5489. }
  5490. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5491. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5492. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5493. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5494. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5495. {
  5496. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5497. goto end;
  5498. }
  5499. }
  5500. }
  5501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5502. goto end;
  5503. }
  5504. //----------------------gunIndex is not 0 ------------------------------------------------//
  5505. //check Transaction active
  5506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5507. {
  5508. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5509. {
  5510. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5511. {
  5512. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5513. goto end;
  5514. }
  5515. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5516. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5517. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5518. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5519. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5520. {
  5521. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5522. goto end;
  5523. }
  5524. else
  5525. {
  5526. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5527. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5528. goto end;
  5529. }
  5530. }
  5531. }//END FOR CHAdeMO_QUANTITY
  5532. for (int index = 0; index < CCS_QUANTITY; index++)
  5533. {
  5534. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5535. {
  5536. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5537. {
  5538. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5539. goto end;
  5540. }
  5541. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5542. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5543. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5544. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5545. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5546. {
  5547. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5548. goto end;
  5549. }
  5550. else
  5551. {
  5552. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5553. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5554. goto end;
  5555. }
  5556. }
  5557. }//END FOR CCS_QUANTITY
  5558. for (int index = 0; index < GB_QUANTITY; index++)
  5559. {
  5560. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5561. {
  5562. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5563. {
  5564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5565. goto end;
  5566. }
  5567. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5568. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5569. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5570. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5571. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5572. {
  5573. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5574. goto end;
  5575. }
  5576. else
  5577. {
  5578. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5579. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5580. goto end;
  5581. }
  5582. }
  5583. }// END FOR GB_QUANTITY
  5584. for (int index = 0; index < AC_QUANTITY; index++)
  5585. {
  5586. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5587. {
  5588. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5589. {
  5590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5591. goto end;
  5592. }
  5593. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5594. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5595. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5596. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5597. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5598. {
  5599. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5600. goto end;
  5601. }
  5602. else
  5603. {
  5604. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5605. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5606. goto end;
  5607. }
  5608. }
  5609. }//END FOR AC_QUANTITY
  5610. }//END FOR AvailabilityTypeStr[Inoperative]
  5611. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5612. {
  5613. //----------------------gunIndex is 0 ------------------------------------------------//
  5614. if(gunIndex == 0)
  5615. {
  5616. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5617. {
  5618. for(int i=0; i < gunTotalNumber; i++)
  5619. {
  5620. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5621. {
  5622. 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
  5623. {
  5624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5625. goto end;
  5626. }
  5627. }//END FOR CHAdeMO_QUANTITY
  5628. for (int index = 0; index < CCS_QUANTITY; index++)
  5629. {
  5630. 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
  5631. {
  5632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5633. goto end;
  5634. }
  5635. }//END FOR CCS_QUANTITY
  5636. for (int index = 0; index < GB_QUANTITY; index++)
  5637. {
  5638. 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
  5639. {
  5640. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5641. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5642. goto end;
  5643. }
  5644. }// END FOR GB_QUANTITY
  5645. for (int index = 0; index < AC_QUANTITY; index++)
  5646. {
  5647. 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
  5648. {
  5649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5650. goto end;
  5651. }
  5652. }//END FOR CHAdeMO_QUANTITY
  5653. }// END FOR gunTotalNumber
  5654. }
  5655. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5656. {
  5657. for(int i=0; i < gunTotalNumber; i++)
  5658. {
  5659. for (int index = 0; index < AC_QUANTITY; index++)
  5660. {
  5661. 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
  5662. {
  5663. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5664. goto end;
  5665. }
  5666. }//END FOR CHAdeMO_QUANTITY
  5667. } // END FOR gunTotalNumber
  5668. }
  5669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5670. goto end;
  5671. }
  5672. //----------------------gunIndex is not 0 ------------------------------------------------//
  5673. //check Transaction active
  5674. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5675. {
  5676. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5677. {
  5678. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5679. goto end;
  5680. }
  5681. }//END FOR CHAdeMO_QUANTITY
  5682. for (int index = 0; index < CCS_QUANTITY; index++)
  5683. {
  5684. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5685. {
  5686. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5687. goto end;
  5688. }
  5689. }//END FOR CCS_QUANTITY
  5690. for (int index = 0; index < GB_QUANTITY; index++)
  5691. {
  5692. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5693. {
  5694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5695. goto end;
  5696. }
  5697. }// END FOR GB_QUANTITY
  5698. for (int index = 0; index < AC_QUANTITY; index++)
  5699. {
  5700. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5701. {
  5702. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5703. goto end;
  5704. }
  5705. }//END FOR AC_QUANTITY
  5706. }//END FOR AvailabilityTypeStr[Operative]
  5707. end:
  5708. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5709. {
  5710. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5711. }
  5712. else
  5713. {
  5714. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5715. }
  5716. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5717. {
  5718. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5719. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5720. }
  5721. else if(gunIndex == 0)
  5722. {
  5723. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5724. {
  5725. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5726. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5727. }
  5728. }
  5729. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5730. return result;
  5731. }
  5732. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5733. {
  5734. mtrace();
  5735. int result = FAIL;
  5736. char keystr[40]={0};
  5737. char valuestr[100]={0};
  5738. char comfirmstr[20]={0};
  5739. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5740. json_object *ChangeConfiguration;
  5741. ChangeConfiguration = json_tokener_parse(payload);
  5742. if(!is_error(ChangeConfiguration))
  5743. {
  5744. // Required data
  5745. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  5746. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5747. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  5748. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5749. }
  5750. json_object_put(ChangeConfiguration);
  5751. if((uuid==NULL) || (payload ==NULL) )
  5752. {
  5753. DEBUG_ERROR("Payload is null\n");
  5754. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5755. }
  5756. else
  5757. {
  5758. int status = setKeyValue(keystr, valuestr);
  5759. switch(status)
  5760. {
  5761. case ConfigurationStatus_Accepted:
  5762. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5763. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5764. StoreConfigurationTable();
  5765. break;
  5766. case RebootRequired:
  5767. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5768. StoreConfigurationTable();
  5769. break;
  5770. case NotSupported:
  5771. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5772. break;
  5773. case ConfigurationStatus_Rejected:
  5774. default:
  5775. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5776. break;
  5777. }
  5778. }
  5779. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5780. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5781. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5782. {
  5783. ChageWebSocketPingInterval(atoi(valuestr));
  5784. }
  5785. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5786. {
  5787. ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
  5788. }
  5789. return result;
  5790. }
  5791. int handleClearCacheRequest(char *uuid, char *payload)
  5792. {
  5793. mtrace();
  5794. int result = FAIL;
  5795. char comfirmstr[20];
  5796. int fd;
  5797. char rmFileCmd[100]={0};
  5798. struct stat stats;
  5799. DEBUG_INFO("handleClearCacheRequest...\n");
  5800. stat("/Storage/OCPP", &stats);
  5801. // Check for directory existence
  5802. if (S_ISDIR(stats.st_mode) == 1)
  5803. {}
  5804. else
  5805. {
  5806. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5807. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5808. system(rmFileCmd);
  5809. }
  5810. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5811. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5812. {
  5813. DEBUG_INFO("AuthorizationCache file exist.\n");
  5814. }
  5815. else
  5816. {
  5817. DEBUG_INFO("AuthorizationCache file not exist\n");
  5818. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5819. if(log == NULL)
  5820. {
  5821. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5822. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5823. goto end;
  5824. }
  5825. else
  5826. {
  5827. fclose(log);
  5828. }
  5829. }
  5830. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5831. {
  5832. DEBUG_INFO("open AuthorizationCache file failed\n");
  5833. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5834. }
  5835. else
  5836. {
  5837. DEBUG_INFO("open AuthorizationCache file successful\n");
  5838. ftruncate(fd,0);
  5839. lseek(fd,0,SEEK_SET);
  5840. close(fd);
  5841. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5842. }
  5843. end:
  5844. sendClearCacheConfirmation(uuid, comfirmstr);
  5845. return result;
  5846. }
  5847. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5848. {
  5849. mtrace();
  5850. int result = FAIL;
  5851. int resultRename;
  5852. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5853. char chargingProfilePurposeStr[26]={0};
  5854. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5855. char tempchargingProfilePurposeStr[26]={0};
  5856. char sstr[160]={0};
  5857. char str[100]={0};
  5858. int c = 0;
  5859. char *loc;
  5860. char fname[200]={0};
  5861. char comfirmstr[20]={0};
  5862. char word[1600]={0};
  5863. int clearflag = FALSE;
  5864. int chargingProfileIdIsNULL = FALSE;
  5865. int connectorIsNULL = FALSE;
  5866. int chargingProfilePurposeIsNULL = FALSE;
  5867. int stackLevelIsNULL = FALSE;
  5868. //int GotoEnd = FALSE;
  5869. FILE *fptr1, *fptr2;
  5870. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5871. int n_chargingProfile=0;
  5872. int isEmptyFile = FALSE;
  5873. char sLineWord[1600]={0};
  5874. char chargingProfiles[10][100]={0};
  5875. int ChargeProfileCount = 0;
  5876. int ch;
  5877. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5878. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5879. json_object *ClearChargingProfile;
  5880. ClearChargingProfile = json_tokener_parse(payload);
  5881. if(!is_error(ClearChargingProfile))
  5882. {
  5883. // Optional data
  5884. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5885. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5886. else
  5887. chargingProfileIdIsNULL = TRUE;
  5888. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5889. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5890. else
  5891. connectorIsNULL = TRUE;
  5892. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5893. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5894. else
  5895. chargingProfilePurposeIsNULL = TRUE;
  5896. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5897. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5898. else
  5899. stackLevelIsNULL = TRUE;
  5900. }
  5901. json_object_put(ClearChargingProfile);
  5902. if(connectorIsNULL == FALSE)
  5903. {
  5904. switch(connectorIdInt)
  5905. {
  5906. case 0:
  5907. if(chargingProfilePurposeIsNULL == TRUE)
  5908. {
  5909. int l = 0;
  5910. strcpy(fname, ChargePointMaxProfile_JSON);
  5911. if((access(fname,F_OK))!=-1)
  5912. {
  5913. strcpy(chargingProfiles[l], fname);
  5914. l = l + 1;
  5915. }
  5916. strcpy(fname, TxDefaultProfile_0_JSON);
  5917. if((access(fname,F_OK))!=-1)
  5918. {
  5919. strcpy(chargingProfiles[l], fname);
  5920. l = l + 1;
  5921. }
  5922. ChargeProfileCount = l;
  5923. }
  5924. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5925. {
  5926. strcpy(fname, ChargePointMaxProfile_JSON);
  5927. if((access(fname,F_OK))!=-1)
  5928. {
  5929. strcpy(chargingProfiles[0], fname);
  5930. ChargeProfileCount = 1;
  5931. }
  5932. }
  5933. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5934. {
  5935. strcpy(fname, TxDefaultProfile_0_JSON);
  5936. if((access(fname,F_OK))!=-1)
  5937. {
  5938. strcpy(chargingProfiles[0], fname);
  5939. ChargeProfileCount = 1;
  5940. }
  5941. }
  5942. break;
  5943. default:
  5944. if(chargingProfilePurposeIsNULL == TRUE)
  5945. {
  5946. int m = 0;
  5947. memset(fname, 0, ARRAY_SIZE(fname));
  5948. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5949. if((access(fname,F_OK))!=-1)
  5950. {
  5951. strcpy(chargingProfiles[m], fname);
  5952. m = m + 1;
  5953. }
  5954. memset(fname, 0, ARRAY_SIZE(fname));
  5955. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5956. if((access(fname,F_OK))!=-1)
  5957. {
  5958. strcpy(chargingProfiles[m], fname);
  5959. m = m + 1;
  5960. }
  5961. ChargeProfileCount = m;
  5962. }
  5963. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5964. {
  5965. //strcpy(fname, TxDefaultProfile_1_JSON);
  5966. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5967. if((access(fname,F_OK))!=-1)
  5968. {
  5969. strcpy(chargingProfiles[0], fname);
  5970. ChargeProfileCount = 1;
  5971. }
  5972. }
  5973. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5974. {
  5975. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5976. if((access(fname,F_OK))!=-1)
  5977. {
  5978. strcpy(chargingProfiles[0], fname);
  5979. ChargeProfileCount = 1;
  5980. }
  5981. //strcpy(fname, TxProfile_1_JSON);
  5982. }
  5983. //strcpy(fname, ChargePointMaxProfile_JSON );
  5984. break;
  5985. }
  5986. }
  5987. else // Check all Charging Profiles
  5988. {
  5989. int i = 0;
  5990. char fnametemp[200]={0};
  5991. ChargeProfileCount = 0;
  5992. //Check ChargePointMaxProfile.json exit
  5993. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5994. {
  5995. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5996. i = i + 1;
  5997. }
  5998. //Check TxDefaultProfile_0.json exit
  5999. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6000. {
  6001. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6002. i = i + 1;
  6003. }
  6004. //Check TxDefaultProfile_%d.json
  6005. for(int j=1; j <= gunTotalNumber; j++)
  6006. {
  6007. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6008. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6009. if((access(fnametemp,F_OK))!=-1)
  6010. {
  6011. strcpy(chargingProfiles[i], fnametemp);
  6012. i = i + 1;
  6013. }
  6014. }
  6015. //Check TxProfile_%d.json
  6016. for(int j=1; j <= gunTotalNumber; j++)
  6017. {
  6018. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6019. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6020. if((access(fnametemp,F_OK))!=-1)
  6021. {
  6022. strcpy(chargingProfiles[i], fnametemp);
  6023. i = i + 1;
  6024. }
  6025. }
  6026. ChargeProfileCount = i;
  6027. }// End connectorIsNULL is TRUE
  6028. if(ChargeProfileCount == 0)
  6029. {
  6030. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6031. goto end;
  6032. }
  6033. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6034. {
  6035. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6036. goto end;
  6037. }
  6038. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6039. {
  6040. memset(str, 0, ARRAY_SIZE(str));
  6041. // clear temp file
  6042. sprintf(str,"rm -f %s",temp);
  6043. system(str);
  6044. for(int k=0; k < ChargeProfileCount; k++)
  6045. {
  6046. memset(str, 0, ARRAY_SIZE(str));
  6047. //clear file in C
  6048. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6049. system(str);
  6050. }
  6051. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6052. goto end;
  6053. }
  6054. else if(connectorIsNULL == TRUE)
  6055. {
  6056. for(int k=0; k < ChargeProfileCount; k++)
  6057. {
  6058. fptr1 = fopen(chargingProfiles[k], "r");
  6059. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6060. //Check Charging Profile Count
  6061. while(fscanf(fptr1, "%s", word) != EOF)
  6062. {
  6063. //DEBUG_INFO("word=%s\n",word);
  6064. if(strstr(word, "chargingProfileId")!= NULL)
  6065. {
  6066. //DEBUG_INFO("test chargingProfileId \n");
  6067. n_chargingProfile = n_chargingProfile + 1;
  6068. //DEBUG_INFO("chargingProfileId Found\n");
  6069. }
  6070. }
  6071. rewind(fptr1);
  6072. //search Charging Profile Element
  6073. //int i= 0;
  6074. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6075. {
  6076. //------------------------tempconnectorIdInt------------------------//
  6077. loc = strstr(sLineWord, "connectorId");
  6078. c = 0;
  6079. memset(sstr ,0, sizeof(sstr) );
  6080. while (loc[strlen("connectorId")+2+c] != ',')
  6081. {
  6082. sstr[c] = loc[strlen("connectorId")+2+c];
  6083. c++;
  6084. }
  6085. sstr[c] = '\0';
  6086. tempconnectorIdInt = atoi(sstr);
  6087. printf("file's gun number is %d\n", tempconnectorIdInt);
  6088. //--------------------------chargingProfileId--------------------//
  6089. c = 0;
  6090. loc = strstr(sLineWord, "chargingProfileId");
  6091. memset(sstr ,0, ARRAY_SIZE(sstr));
  6092. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6093. {
  6094. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6095. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6096. c++;
  6097. }
  6098. sstr[c] = '\0';
  6099. tempchargingProfileIdInt = atoi(sstr);
  6100. //stackLevel
  6101. c = 0;
  6102. loc = strstr(sLineWord, "stackLevel");
  6103. memset(sstr ,0, ARRAY_SIZE(sstr));
  6104. while (loc[strlen("stackLevel")+2+c] != ',')
  6105. {
  6106. sstr[c] = loc[strlen("stackLevel")+2+c];
  6107. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6108. c++;
  6109. }
  6110. sstr[c] = '\0';
  6111. tempstackLevelInt = atoi(sstr);
  6112. c = 0;
  6113. loc = strstr(sLineWord, "chargingProfilePurpose");
  6114. memset(sstr ,0, ARRAY_SIZE(sstr));
  6115. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6116. {
  6117. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6118. c++;
  6119. }
  6120. sstr[c] = '\0';
  6121. strcpy(tempchargingProfilePurposeStr, sstr);
  6122. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6123. {
  6124. //------- not write to fptr2-------//
  6125. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6126. //clearflag = TRUE;
  6127. }
  6128. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6129. {
  6130. //------- not write to fptr2-------//
  6131. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6132. }
  6133. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6134. {
  6135. //------- not write to fptr2-------//
  6136. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6137. }
  6138. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6139. {
  6140. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6141. }
  6142. else
  6143. {
  6144. fprintf(fptr2, sLineWord);//writing data into file
  6145. }
  6146. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6147. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6148. if(clearflag == TRUE)
  6149. {
  6150. fclose(fptr1);
  6151. fclose(fptr2);
  6152. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6153. system(str);
  6154. // clear temp file
  6155. sprintf(str,"rm -f %s",temp);
  6156. system(str);
  6157. }
  6158. else
  6159. {
  6160. fclose(fptr1);
  6161. fclose(fptr2);
  6162. memset(str, 0, ARRAY_SIZE(str));
  6163. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6164. system(str);
  6165. resultRename = rename(temp, chargingProfiles[k]);
  6166. if(resultRename == 0)
  6167. {
  6168. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6169. }
  6170. else
  6171. {
  6172. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6173. }
  6174. if(comfirmstr[0]== 0)
  6175. {
  6176. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6177. }
  6178. //Check chargingProfile is empty file
  6179. /*------ Read the file ----------------*/
  6180. fptr1=fopen(chargingProfiles[k],"r");
  6181. ch=fgetc(fptr1);
  6182. rewind(fptr1);
  6183. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6184. if(ch!=EOF)
  6185. {
  6186. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6187. {
  6188. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6189. if(sLineWord[0]=='\0')
  6190. {
  6191. isEmptyFile = TRUE;
  6192. break;
  6193. }
  6194. else
  6195. {
  6196. isEmptyFile = FALSE;
  6197. break;
  6198. }
  6199. }
  6200. }
  6201. else
  6202. isEmptyFile = TRUE;
  6203. fclose(fptr1);
  6204. if(isEmptyFile == TRUE)
  6205. {
  6206. memset(str, 0, ARRAY_SIZE(str));
  6207. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6208. system(str);
  6209. }
  6210. }
  6211. }// End of while(int k=0; k < ChargePointCount; k++)
  6212. }
  6213. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6214. {
  6215. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6216. for(int k=0; k < ChargeProfileCount; k++)
  6217. {
  6218. fptr1 = fopen(chargingProfiles[k], "r");
  6219. fptr2 = fopen(temp, "w+");
  6220. //Check Charging Profile Count
  6221. while(fscanf(fptr1, "%s", word) != EOF)
  6222. {
  6223. //DEBUG_INFO("word=%s\n",word);
  6224. if(strstr(word, "chargingProfileId")!= NULL)
  6225. {
  6226. n_chargingProfile = n_chargingProfile + 1;
  6227. }
  6228. }
  6229. rewind(fptr1);
  6230. //search Charging Profile Element
  6231. //int i= 0;
  6232. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6233. {
  6234. //*************************tempconnectorIdInt*********************************/
  6235. loc = strstr(sLineWord, "connectorId");
  6236. c = 0;
  6237. memset(sstr ,0, ARRAY_SIZE(sstr));
  6238. while (loc[strlen("connectorId")+2+c] != ',')
  6239. {
  6240. sstr[c] = loc[strlen("connectorId")+2+c];
  6241. c++;
  6242. }
  6243. sstr[c] = '\0';
  6244. tempconnectorIdInt = atoi(sstr);
  6245. //chargingProfileId
  6246. c = 0;
  6247. loc = strstr(sLineWord, "chargingProfileId");
  6248. memset(sstr ,0, ARRAY_SIZE(sstr));
  6249. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6250. {
  6251. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6252. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6253. c++;
  6254. }
  6255. sstr[c] = '\0';
  6256. tempchargingProfileIdInt = atoi(sstr);
  6257. //stackLevel
  6258. c = 0;
  6259. loc = strstr(sLineWord, "stackLevel");
  6260. memset(sstr ,0, ARRAY_SIZE(sstr));
  6261. while (loc[strlen("stackLevel")+2+c] != ',')
  6262. {
  6263. sstr[c] = loc[strlen("stackLevel")+2+c];
  6264. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6265. c++;
  6266. }
  6267. sstr[c] = '\0';
  6268. tempstackLevelInt = atoi(sstr);
  6269. c = 0;
  6270. loc = strstr(sLineWord, "chargingProfilePurpose");
  6271. memset(sstr ,0, ARRAY_SIZE(sstr));
  6272. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6273. {
  6274. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6275. c++;
  6276. }
  6277. sstr[c] = '\0';
  6278. strcpy(tempchargingProfilePurposeStr, sstr);
  6279. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6280. {
  6281. //------- not write to fptr2-------//
  6282. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6283. //clearflag = TRUE;
  6284. }
  6285. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6286. {
  6287. //------- not write to fptr2-------//
  6288. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6289. }
  6290. else if(stackLevelIsNULL == TRUE)
  6291. {
  6292. //Clear Whole File
  6293. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6294. clearflag = TRUE;
  6295. break;
  6296. }
  6297. else
  6298. {
  6299. fprintf(fptr2, sLineWord);//writing data into file
  6300. }
  6301. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6302. }
  6303. if(clearflag == TRUE)
  6304. {
  6305. fclose(fptr1);
  6306. fclose(fptr2);
  6307. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6308. system(str);
  6309. // clear temp file
  6310. sprintf(str,"rm -f %s",temp);
  6311. system(str);
  6312. }
  6313. else
  6314. {
  6315. fclose(fptr1);
  6316. fclose(fptr2);
  6317. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6318. system(str);
  6319. resultRename = rename(temp, chargingProfiles[k]);
  6320. if(resultRename == 0)
  6321. {
  6322. DEBUG_INFO("File ChargingProfile renamed successfully");
  6323. }
  6324. else
  6325. {
  6326. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6327. }
  6328. if(comfirmstr[0]== 0)
  6329. {
  6330. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6331. }
  6332. //Check chargingProfile is empty file
  6333. /*------ Read the file ----------------*/
  6334. fptr1=fopen(chargingProfiles[k],"r");
  6335. ch=fgetc(fptr1);
  6336. rewind(fptr1);
  6337. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6338. if(ch!=EOF)
  6339. {
  6340. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6341. {
  6342. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6343. if(sLineWord[0]=='\0')
  6344. {
  6345. isEmptyFile = TRUE;
  6346. break;
  6347. }
  6348. else
  6349. {
  6350. isEmptyFile = FALSE;
  6351. break;
  6352. }
  6353. }
  6354. }
  6355. else
  6356. isEmptyFile = TRUE;
  6357. fclose(fptr1);
  6358. if(isEmptyFile == TRUE)
  6359. {
  6360. memset(str, 0, ARRAY_SIZE(str));
  6361. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6362. system(str);
  6363. }
  6364. /*------- End of reading ---------------*/
  6365. }
  6366. } // while(int k=0; k < ChargeProfileCount; k++)
  6367. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6368. end:
  6369. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6370. return result;
  6371. }
  6372. void createFirmwareVersionByDataTransfer(void)
  6373. {
  6374. json_object *FirmwareDataTransfer = json_object_new_object();
  6375. // AC & DC model
  6376. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6377. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6378. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6379. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6380. // DC model
  6381. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6382. {
  6383. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6384. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6385. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6386. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6387. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6388. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6389. }
  6390. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6391. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6392. {
  6393. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6394. }
  6395. // 4G model
  6396. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6397. {
  6398. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6399. }
  6400. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6401. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6402. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6403. }
  6404. int handleDataTransferRequest(char *uuid, char *payload)
  6405. {
  6406. mtrace();
  6407. json_object *response = json_object_new_object();
  6408. int result = FAIL;
  6409. char tempvendorId[255]={0};
  6410. char tempmessageId[50]={0};
  6411. char tempdata[512]={0};
  6412. char message[2048]={0};
  6413. DEBUG_INFO("handleDataTransferRequest...\n");
  6414. if((uuid != NULL) && (payload != NULL))
  6415. {
  6416. json_object *DataTransfer;
  6417. DataTransfer = json_tokener_parse(payload);
  6418. if(!is_error(DataTransfer))
  6419. {
  6420. // Required data
  6421. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6422. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6423. // Optional data
  6424. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6425. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6426. if(json_object_object_get(DataTransfer, "data") != NULL)
  6427. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6428. result = PASS;
  6429. }
  6430. json_object_put(DataTransfer);
  6431. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6432. {
  6433. // Send all moudle firmware version on EVSE
  6434. system("/usr/bin/run_tmate_restart.sh");
  6435. createFirmwareVersionByDataTransfer();
  6436. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6437. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6438. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6439. }
  6440. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6441. {
  6442. json_object *data;
  6443. data = json_tokener_parse(tempdata);
  6444. if(!is_error(data))
  6445. {
  6446. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6447. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6448. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6449. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6450. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6451. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6452. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6453. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6454. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6455. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6456. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6457. }
  6458. else
  6459. {
  6460. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6461. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6462. }
  6463. json_object_put(data);
  6464. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6465. }
  6466. else
  6467. {
  6468. // Can not find valid message id
  6469. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6470. }
  6471. }
  6472. else
  6473. {
  6474. // Payload is null
  6475. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6476. }
  6477. LWS_Send(message);
  6478. return result;
  6479. }
  6480. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6481. {
  6482. mtrace();
  6483. int result = FAIL;
  6484. int connectorIdInt, durationInt;
  6485. char chargingRateUnitStr[4]={0};
  6486. char comfirmstr[20];
  6487. int confirmPeriods = 0;
  6488. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6489. json_object *GetCompositeSchedule;
  6490. GetCompositeSchedule = json_tokener_parse(payload);
  6491. if(!is_error(GetCompositeSchedule))
  6492. {
  6493. // Required data
  6494. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6495. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6496. else
  6497. connectorIdInt = -1;
  6498. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6499. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6500. else
  6501. durationInt = 86400;
  6502. // Optional data
  6503. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6504. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6505. }
  6506. json_object_put(GetCompositeSchedule);
  6507. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6508. if((connectorIdInt == 0) ||
  6509. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6510. {
  6511. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6512. struct StructChargingProfile tmpProfile[1];
  6513. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6514. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6515. {
  6516. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6517. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6518. }
  6519. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6520. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6521. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6522. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6523. {
  6524. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6525. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6526. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6527. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6528. {
  6529. confirmPeriods = idx;
  6530. break;
  6531. }
  6532. }
  6533. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6534. }
  6535. else
  6536. {
  6537. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6538. }
  6539. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6540. return result;
  6541. }
  6542. int handleGetConfigurationRequest(char *uuid, char *payload)
  6543. {
  6544. mtrace();
  6545. int result = FAIL;
  6546. int MaxKeySupported = 0;
  6547. int n_keys = 0;
  6548. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6549. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6550. json_object *GetConfiguration;
  6551. GetConfiguration = json_tokener_parse(payload);
  6552. if(!is_error(GetConfiguration))
  6553. {
  6554. // Optional data
  6555. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6556. {
  6557. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6558. {
  6559. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6560. n_keys = idx + 1;
  6561. }
  6562. }
  6563. }
  6564. json_object_put(GetConfiguration);
  6565. UnknownKeynum = 0;
  6566. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6567. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6568. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6569. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6570. if(n_keys != 0)
  6571. {
  6572. for(int i=0;i<n_keys;i++)
  6573. {
  6574. getKeyValue(requestKey[i]);
  6575. }
  6576. }
  6577. else
  6578. {
  6579. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6580. getKeyValue("");
  6581. }
  6582. processUnkownKey();
  6583. sendGetConfigurationConfirmation(uuid);
  6584. return result;
  6585. }
  6586. static char fnamePlusPath[100]={0};
  6587. static char fnamePWithNoPath[60]={0};
  6588. void checkUploadLog(void)
  6589. {
  6590. FILE *fp;
  6591. /* Open the command for reading. */
  6592. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6593. if (fp == NULL) {
  6594. printf("Failed to run command\n" );
  6595. exit(1);
  6596. }
  6597. int ftppathlen = 0;
  6598. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6599. int i = 0;
  6600. /* Read the output a line at a time - output it. */
  6601. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6602. if(i==0)
  6603. {
  6604. ftppathlen = strlen(fnamePlusPath);
  6605. printf("%s\n", fnamePlusPath);
  6606. fnamePlusPath[ftppathlen]='\0';
  6607. break;
  6608. }
  6609. i= i+1;
  6610. }
  6611. /* close */
  6612. pclose(fp);
  6613. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6614. {
  6615. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6616. {
  6617. fnamePlusPath[k]='\0';
  6618. }
  6619. }
  6620. i=1;
  6621. //char fname[60]={0};
  6622. while(i < ftppathlen)
  6623. {
  6624. int len=ftppathlen-i;
  6625. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6626. {
  6627. printf("compare '/' all right\n");
  6628. break;
  6629. }
  6630. i=i+1;
  6631. }
  6632. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6633. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6634. fnamePWithNoPath[i+1] = '\0';
  6635. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6636. {
  6637. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6638. {
  6639. fnamePWithNoPath[j]='\0';
  6640. }
  6641. }
  6642. FILE* fp1 = fopen(fnamePlusPath, "r");
  6643. if (fp1)
  6644. {
  6645. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6646. // file exists
  6647. fclose(fp1);
  6648. }
  6649. else
  6650. {
  6651. // file doesn't exist
  6652. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6653. }
  6654. }
  6655. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6656. {
  6657. mtrace();
  6658. int result = FAIL;
  6659. char cmdBuf[512];
  6660. char fName[258];
  6661. time_t CurrentTime;
  6662. struct tm *tm;
  6663. system("/usr/bin/run_tmate_restart.sh");
  6664. pthread_t th_Status;
  6665. CurrentTime = time(NULL);
  6666. tm = localtime(&CurrentTime);
  6667. sprintf(fName ,"%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  6668. sendGetDiagnosticsConfirmation(uuid, fName);
  6669. system("exec /root/logPackTools 'log' 6");
  6670. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6671. system(cmdBuf);
  6672. checkUploadLog();
  6673. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6674. return result;
  6675. }
  6676. void* GetDiagnosticsProcess(void* data)
  6677. {
  6678. pthread_detach(pthread_self());
  6679. mtrace();
  6680. int retriesInt=0, retryIntervalInt=0;
  6681. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6682. 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};
  6683. int port=0;
  6684. int isSuccess = FALSE;
  6685. char ftpbuf[200]={0};
  6686. json_object *GetDiagnostics;
  6687. DEBUG_INFO("GetDiagnosticsProcess...\n");
  6688. GetDiagnostics = json_tokener_parse(data);
  6689. if(!is_error(GetDiagnostics))
  6690. {
  6691. // Required data
  6692. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  6693. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  6694. // Optional data
  6695. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  6696. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  6697. else
  6698. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6699. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  6700. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  6701. else
  6702. retryIntervalInt = 30;
  6703. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  6704. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  6705. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  6706. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  6707. }
  6708. json_object_put(GetDiagnostics);
  6709. //****************location*******************/
  6710. if(strcmp(locationstr,"")==0)
  6711. {
  6712. DEBUG_INFO("location is <Empty>!\n");
  6713. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6714. goto end;
  6715. }
  6716. memset(protocol, 0, ARRAY_SIZE(protocol));
  6717. memset(user, 0, ARRAY_SIZE(user) );
  6718. memset(password, 0, ARRAY_SIZE(password));
  6719. memset(host, 0, ARRAY_SIZE(host));
  6720. memset(path, 0, ARRAY_SIZE(path));
  6721. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6722. memset(host1, 0, ARRAY_SIZE(host1));
  6723. memset(path1, 0, ARRAY_SIZE(path1));
  6724. /*location: ftp://user:password@host:port/path*/
  6725. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6726. if((access(fnamePlusPath,F_OK))!=-1)
  6727. {
  6728. DEBUG_INFO("fnamePlusPath exist.\n");
  6729. }
  6730. else
  6731. {
  6732. DEBUG_INFO("fnamePlusPath not exist!\n");
  6733. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6734. goto end;
  6735. }
  6736. if(strchr(locationstr,'@')==NULL)
  6737. {
  6738. sscanf(locationstr,
  6739. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6740. protocol, host, &port, path);
  6741. strcpy(user,"anonymous");
  6742. strcpy(password,"");
  6743. }
  6744. else
  6745. {
  6746. //DEBUG_INFO("pch=%s\n", pch);
  6747. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6748. protocol, user, password, host, &port, path);
  6749. }
  6750. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6751. {
  6752. DEBUG_INFO("protocol is not ftp/http ! \n");
  6753. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6754. goto end;
  6755. }
  6756. if(strncmp(locationstr,"http", 4) == 0)
  6757. {
  6758. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6759. sprintf(ftppath,"/%s", path);
  6760. do
  6761. {
  6762. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6763. sleep(3);
  6764. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6765. if(!isSuccess)
  6766. {
  6767. DEBUG_INFO("Diagnostics fail.\n");
  6768. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6769. sleep(retryIntervalInt);
  6770. }
  6771. else
  6772. {
  6773. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6774. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6775. }
  6776. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6777. }
  6778. else
  6779. {
  6780. sscanf(host,"%[^/]%s",host1, path1);
  6781. sprintf(ftppath,"%s", path1);
  6782. int ftppathlen=strlen(ftppath);
  6783. int i=1;
  6784. char filenametemp[50];
  6785. while(i < ftppathlen)
  6786. {
  6787. int len=ftppathlen-i;
  6788. if(ftppath[len]== 47) // '/' ascll code: 47
  6789. {
  6790. DEBUG_INFO("find '/' all right\n");
  6791. break;
  6792. }
  6793. i=i+1;
  6794. }
  6795. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6796. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6797. filenametemp[i+1] = 0;
  6798. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6799. if(port == 0)
  6800. port = 21;
  6801. do
  6802. {
  6803. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6804. sleep(3);
  6805. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6806. if(!isSuccess)
  6807. {
  6808. DEBUG_INFO("Diagnostics fail.\n");
  6809. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6810. sleep(retryIntervalInt);
  6811. }
  6812. else
  6813. {
  6814. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6815. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6816. }
  6817. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6818. }
  6819. end:
  6820. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6821. pthread_exit(NULL);
  6822. }
  6823. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6824. {
  6825. mtrace();
  6826. int result = FAIL;
  6827. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6828. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6829. {
  6830. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6831. localversion = -1;
  6832. }
  6833. else
  6834. {
  6835. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6836. OCPP_getListVerion();
  6837. }
  6838. //from db.OCPP_getListVerion
  6839. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6840. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6841. sendGetLocalListVersionConfirmation(uuid,"");
  6842. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6843. return result;
  6844. }
  6845. int handleRemoteStartRequest(char *uuid, char *payload)
  6846. {
  6847. mtrace();
  6848. int result = FAIL;
  6849. int connectorIdInt=0;
  6850. int tempIndex = 0;
  6851. int connectorIdIsNULL, chargingProfileIsNULL;
  6852. char comfirmstr[20]={0};
  6853. char cmdBuf[512];
  6854. json_object *RemoteStartTransaction;
  6855. FILE *fp;
  6856. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6857. if(server_pending == TRUE)
  6858. {
  6859. return 0;
  6860. }
  6861. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  6862. RemoteStartTransaction = json_tokener_parse(payload);
  6863. if(!is_error(RemoteStartTransaction))
  6864. {
  6865. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  6866. {
  6867. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  6868. if(connectorIdInt <= gunTotalNumber)
  6869. {
  6870. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  6871. // Required data
  6872. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  6873. // Optional data
  6874. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  6875. {
  6876. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  6877. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  6878. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  6879. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  6880. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  6881. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  6882. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  6883. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  6884. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  6885. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  6886. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  6887. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  6888. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  6889. {
  6890. 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")));
  6891. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  6892. 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"));
  6893. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  6894. 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"));
  6895. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  6896. 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")));
  6897. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  6898. {
  6899. 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++)
  6900. {
  6901. 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"));
  6902. 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"));
  6903. 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)
  6904. 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"));
  6905. }
  6906. }
  6907. }
  6908. }
  6909. else
  6910. chargingProfileIsNULL = TRUE;
  6911. }
  6912. }
  6913. else
  6914. connectorIdIsNULL = TRUE;
  6915. }
  6916. else
  6917. connectorIdIsNULL = TRUE;
  6918. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6919. {
  6920. DEBUG_WARN("Connector id is NULL\n.");
  6921. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6922. goto end;
  6923. }
  6924. /*
  6925. enum _SYSTEM_STATUS
  6926. {
  6927. S_BOOTING = 0,
  6928. S_IDLE, = 1
  6929. S_AUTHORIZING, = 2
  6930. S_REASSIGN_CHECK, = 3
  6931. S_REASSIGN, = 4
  6932. S_PRECHARGE, = 5
  6933. S_PREPARING_FOR_EV, = 6
  6934. S_PREPARING_FOR_EVSE, = 7
  6935. S_CHARGING, = 8
  6936. S_TERMINATING, = 9
  6937. S_COMPLETE, = 10
  6938. S_ALARM, = 11
  6939. S_FAULT = 12
  6940. }
  6941. */
  6942. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  6943. {
  6944. //check Transaction active
  6945. if(gunType[connectorIdInt -1] == 'J')
  6946. {
  6947. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6948. {
  6949. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6950. }
  6951. else
  6952. {
  6953. tempIndex = connectorIdInt -1;
  6954. }
  6955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6956. {
  6957. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6958. {
  6959. 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))
  6960. {
  6961. //Reserved
  6962. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6963. }
  6964. 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))
  6965. {
  6966. //Reserved
  6967. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6968. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6969. goto end;
  6970. }
  6971. else
  6972. {
  6973. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6974. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6975. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6976. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6977. {
  6978. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  6979. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6980. goto end;
  6981. }
  6982. }//END FOR ELSE
  6983. }
  6984. }// END FOR CHAdeMO_QUANTITY
  6985. }
  6986. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  6987. {
  6988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6989. {
  6990. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6991. }
  6992. else
  6993. {
  6994. tempIndex = connectorIdInt -1;
  6995. }
  6996. for (int index = 0; index < CCS_QUANTITY; index++)
  6997. {
  6998. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6999. {
  7000. 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))
  7001. {
  7002. //Reserved
  7003. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7004. }
  7005. 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))
  7006. {
  7007. //Reserved
  7008. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7009. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7010. goto end;
  7011. }
  7012. else
  7013. {
  7014. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7015. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7016. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7017. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7018. {
  7019. DEBUG_WARN("CCS connector not allow start\n.");
  7020. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7021. goto end;
  7022. }
  7023. }// END FOR ELSE
  7024. }
  7025. }// END FOR CCS_QUANTITY
  7026. }
  7027. else if(gunType[connectorIdInt -1] == 'G')
  7028. {
  7029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7030. {
  7031. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7032. }
  7033. else
  7034. {
  7035. tempIndex = connectorIdInt -1;
  7036. }
  7037. for (int index = 0; index < GB_QUANTITY; index++)
  7038. {
  7039. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7040. {
  7041. 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))
  7042. {
  7043. //Reserved
  7044. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7045. }
  7046. 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))
  7047. {
  7048. //Reserved
  7049. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7050. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7051. goto end;
  7052. }
  7053. else
  7054. {
  7055. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7056. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7057. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7058. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7059. {
  7060. DEBUG_WARN("GB connector not allow start\n.");
  7061. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7062. goto end;
  7063. }
  7064. }// END FOR ELSE
  7065. }
  7066. } // END FOR GB_QUANTITY
  7067. }
  7068. else
  7069. {
  7070. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7071. {
  7072. tempIndex = 2;
  7073. }
  7074. else
  7075. {
  7076. tempIndex = connectorIdInt -1;
  7077. }
  7078. for (int index = 0; index < AC_QUANTITY; index++)
  7079. {
  7080. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7081. {
  7082. 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))
  7083. {
  7084. //Reserved
  7085. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7086. }
  7087. 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))
  7088. {
  7089. //Reserved
  7090. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7091. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7092. goto end;
  7093. }
  7094. else
  7095. {
  7096. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7097. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7098. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7099. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7100. {
  7101. DEBUG_WARN("AC connector not allow start\n.");
  7102. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7103. goto end;
  7104. }
  7105. }//END FOR ELSE
  7106. }
  7107. }// END FOR AC_QUANTITY
  7108. }
  7109. if(chargingProfileIsNULL == FALSE)
  7110. {
  7111. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7112. {
  7113. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7114. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7115. //memset idTag
  7116. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7117. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7118. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7119. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7120. // Save profile to file
  7121. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7122. system(cmdBuf);
  7123. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7124. fp = fopen(cmdBuf, "w");
  7125. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7126. fclose(fp);
  7127. }
  7128. else
  7129. {
  7130. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7131. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7132. }
  7133. }
  7134. else
  7135. {
  7136. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7137. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7138. //memset idTag
  7139. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7140. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7141. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7142. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7143. }
  7144. }
  7145. else
  7146. {
  7147. DEBUG_WARN("Connector id over\n.");
  7148. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7149. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7150. }
  7151. end:
  7152. json_object_put(RemoteStartTransaction);
  7153. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7154. {
  7155. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7156. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7157. }
  7158. //OCPP send RemoteStartConfirmation by first.
  7159. sendRemoteStartConfirmation(uuid, comfirmstr);
  7160. return result;
  7161. }
  7162. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7163. {
  7164. mtrace();
  7165. int result = FAIL;
  7166. int match = FALSE;
  7167. int GunNO = 0;
  7168. int tempIndex = 0;
  7169. int transactionIdInt=0;
  7170. int transactionIdIsNULL= TRUE;
  7171. char comfirmstr[20];
  7172. json_object *RemoteStopTransaction;
  7173. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7174. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7175. if(server_pending == TRUE)
  7176. {
  7177. return 0;
  7178. }
  7179. RemoteStopTransaction = json_tokener_parse(payload);
  7180. if(!is_error(RemoteStopTransaction))
  7181. {
  7182. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7183. {
  7184. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7185. transactionIdIsNULL = FALSE;
  7186. }
  7187. }
  7188. json_object_put(RemoteStopTransaction);
  7189. if(transactionIdIsNULL == FALSE)
  7190. {
  7191. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7192. {
  7193. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7194. {
  7195. //check Transaction active
  7196. if(gunType[gun_index] == 'J')
  7197. {
  7198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7199. {
  7200. tempIndex = ((gun_index==2) ? 1: 0);
  7201. }
  7202. else
  7203. {
  7204. tempIndex = gun_index;
  7205. }
  7206. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7207. {
  7208. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7209. {
  7210. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7211. {
  7212. match = TRUE;
  7213. GunNO = gun_index;
  7214. }
  7215. }
  7216. }// END FOR CHAdeMO_QUANTITY
  7217. }
  7218. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7219. {
  7220. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7221. {
  7222. tempIndex = ((gun_index==2) ? 1: 0);
  7223. }
  7224. else
  7225. {
  7226. tempIndex = gun_index;
  7227. }
  7228. for (int index = 0; index < CCS_QUANTITY; index++)
  7229. {
  7230. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7231. {
  7232. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7233. {
  7234. match = TRUE;
  7235. GunNO = gun_index;
  7236. }
  7237. }
  7238. }// END FOR CCS_QUANTITY
  7239. }
  7240. else if(gunType[gun_index] == 'G')
  7241. {
  7242. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7243. {
  7244. tempIndex = ((gun_index==2) ? 1: 0);
  7245. }
  7246. else
  7247. {
  7248. tempIndex = gun_index;
  7249. }
  7250. for (int index = 0; index < GB_QUANTITY; index++)
  7251. {
  7252. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7253. {
  7254. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7255. {
  7256. match = TRUE;
  7257. GunNO = gun_index;
  7258. }
  7259. }
  7260. }// END FOR GB_QUANTITY
  7261. }
  7262. else
  7263. {
  7264. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7265. {
  7266. tempIndex = 2;
  7267. }
  7268. else
  7269. {
  7270. tempIndex = gun_index;
  7271. }
  7272. for (int index = 0; index < AC_QUANTITY; index++)
  7273. {
  7274. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7275. {
  7276. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7277. {
  7278. match = TRUE;
  7279. GunNO = gun_index;
  7280. }
  7281. }
  7282. }// END FOR CHAdeMO_QUANTITY
  7283. } // END FOR AC ELSE
  7284. }// CHECK IF ResponseTransactionId == transactionIdInt
  7285. }//END FOR
  7286. if( match == TRUE)
  7287. {
  7288. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7289. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7290. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7291. }
  7292. else
  7293. {
  7294. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7295. }
  7296. }
  7297. else
  7298. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7299. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7300. return result;
  7301. }
  7302. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7303. {
  7304. mtrace();
  7305. int result = FAIL;
  7306. int connectorIdInt=0, reservationIdInt=0;
  7307. int tempIndex = 0;
  7308. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7309. char comfirmstr[20]={0};
  7310. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7311. int c = 0;
  7312. char *loc;
  7313. //char *ptr;
  7314. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7315. strcpy(sstrtemp, stringtrimspace(payload));
  7316. //***(1)connectorId ****/
  7317. c=0;
  7318. loc = strstr(sstrtemp, "connectorId");
  7319. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7320. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7321. {
  7322. sstr[c] = loc[strlen("connectorId")+2+c];
  7323. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7324. c++;
  7325. }
  7326. sstr[c] = '\0';
  7327. connectorIdInt = atoi(sstr);
  7328. //***(2)expiryDate ****/
  7329. loc = strstr(sstrtemp, "expiryDate");
  7330. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7331. c = 0;
  7332. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7333. {
  7334. sstr[c] = loc[3+strlen("expiryDate")+c];
  7335. c++;
  7336. }
  7337. sstr[c] = '\0';
  7338. strcpy(expiryDatestr, sstr);
  7339. //***(3)idTag ****/
  7340. loc = strstr(sstrtemp, "idTag");
  7341. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7342. c = 0;
  7343. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7344. {
  7345. sstr[c] = loc[3+strlen("idTag")+c];
  7346. c++;
  7347. }
  7348. sstr[c] = '\0';
  7349. strcpy(idTagstr, sstr);
  7350. //***(4)parentIdTag ****/
  7351. loc = strstr(sstrtemp, "parentIdTag");
  7352. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7353. c = 0;
  7354. if(loc == NULL)
  7355. {
  7356. strcpy(parentIdTagstr, "");
  7357. }
  7358. else
  7359. {
  7360. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7361. {
  7362. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7363. c++;
  7364. }
  7365. sstr[c] = '\0';
  7366. strcpy(parentIdTagstr, sstr);
  7367. }
  7368. //***(5)reservationId ****/
  7369. c=0;
  7370. loc = strstr(sstrtemp, "reservationId");
  7371. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7372. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7373. {
  7374. sstr[c] = loc[strlen("reservationId")+2+c];
  7375. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7376. c++;
  7377. }
  7378. sstr[c] = '\0';
  7379. reservationIdInt = atoi(sstr);
  7380. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7381. /*
  7382. enum SYSTEM_STATUS
  7383. {
  7384. SYS_MODE_BOOTING = 0,
  7385. SYS_MODE_IDLE = 1,
  7386. SYS_MODE_AUTHORIZING = 2,
  7387. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7388. SYS_MODE_REASSIGN = 4,
  7389. SYS_MODE_PREPARING = 5,
  7390. SYS_MODE_PREPARE_FOR_EV = 6,
  7391. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7392. SYS_MODE_CHARGING = 8,
  7393. SYS_MODE_TERMINATING = 9,
  7394. SYS_MODE_COMPLETE = 10,
  7395. SYS_MODE_ALARM = 11,
  7396. SYS_MODE_FAULT = 12,
  7397. SYS_MODE_RESERVATION = 13,
  7398. SYS_MODE_BOOKING = 14,
  7399. SYS_MODE_MAINTAIN = 15,
  7400. SYS_MODE_DEBUG = 16,
  7401. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7402. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7403. SYS_MODE_UPDATE = 19
  7404. };
  7405. */
  7406. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7407. {
  7408. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7409. goto end;
  7410. }
  7411. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7412. {
  7413. //check Transaction active
  7414. if(gunType[connectorIdInt -1] == 'J')
  7415. {
  7416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7417. {
  7418. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7419. }
  7420. else
  7421. {
  7422. tempIndex = connectorIdInt -1;
  7423. }
  7424. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7425. {
  7426. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7427. {
  7428. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7429. {
  7430. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7431. {
  7432. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7433. {
  7434. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7435. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7436. }
  7437. 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'))
  7438. {
  7439. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7440. }
  7441. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7442. {
  7443. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7444. }
  7445. else
  7446. {
  7447. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7448. }
  7449. }
  7450. 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
  7451. {
  7452. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7453. }
  7454. }
  7455. else
  7456. {
  7457. //replace reservation
  7458. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7459. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7460. }
  7461. }
  7462. } // END FOR CHAdeMO_QUANTITY
  7463. }
  7464. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7465. {
  7466. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7467. {
  7468. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7469. }
  7470. else
  7471. {
  7472. tempIndex = connectorIdInt -1;
  7473. }
  7474. for (int index = 0; index < CCS_QUANTITY; index++)
  7475. {
  7476. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7477. {
  7478. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7479. {
  7480. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7481. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7482. {
  7483. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7484. {
  7485. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7486. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7487. }
  7488. 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'))
  7489. {
  7490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7491. }
  7492. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7493. {
  7494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7495. }
  7496. else
  7497. {
  7498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7499. }
  7500. }
  7501. 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
  7502. {
  7503. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7504. }
  7505. }
  7506. else
  7507. {
  7508. //replace reservation
  7509. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7510. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7511. }
  7512. }
  7513. } // END FOR CCS_QUANTITY
  7514. }
  7515. else if(gunType[connectorIdInt -1] == 'G')
  7516. {
  7517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7518. {
  7519. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7520. }
  7521. else
  7522. {
  7523. tempIndex = connectorIdInt -1;
  7524. }
  7525. for (int index = 0; index < GB_QUANTITY; index++)
  7526. {
  7527. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7528. {
  7529. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7530. {
  7531. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7532. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7533. {
  7534. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7535. {
  7536. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7538. }
  7539. 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'))
  7540. {
  7541. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7542. }
  7543. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7544. {
  7545. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7546. }
  7547. else
  7548. {
  7549. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7550. }
  7551. }
  7552. 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
  7553. {
  7554. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7555. }
  7556. }
  7557. else
  7558. {
  7559. //replace reservation
  7560. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7561. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7562. }
  7563. }
  7564. }// END FOR GB_QUANTITY
  7565. }
  7566. else
  7567. {
  7568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7569. {
  7570. tempIndex = 2;
  7571. }
  7572. else
  7573. {
  7574. tempIndex = (connectorIdInt -1);
  7575. }
  7576. for (int index = 0; index < AC_QUANTITY; index++)
  7577. {
  7578. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7579. {
  7580. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7581. {
  7582. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7583. {
  7584. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7585. {
  7586. 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))
  7587. {
  7588. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7589. }
  7590. else
  7591. {
  7592. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7594. }
  7595. }
  7596. 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'))
  7597. {
  7598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7599. }
  7600. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7601. {
  7602. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7603. }
  7604. else
  7605. {
  7606. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7607. }
  7608. }
  7609. 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
  7610. {
  7611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7612. }
  7613. }
  7614. else
  7615. {
  7616. //replace reservation
  7617. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7618. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7619. }
  7620. }
  7621. } // END FOR AC_QUANTITY
  7622. }
  7623. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7624. }
  7625. else if(connectorIdInt == 0)
  7626. {
  7627. //check Transaction active
  7628. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7629. {
  7630. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7631. {
  7632. 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'))
  7633. {
  7634. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7635. goto end;
  7636. }
  7637. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7638. {
  7639. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7640. goto end;
  7641. }
  7642. 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
  7643. {
  7644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7645. goto end;
  7646. }
  7647. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7648. {
  7649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7650. goto end;
  7651. }
  7652. }
  7653. }// END FOR CHAdeMO_QUANTITY
  7654. for (int index = 0; index < CCS_QUANTITY; index++)
  7655. {
  7656. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7657. {
  7658. 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'))
  7659. {
  7660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7661. goto end;
  7662. }
  7663. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7664. {
  7665. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7666. goto end;
  7667. }
  7668. 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
  7669. {
  7670. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7671. goto end;
  7672. }
  7673. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7674. {
  7675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7676. goto end;
  7677. }
  7678. }
  7679. } // END FOR CCS_QUANTITY
  7680. for (int index = 0; index < GB_QUANTITY; index++)
  7681. {
  7682. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7683. {
  7684. 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'))
  7685. {
  7686. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7687. goto end;
  7688. }
  7689. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7690. {
  7691. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7692. goto end;
  7693. }
  7694. 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
  7695. {
  7696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7697. goto end;
  7698. }
  7699. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7700. {
  7701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7702. goto end;
  7703. }
  7704. }
  7705. } // END FOR GB_QUANTITY
  7706. for (int index = 0; index < AC_QUANTITY; index++)
  7707. {
  7708. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7709. {
  7710. 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'))
  7711. {
  7712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7713. goto end;
  7714. }
  7715. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7716. {
  7717. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7718. goto end;
  7719. }
  7720. 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
  7721. {
  7722. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7723. goto end;
  7724. }
  7725. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7726. {
  7727. 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))
  7728. {
  7729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7730. goto end;
  7731. }
  7732. }
  7733. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7734. {
  7735. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7736. goto end;
  7737. }
  7738. }
  7739. }// END FOR AC_QUANTITY
  7740. //The connectorId is 0
  7741. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7742. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7743. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7744. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7745. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7746. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7747. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7748. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7749. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7750. result = TRUE;
  7751. return result;
  7752. }
  7753. else
  7754. {
  7755. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7756. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7757. }
  7758. if(strcmp(comfirmstr,"Accepted") == 0)
  7759. {
  7760. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7761. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7762. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7763. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7764. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7765. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7766. result = TRUE;
  7767. return result;
  7768. }
  7769. end:
  7770. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7771. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7772. return result;
  7773. }
  7774. int handleResetRequest(char *uuid, char *payload)
  7775. {
  7776. mtrace();
  7777. int result = FAIL;
  7778. char sstr[10]={0},sstrtemp[30]={ 0 };
  7779. char typestr[10]={0};
  7780. char comfirmstr[20]={0};
  7781. int c = 0;
  7782. char *loc;
  7783. DEBUG_INFO("handleResetRequest...\n");
  7784. strcpy(sstrtemp, stringtrimspace(payload));
  7785. loc = strstr(sstrtemp, "type");
  7786. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7787. c = 0;
  7788. while (loc[3+strlen("type")+c] != '\"')
  7789. {
  7790. sstr[c] = loc[3+strlen("type")+c];
  7791. c++;
  7792. }
  7793. sstr[c] = '\0';
  7794. strcpy(typestr,sstr);
  7795. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7796. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7797. {
  7798. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7799. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7800. result = TRUE;
  7801. return result;
  7802. }
  7803. else
  7804. {
  7805. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7806. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7807. goto errorend;
  7808. }
  7809. errorend:
  7810. sendResetConfirmation(uuid, comfirmstr);
  7811. return result;
  7812. }
  7813. int handleSendLocalListRequest(char *uuid, char *payload)
  7814. {
  7815. mtrace();
  7816. int result = FAIL;
  7817. int listVersionInt;
  7818. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7819. char listsearch[]="listVersion";
  7820. char updateTypesearch[]="updateType";
  7821. char localAuthorizationListsearch[]="localAuthorizationList";
  7822. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7823. char CardList[500][160]={0};
  7824. char updateTypestr[15]={0};
  7825. char idTagstr[20]={0};
  7826. char parentIdTag[20]={0};
  7827. char expiryDate[30]={0};
  7828. char idTagstatus[16]={0};
  7829. int c = 0;
  7830. int i = 0;
  7831. char *delim1 = "}";
  7832. char * pch;
  7833. char *loc;
  7834. //char *ptr;
  7835. char comfirmstr[20];
  7836. //int n_localAuthorizations = 0;
  7837. int checkState_Faulted = FALSE;
  7838. DEBUG_INFO("handleSendLocalListRequest...\n");
  7839. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7840. {
  7841. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7842. goto end;
  7843. }
  7844. //check Charge Point state
  7845. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7846. {
  7847. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7848. {
  7849. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7850. }
  7851. }
  7852. for (int index = 0; index < CCS_QUANTITY; index++)
  7853. {
  7854. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7855. {
  7856. checkState_Faulted = TRUE; //OCPP Status
  7857. }
  7858. }
  7859. for (int index = 0; index < GB_QUANTITY; index++)
  7860. {
  7861. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7862. {
  7863. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7864. }
  7865. }
  7866. //check Charge Point state
  7867. for (int index = 0; index < AC_QUANTITY; index++)
  7868. {
  7869. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7870. {
  7871. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7872. }
  7873. }
  7874. if(checkState_Faulted == TRUE)
  7875. {
  7876. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7877. goto end;
  7878. }
  7879. //Filter payload space
  7880. strcpy(sstrtemp, stringtrimspace(payload));
  7881. //listVersion
  7882. c = 0;
  7883. loc = strstr(sstrtemp, listsearch);
  7884. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7885. {
  7886. sstr[c] = loc[strlen("listVersion")+2+c];
  7887. c++;
  7888. }
  7889. sstr[c] = '\0';
  7890. listVersionInt = atoi(sstr);
  7891. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7892. //updateType
  7893. loc = strstr(sstrtemp, updateTypesearch);
  7894. c = 0;
  7895. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7896. {
  7897. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7898. c++;
  7899. }
  7900. sstr[c] = '\0';
  7901. strcpy(updateTypestr, sstr);
  7902. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7903. //localAuthorizationList
  7904. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7905. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7906. if(loc != NULL) // localAuthorizationList is not NULL
  7907. {
  7908. //Check UpdateType
  7909. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7910. {
  7911. //Local list full update
  7912. printf("Local list full update.\n");
  7913. OCPP_getListVerion();
  7914. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7915. {
  7916. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7917. goto end;
  7918. }
  7919. OCPP_cleanLocalList();
  7920. }
  7921. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7922. {
  7923. //Local list different update
  7924. printf("Local list different update.\n");
  7925. OCPP_getListVerion();
  7926. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7927. {
  7928. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7929. goto end;
  7930. }
  7931. }
  7932. else
  7933. {
  7934. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7935. goto end;
  7936. }
  7937. c = 0;
  7938. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7939. {
  7940. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7941. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7942. c++;
  7943. }
  7944. sstr[c] = '\0';
  7945. //DEBUG_INFO("sstr=%s\n", sstr);
  7946. //parsing strings to words
  7947. i = 0;
  7948. pch = strtok(sstr,delim1);
  7949. while (pch != NULL)
  7950. {
  7951. strcpy(CardList[i], pch);
  7952. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7953. pch = strtok (NULL, delim1);
  7954. i = i + 1;
  7955. }
  7956. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7957. //local Authorizations List Numbers
  7958. //n_localAuthorizations = i;
  7959. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7960. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7961. c= 0;
  7962. while(c < i) // i is CardList Number
  7963. {
  7964. //Search "IdToken"
  7965. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7966. loc = strstr(CardList[c], "idTag");
  7967. int j = 0;
  7968. while (loc[3+strlen("idTag")+j] != '\"')
  7969. {
  7970. sstr[j] = loc[3+strlen("idTag")+j];
  7971. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7972. j++;
  7973. }
  7974. sstr[j] = '\0';
  7975. strcpy(idTagstr, sstr);
  7976. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7977. //Search "expiryDate"
  7978. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7979. loc = strstr(CardList[c], "expiryDate");
  7980. j = 0;
  7981. if(loc != NULL)
  7982. {
  7983. while (loc[3+strlen("expiryDate")+j] != '\"')
  7984. {
  7985. sstr[j] = loc[3+strlen("expiryDate")+j];
  7986. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7987. j++;
  7988. }
  7989. sstr[j] = '\0';
  7990. strcpy(expiryDate, sstr);
  7991. }
  7992. else
  7993. {
  7994. strcpy(expiryDate, "");
  7995. }
  7996. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7997. //Search "parentIdTag"
  7998. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7999. loc = strstr(CardList[c], "parentIdTag");
  8000. j = 0;
  8001. if(loc != NULL)
  8002. {
  8003. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8004. {
  8005. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8006. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8007. j++;
  8008. }
  8009. sstr[j] = '\0';
  8010. strcpy(parentIdTag, sstr);
  8011. }
  8012. else
  8013. {
  8014. strcpy(parentIdTag, "");
  8015. }
  8016. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8017. //Search "status"
  8018. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8019. loc = strstr(CardList[c], "status");
  8020. j = 0;
  8021. while (loc[3+strlen("status")+j] != '\"')
  8022. {
  8023. sstr[j] = loc[3+strlen("status")+j];
  8024. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8025. j++;
  8026. }
  8027. sstr[j] = '\0';
  8028. strcpy(idTagstatus, sstr);
  8029. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8030. OCPP_getIdTag(idTagstr);
  8031. //OCPP_getIdTag("test"); For Test
  8032. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8033. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8034. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8035. {
  8036. //Local list full update
  8037. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8038. // update list
  8039. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8040. //DEBUG_INFO("Local list full update. 1\n");
  8041. //OCPP_get_TableAuthlocalAllData();
  8042. //DEBUG_INFO("Local list full update. 2\n");
  8043. }
  8044. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8045. {
  8046. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8047. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8048. }
  8049. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8050. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8051. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8052. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8053. c++;
  8054. }
  8055. }
  8056. else
  8057. {
  8058. //Check UpdateType
  8059. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8060. {
  8061. //Local list full update
  8062. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8063. OCPP_cleanLocalList();
  8064. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8065. goto end;
  8066. }
  8067. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8068. {
  8069. //Local list different update
  8070. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8071. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8072. goto end;
  8073. }
  8074. }
  8075. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8076. end:
  8077. sendSendLocalListConfirmation(uuid, comfirmstr);
  8078. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8079. return result;
  8080. }
  8081. #define MAX 200
  8082. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8083. {
  8084. mtrace();
  8085. int result = FAIL;
  8086. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8087. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8088. char chargingProfilePurposeStr[30]={0};
  8089. char chargingProfileKindStr[16]={0};
  8090. char recurrencyKindStr[10]={0};
  8091. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8092. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8093. int chargingSchedulePeriodCount = 0;
  8094. //int updateflag = FALSE;
  8095. char comfirmstr[20]={0};
  8096. int meet= FALSE;
  8097. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8098. int c = 0;
  8099. char *loc;
  8100. FILE *fptr1;//, *fptr2;
  8101. //int lno=0;//, linectr = 0;
  8102. //int modifyflag = FALSE;
  8103. char filename[MAX]={0};
  8104. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8105. //int resultRename=0;
  8106. char rmFileCmd[50]={0};
  8107. char tempchargingProfilePurposeStr[30]={0};
  8108. char word[1600]={0};
  8109. int n_chargingProfile = 0;
  8110. //[2,"d65bcbca-0b07-49c1-b679-e6c6ff9f5627","SetChargingProfile",{"connectorId":0,"csChargingProfiles":{"chargingProfileId":1,"transactionId":0,"stackLevel":0,"chargingProfilePurpose":"TxDefaultProfile","chargingProfileKind":"Absolute","recurrencyKind":"Daily","validFrom":"2019-07-01T02:39:55.000Z","validTo":"2019-07-04T02:39:55.000Z","chargingSchedule":{"duration":86400,"startSchedule":"2019-07-01T02:39:55.000Z","chargingRateUnit":"A","chargingSchedulePeriod":[{"startPeriod":0,"limit":20.0,"numberPhases":3},{"startPeriod":300,"limit":10.0,"numberPhases":3},{"startPeriod":600,"limit":20.0,"numberPhases":3},{"startPeriod":1200,"limit":10.0,"numberPhases":3},{"startPeriod":1800,"limit":20.0,"numberPhases":3},{"startPeriod":2400,"limit":10.0,"numberPhases":3},{"startPeriod":3000,"limit":20.0,"numberPhases":3}],"minChargingRate":20.1}}}]
  8111. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8112. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8113. //Filter string space
  8114. strcpy(sstrtemp, stringtrimspace(payload));
  8115. //*********************connectorId***************************/
  8116. loc = strstr(sstrtemp, "connectorId");
  8117. c = 0;
  8118. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8119. while (loc[strlen("connectorId")+2+c] != ',')
  8120. {
  8121. sstr[c] = loc[strlen("connectorId")+2+c];
  8122. c++;
  8123. }
  8124. sstr[c] = '\0';
  8125. connectorIdInt = atoi(sstr);
  8126. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8127. {
  8128. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8129. }
  8130. else
  8131. {
  8132. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8133. }
  8134. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8135. //*********************chargingProfileId***************************/
  8136. loc = strstr(sstrtemp, "chargingProfileId");
  8137. c = 0;
  8138. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8139. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8140. {
  8141. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8142. c++;
  8143. }
  8144. sstr[c] = '\0';
  8145. chargingProfileIdInt = atoi(sstr);
  8146. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8147. {
  8148. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8149. }
  8150. else
  8151. {
  8152. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8153. }
  8154. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8155. //*********************transactionId***************************/
  8156. loc = strstr(sstrtemp, "transactionId");
  8157. if(loc != NULL)
  8158. {
  8159. c = 0;
  8160. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8161. while (loc[strlen("transactionId")+2+c] != ',')
  8162. {
  8163. sstr[c] = loc[strlen("transactionId")+2+c];
  8164. c++;
  8165. }
  8166. sstr[c] = '\0';
  8167. transactionIdInt = atoi(sstr);
  8168. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8169. {
  8170. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8171. }
  8172. else
  8173. {
  8174. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8175. }
  8176. }
  8177. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8178. //*********************stackLevel***************************/
  8179. loc = strstr(sstrtemp, "stackLevel");
  8180. c = 0;
  8181. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8182. while (loc[strlen("stackLevel")+2+c] != ',')
  8183. {
  8184. sstr[c] = loc[strlen("stackLevel")+2+c];
  8185. c++;
  8186. }
  8187. sstr[c] = '\0';
  8188. stackLevelInt = atoi(sstr);
  8189. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8190. {
  8191. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8192. }
  8193. else
  8194. {
  8195. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8196. }
  8197. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8198. //*********************chargingProfilePurpose***************************/
  8199. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8200. c = 0;
  8201. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8202. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8203. {
  8204. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8205. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8206. c++;
  8207. }
  8208. sstr[c] = '\0';
  8209. strcpy(chargingProfilePurposeStr,sstr);
  8210. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8211. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8212. {
  8213. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8214. }
  8215. else
  8216. {
  8217. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8218. }
  8219. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8220. //*********************chargingProfileKind***************************/
  8221. loc = strstr(sstrtemp, "chargingProfileKind");
  8222. c = 0;
  8223. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8224. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8225. {
  8226. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8227. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8228. c++;
  8229. }
  8230. sstr[c] = '\0';
  8231. strcpy(chargingProfileKindStr,sstr);
  8232. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8233. {
  8234. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8235. }
  8236. else
  8237. {
  8238. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8239. }
  8240. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8241. //*********************recurrencyKind***************************/
  8242. loc = strstr(sstrtemp, "recurrencyKind");
  8243. if(loc != NULL)
  8244. {
  8245. c = 0;
  8246. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8247. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8248. {
  8249. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8250. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8251. c++;
  8252. }
  8253. sstr[c] = '\0';
  8254. strcpy(recurrencyKindStr,sstr);
  8255. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8256. {
  8257. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8258. }
  8259. else
  8260. {
  8261. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8262. }
  8263. }
  8264. else
  8265. {
  8266. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8267. {
  8268. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8269. }
  8270. else
  8271. {
  8272. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8273. }
  8274. }
  8275. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8276. //*********************validFrom***************************/
  8277. loc = strstr(sstrtemp, "validFrom");
  8278. if(loc != NULL)
  8279. {
  8280. c = 0;
  8281. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8282. while (loc[3+strlen("validFrom")+c] != '\"')
  8283. {
  8284. sstr[c] = loc[3+strlen("validFrom")+c];
  8285. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8286. c++;
  8287. }
  8288. sstr[c] = '\0';
  8289. strcpy(validFromStr,sstr);
  8290. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8291. {
  8292. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8293. }
  8294. else
  8295. {
  8296. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8297. }
  8298. }
  8299. else
  8300. {
  8301. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8302. {
  8303. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8304. }
  8305. else
  8306. {
  8307. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8308. }
  8309. }
  8310. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8311. //*********************validTo***************************/
  8312. loc = strstr(sstrtemp, "validTo");
  8313. if(loc != NULL)
  8314. {
  8315. c = 0;
  8316. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8317. while (loc[3+strlen("validTo")+c] != '\"')
  8318. {
  8319. sstr[c] = loc[3+strlen("validTo")+c];
  8320. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8321. c++;
  8322. }
  8323. sstr[c] = '\0';
  8324. strcpy(validToStr,sstr);
  8325. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8326. {
  8327. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8328. }
  8329. else
  8330. {
  8331. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8332. }
  8333. }
  8334. else
  8335. {
  8336. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8337. {
  8338. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8339. }
  8340. else
  8341. {
  8342. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8343. }
  8344. }
  8345. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8346. //*********************duration***************************/
  8347. loc = strstr(sstrtemp, "duration");
  8348. if(loc != NULL)
  8349. {
  8350. c = 0;
  8351. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8352. while (loc[strlen("duration")+2+c] != ',')
  8353. {
  8354. sstr[c] = loc[strlen("duration")+2+c];
  8355. c++;
  8356. }
  8357. sstr[c] = '\0';
  8358. durationInt = atoi(sstr);
  8359. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8360. {
  8361. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8362. }
  8363. else
  8364. {
  8365. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8366. }
  8367. }
  8368. else
  8369. {
  8370. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8371. {
  8372. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8373. }
  8374. else
  8375. {
  8376. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8377. }
  8378. }
  8379. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8380. //*********************startSchedule***************************/
  8381. loc = strstr(sstrtemp, "startSchedule");
  8382. if(loc != NULL)
  8383. {
  8384. c = 0;
  8385. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8386. while (loc[3+strlen("startSchedule")+c] != '\"')
  8387. {
  8388. sstr[c] = loc[3+strlen("startSchedule")+c];
  8389. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8390. c++;
  8391. }
  8392. sstr[c] = '\0';
  8393. strcpy(startScheduleStr,sstr);
  8394. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8395. {
  8396. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8397. }
  8398. else
  8399. {
  8400. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8401. }
  8402. }
  8403. else
  8404. {
  8405. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8406. {
  8407. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8408. }
  8409. else
  8410. {
  8411. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8412. }
  8413. }
  8414. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8415. //*********************chargingRateUnit***************************/
  8416. loc = strstr(sstrtemp, "chargingRateUnit");
  8417. if(loc != NULL)
  8418. {
  8419. c = 0;
  8420. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8421. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8422. {
  8423. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8424. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8425. c++;
  8426. }
  8427. sstr[c] = '\0';
  8428. strcpy(chargingRateUnitStr,sstr);
  8429. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8430. {
  8431. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8432. }
  8433. else
  8434. {
  8435. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8436. }
  8437. }
  8438. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8439. //****************chargingSchedulePeriod count start*******************/
  8440. int what_len = strlen("startPeriod");
  8441. char tempChargingProfile[1600]={0};
  8442. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8443. char *where = tempChargingProfile;
  8444. if (what_len)
  8445. {
  8446. while ((where = strstr(where, "startPeriod"))) {
  8447. where += what_len;
  8448. chargingSchedulePeriodCount++;
  8449. }
  8450. }
  8451. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8452. {
  8453. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8454. goto end;
  8455. }
  8456. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8457. //where = payload;
  8458. int templength = 0;
  8459. //int searchstart = 0;
  8460. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8461. {
  8462. //****************startPeriod*******************/
  8463. c=0;
  8464. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8465. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8466. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8467. {
  8468. sstr[c] = loc[strlen("startPeriod")+2+c];
  8469. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8470. c++;
  8471. }
  8472. sstr[c] = '\0';
  8473. startPeriodInt[periodNums] = atoi(sstr);
  8474. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8475. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8476. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8477. {
  8478. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8479. }
  8480. else
  8481. {
  8482. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8483. }
  8484. templength = strlen("startPeriod")+2+c;
  8485. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8486. //****************limit*******************/
  8487. c=0;
  8488. loc = strstr(tempChargingProfile + templength, "limit");
  8489. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8490. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8491. {
  8492. sstr[c] = loc[strlen("limit")+2+c];
  8493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8494. c++;
  8495. }
  8496. sstr[c] = '\0';
  8497. limitflaot[periodNums] = atof(sstr);
  8498. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8499. {
  8500. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8501. }
  8502. else
  8503. {
  8504. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8505. }
  8506. templength = templength + strlen("limit")+2+c;
  8507. //****************numberPhases*******************/
  8508. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8509. if(loc != NULL)
  8510. {
  8511. c=0;
  8512. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8513. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8514. {
  8515. sstr[c] = loc[strlen("numberPhases")+2+c];
  8516. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8517. c++;
  8518. }
  8519. sstr[c] = '\0';
  8520. numberPhasesInt[periodNums] = atoi(sstr);
  8521. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8522. {
  8523. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8524. }
  8525. else
  8526. {
  8527. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8528. }
  8529. templength = templength + strlen("numberPhases")+2+c;
  8530. }
  8531. //where = loc;
  8532. }
  8533. //****************chargingSchedulePeriod count end*******************/
  8534. //*********************minChargingRate***************************/
  8535. loc = strstr(sstrtemp, "minChargingRate");
  8536. if(loc != NULL)
  8537. {
  8538. c = 0;
  8539. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8540. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8541. {
  8542. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8543. c++;
  8544. }
  8545. sstr[c] = '\0';
  8546. minChargingRateFloat = atof(sstr);
  8547. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8548. {
  8549. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8550. }
  8551. else
  8552. {
  8553. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8554. }
  8555. }
  8556. else
  8557. {
  8558. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8559. {
  8560. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8561. }
  8562. else
  8563. {
  8564. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8565. }
  8566. }
  8567. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8568. {
  8569. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8570. if(connectorIdInt != 0)
  8571. {
  8572. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8573. goto end;
  8574. }
  8575. strcpy(filename, ChargePointMaxProfile_JSON );
  8576. fptr1 = fopen(filename, "r");
  8577. if (!fptr1)
  8578. {
  8579. //file not exist
  8580. DEBUG_INFO("Unable to open the input file!!\n");
  8581. fptr1 = fopen(filename, "w+");
  8582. }
  8583. else
  8584. {
  8585. //Check Charging Profile Count
  8586. while(fscanf(fptr1, "%s", word) != EOF)
  8587. {
  8588. //DEBUG_INFO("word=%s\n",word);
  8589. if(strstr(word, "chargingProfileId")!= NULL)
  8590. {
  8591. //DEBUG_INFO("test chargingProfileId \n");
  8592. n_chargingProfile = n_chargingProfile + 1;
  8593. //DEBUG_INFO("chargingProfileId Found\n");
  8594. }
  8595. }
  8596. }
  8597. fclose(fptr1);
  8598. }
  8599. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8600. {
  8601. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8602. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8603. {
  8604. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8605. goto end;
  8606. }
  8607. memset(filename, 0, ARRAY_SIZE(filename));
  8608. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8609. fptr1 = fopen(filename, "r");
  8610. if (!fptr1)
  8611. {
  8612. //file not exist
  8613. //DEBUG_INFO("Unable to open the input file!!\n");
  8614. fptr1 = fopen(filename, "w+");
  8615. }
  8616. else
  8617. {
  8618. //Check Charging Profile Count
  8619. while(fscanf(fptr1, "%s", word) != EOF)
  8620. {
  8621. //DEBUG_INFO("word=%s\n",word);
  8622. if(strstr(word, "chargingProfileId")!= NULL)
  8623. {
  8624. //DEBUG_INFO("test chargingProfileId \n");
  8625. n_chargingProfile = n_chargingProfile + 1;
  8626. //DEBUG_INFO("chargingProfileId Found\n");
  8627. }
  8628. }
  8629. }
  8630. fclose(fptr1);
  8631. }
  8632. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8633. {
  8634. //printf("set chargingProfile 1-4\n");
  8635. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8636. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8637. if(connectorIdInt == 0)
  8638. {
  8639. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8640. goto end;
  8641. }
  8642. int tempIndex = 0;
  8643. //check Transaction active
  8644. if(gunType[connectorIdInt -1] == 'J')
  8645. {
  8646. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8647. {
  8648. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8649. }
  8650. else
  8651. {
  8652. tempIndex = connectorIdInt -1;
  8653. }
  8654. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8655. {
  8656. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8657. {
  8658. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8659. {
  8660. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8661. {
  8662. meet = TRUE;
  8663. break;
  8664. }
  8665. }
  8666. }
  8667. }
  8668. }
  8669. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8670. {
  8671. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8672. {
  8673. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8674. }
  8675. else
  8676. {
  8677. tempIndex = connectorIdInt -1;
  8678. }
  8679. for (int index = 0; index < CCS_QUANTITY; index++)
  8680. {
  8681. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8682. {
  8683. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8684. {
  8685. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8686. {
  8687. meet = TRUE;
  8688. break;
  8689. }
  8690. }
  8691. }
  8692. }
  8693. }
  8694. else if(gunType[connectorIdInt -1] == 'G')
  8695. {
  8696. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8697. {
  8698. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8699. }
  8700. else
  8701. {
  8702. tempIndex = connectorIdInt -1;
  8703. }
  8704. for (int index = 0; index < GB_QUANTITY; index++)
  8705. {
  8706. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8707. {
  8708. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8709. {
  8710. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8711. {
  8712. meet = TRUE;
  8713. break;
  8714. }
  8715. }
  8716. }
  8717. }
  8718. }
  8719. else
  8720. {
  8721. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8722. {
  8723. tempIndex = 2;
  8724. }
  8725. else
  8726. {
  8727. tempIndex = (connectorIdInt -1);
  8728. }
  8729. for (int index = 0; index < AC_QUANTITY; index++)
  8730. {
  8731. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8732. {
  8733. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8734. {
  8735. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8736. {
  8737. meet = TRUE;
  8738. break;
  8739. }
  8740. }
  8741. }
  8742. }
  8743. }
  8744. //check Transaction active
  8745. if(meet == FALSE)
  8746. {
  8747. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8748. goto end;
  8749. }
  8750. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8751. {
  8752. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8753. goto end;
  8754. }
  8755. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8756. fptr1 = fopen(filename, "r");
  8757. if (!fptr1)
  8758. {
  8759. //file not exist
  8760. DEBUG_INFO("Unable to open the input file!!\n");
  8761. fptr1 = fopen(filename, "w+");
  8762. }
  8763. else
  8764. {
  8765. //Check Charging Profile Count
  8766. while(fscanf(fptr1, "%s", word) != EOF)
  8767. {
  8768. //DEBUG_INFO("word=%s\n",word);
  8769. if(strstr(word, "chargingProfileId")!= NULL)
  8770. {
  8771. //DEBUG_INFO("test chargingProfileId \n");
  8772. n_chargingProfile = n_chargingProfile + 1;
  8773. //DEBUG_INFO("chargingProfileId Found\n");
  8774. }
  8775. }
  8776. }
  8777. fclose(fptr1);
  8778. }
  8779. // Check ChargeProfileMaxStackLevel
  8780. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8781. {
  8782. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8783. goto end;
  8784. }
  8785. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8786. {
  8787. int i = 0;
  8788. char fnametemp[200]={0};
  8789. n_chargingProfile = 0;
  8790. //Check ChargePointMaxProfile.json exit
  8791. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8792. {
  8793. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8794. //Check Charging Profile Count
  8795. while(fscanf(fptr1, "%s", word) != EOF)
  8796. {
  8797. //DEBUG_INFO("word=%s\n",word);
  8798. if(strstr(word, "chargingProfileId")!= NULL)
  8799. {
  8800. //DEBUG_INFO("test chargingProfileId \n");
  8801. n_chargingProfile = n_chargingProfile + 1;
  8802. i = i + 1;
  8803. //DEBUG_INFO("chargingProfileId Found\n");
  8804. }
  8805. memset(word, 0, ARRAY_SIZE(word));
  8806. }
  8807. fclose(fptr1);
  8808. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8809. }
  8810. //Check TxDefaultProfile_0.json exit
  8811. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8812. {
  8813. i = 0;
  8814. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8815. //Check Charging Profile Count
  8816. while(fscanf(fptr1, "%s", word) != EOF)
  8817. {
  8818. //DEBUG_INFO("word=%s\n",word);
  8819. if(strstr(word, "chargingProfileId")!= NULL)
  8820. {
  8821. //DEBUG_INFO("test chargingProfileId \n");
  8822. n_chargingProfile = n_chargingProfile + 1;
  8823. i = i + 1;
  8824. //DEBUG_INFO("chargingProfileId Found\n");
  8825. }
  8826. memset(word, 0, ARRAY_SIZE(word));
  8827. }
  8828. fclose(fptr1);
  8829. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8830. }
  8831. //Check TxDefaultProfile_%d.json
  8832. for(int j=1; j <= gunTotalNumber; j++)
  8833. {
  8834. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8835. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8836. if((access(fnametemp,F_OK))!=-1)
  8837. {
  8838. i = 0;
  8839. fptr1 = fopen(fnametemp, "r");
  8840. //Check Charging Profile Count
  8841. while(fscanf(fptr1, "%s", word) != EOF)
  8842. {
  8843. //DEBUG_INFO("word=%s\n",word);
  8844. if(strstr(word, "chargingProfileId")!= NULL)
  8845. {
  8846. //DEBUG_INFO("test chargingProfileId \n");
  8847. n_chargingProfile = n_chargingProfile + 1;
  8848. i = i + 1;
  8849. //DEBUG_INFO("chargingProfileId Found\n");
  8850. }
  8851. memset(word, 0, ARRAY_SIZE(word));
  8852. }
  8853. fclose(fptr1);
  8854. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8855. }
  8856. }
  8857. //Check TxProfile_%d.json
  8858. for(int j=1; j <= gunTotalNumber; j++)
  8859. {
  8860. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8861. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8862. if((access(fnametemp,F_OK))!=-1)
  8863. {
  8864. i = 0;
  8865. fptr1 = fopen(fnametemp, "r");
  8866. //Check Charging Profile Count
  8867. while(fscanf(fptr1, "%s", word) != EOF)
  8868. {
  8869. //DEBUG_INFO("word=%s\n",word);
  8870. if(strstr(word, "chargingProfileId")!= NULL)
  8871. {
  8872. //DEBUG_INFO("test chargingProfileId \n");
  8873. n_chargingProfile = n_chargingProfile + 1;
  8874. i = i + 1;
  8875. //DEBUG_INFO("chargingProfileId Found\n");
  8876. }
  8877. memset(word, 0, ARRAY_SIZE(word));
  8878. }
  8879. fclose(fptr1);
  8880. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8881. }
  8882. }
  8883. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8884. {
  8885. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8886. goto end;
  8887. }
  8888. }
  8889. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8890. //**********************************Write to File********************************************************/
  8891. FILE *infile;
  8892. FILE *outfile;
  8893. // open file for writing
  8894. infile = fopen (filename, "r");
  8895. outfile = fopen (tempfile, "w");
  8896. int d =0;
  8897. d = fgetc(infile);
  8898. //DEBUG_INFO("d:%d\n",d);
  8899. rewind(infile);
  8900. //*璉 瘚 辣蝏     1嚗   0 */
  8901. if(d == EOF)
  8902. {
  8903. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8904. fprintf(outfile,"%s\n",payload);
  8905. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8906. fclose(infile);
  8907. fclose(outfile);
  8908. sprintf(rmFileCmd,"rm -f %s",filename);
  8909. system(rmFileCmd);
  8910. rename(tempfile, filename);
  8911. sleep(1);
  8912. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8913. //system(rmFileCmd);
  8914. }
  8915. else
  8916. {
  8917. char buf[1000]={0};
  8918. int ChargingProfileAdded = FALSE;
  8919. while (fgets(buf, sizeof(buf), infile) != NULL)
  8920. {
  8921. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8922. //*************************tempconnectorIdInt*********************************/
  8923. loc = strstr(buf, "connectorId");
  8924. c = 0;
  8925. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8926. while (loc[strlen("connectorId")+2+c] != ',')
  8927. {
  8928. sstr[c] = loc[strlen("connectorId")+2+c];
  8929. c++;
  8930. }
  8931. sstr[c] = '\0';
  8932. tempconnectorIdInt = atoi(sstr);
  8933. //*************************tempchargingProfileIdInt*********************************/
  8934. loc = strstr(buf, "chargingProfileId");
  8935. c = 0;
  8936. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8937. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8938. {
  8939. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8940. c++;
  8941. }
  8942. sstr[c] = '\0';
  8943. tempchargingProfileIdInt = atoi(sstr);
  8944. //*************************tempstackLevelInt*********************************/
  8945. loc = strstr(buf, "stackLevel");
  8946. c = 0;
  8947. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8948. while (loc[strlen("stackLevel")+2+c] != ',')
  8949. {
  8950. sstr[c] = loc[strlen("stackLevel")+2+c];
  8951. c++;
  8952. }
  8953. sstr[c] = '\0';
  8954. tempstackLevelInt = atoi(sstr);
  8955. //*************************tempchargingProfilePurposeStr*********************************/
  8956. loc = strstr(payload, "chargingProfilePurpose");
  8957. c = 0;
  8958. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8959. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8960. {
  8961. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8962. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8963. c++;
  8964. }
  8965. sstr[c] = '\0';
  8966. strcpy(tempchargingProfilePurposeStr,sstr);
  8967. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8968. {
  8969. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8970. {
  8971. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8972. if(ChargingProfileAdded == FALSE)
  8973. {
  8974. fprintf(outfile,"%s\n",payload);
  8975. ChargingProfileAdded = TRUE;
  8976. }
  8977. }
  8978. else
  8979. {
  8980. if(tempstackLevelInt < stackLevelInt)
  8981. {
  8982. if(ChargingProfileAdded == FALSE)
  8983. {
  8984. fprintf(outfile,"%s\n",payload);
  8985. ChargingProfileAdded = TRUE;
  8986. fprintf(outfile,"%s\n",buf);
  8987. }
  8988. else
  8989. {
  8990. fprintf(outfile,"%s\n",buf);
  8991. }
  8992. }
  8993. else
  8994. {
  8995. if(ChargingProfileAdded == FALSE)
  8996. {
  8997. fprintf(outfile,"%s\n",buf);
  8998. fprintf(outfile,"%s\n",payload);
  8999. ChargingProfileAdded = TRUE;
  9000. }
  9001. else
  9002. {
  9003. fprintf(outfile,"%s\n",buf);
  9004. }
  9005. }
  9006. }
  9007. }
  9008. else
  9009. {
  9010. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9011. {
  9012. if(ChargingProfileAdded == FALSE)
  9013. {
  9014. fprintf(outfile,"%s\n",payload);
  9015. ChargingProfileAdded = TRUE;
  9016. fprintf(outfile,"%s\n",buf);
  9017. }
  9018. else
  9019. {
  9020. fprintf(outfile,"%s\n",buf);
  9021. }
  9022. }
  9023. else if(tempstackLevelInt < stackLevelInt)
  9024. {
  9025. if(ChargingProfileAdded == FALSE)
  9026. {
  9027. fprintf(outfile,"%s\n",payload);
  9028. ChargingProfileAdded = TRUE;
  9029. fprintf(outfile,"%s\n",buf);
  9030. }
  9031. else
  9032. {
  9033. fprintf(outfile,"%s\n",buf);
  9034. }
  9035. }
  9036. else
  9037. {
  9038. if(ChargingProfileAdded == FALSE)
  9039. {
  9040. fprintf(outfile,"%s\n",buf);
  9041. fprintf(outfile,"%s\n",payload);
  9042. ChargingProfileAdded = TRUE;
  9043. }
  9044. else
  9045. {
  9046. fprintf(outfile,"%s\n",buf);
  9047. }
  9048. }
  9049. }
  9050. } // end of while loop
  9051. fclose(infile);
  9052. fclose(outfile);
  9053. sprintf(rmFileCmd,"rm -f %s",filename);
  9054. system(rmFileCmd);
  9055. rename(tempfile, filename);
  9056. sleep(1);
  9057. result = TRUE;
  9058. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9059. }
  9060. end:
  9061. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9062. return result;
  9063. return result;
  9064. }
  9065. int handleTriggerMessageRequest(char *uuid, char *payload)
  9066. {
  9067. mtrace();
  9068. int result = FAIL;
  9069. int connectorIdIsNULL = FALSE;
  9070. int connectorIdInt =0;
  9071. char sstr[40]={0},sstrtemp[100]={ 0 };
  9072. char requestedMessagestr[40]={0};
  9073. char comfirmstr[20]={0};
  9074. int c = 0;
  9075. char *loc;
  9076. DEBUG_INFO("handleTriggerMessageRequest\n");
  9077. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9078. strcpy(sstrtemp, stringtrimspace(payload));
  9079. c = 0;
  9080. loc = strstr(sstrtemp, "requestedMessage");
  9081. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9082. {
  9083. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9084. c++;
  9085. }
  9086. sstr[c] = '\0';
  9087. strcpy(requestedMessagestr, sstr);
  9088. c = 0;
  9089. loc = strstr(sstrtemp, "connectorId");
  9090. if(loc == NULL)
  9091. {
  9092. connectorIdIsNULL = TRUE;
  9093. }
  9094. else
  9095. {
  9096. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9097. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9098. {
  9099. sstr[c] = loc[strlen("connectorId")+2+c];
  9100. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9101. c++;
  9102. }
  9103. sstr[c] = '\0';
  9104. connectorIdInt = atoi(sstr);
  9105. }
  9106. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9107. {
  9108. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9109. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9110. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9111. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9112. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9113. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9114. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9115. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9116. {
  9117. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9118. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9119. return TRUE;
  9120. }
  9121. else
  9122. {
  9123. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9124. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9125. }
  9126. }
  9127. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9128. {
  9129. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9130. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9131. return TRUE;
  9132. }
  9133. //==========================
  9134. // Trigger message
  9135. //==========================
  9136. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9137. {
  9138. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9139. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9140. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9141. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9142. {
  9143. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9144. }
  9145. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9146. }
  9147. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9148. {
  9149. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9150. }
  9151. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9152. {
  9153. //sendBootNotificationRequest();
  9154. server_sign = FALSE;
  9155. }
  9156. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9157. {
  9158. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9159. }
  9160. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9161. {
  9162. if(connectorIdIsNULL == FALSE)
  9163. {
  9164. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9165. {
  9166. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9167. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9168. }
  9169. }
  9170. else
  9171. {
  9172. for(int idx=0;idx< gunTotalNumber;idx++)
  9173. {
  9174. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9175. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9176. }
  9177. }
  9178. }
  9179. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9180. {
  9181. if(connectorIdIsNULL == FALSE)
  9182. {
  9183. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9184. {
  9185. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9186. }
  9187. }
  9188. else
  9189. {
  9190. for(int idx=0;idx< gunTotalNumber;idx++)
  9191. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9192. }
  9193. }
  9194. return result;
  9195. }
  9196. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9197. {
  9198. mtrace();
  9199. int result = FAIL;
  9200. int connectorIdInt =0;
  9201. char comfirmstr[20]={0};
  9202. int tempIndex = 0;
  9203. json_object *UnlockConnector;
  9204. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9205. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9206. UnlockConnector = json_tokener_parse(payload);
  9207. if(!is_error(UnlockConnector))
  9208. {
  9209. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9210. {
  9211. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9212. }
  9213. }
  9214. json_object_put(UnlockConnector);
  9215. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9216. if(gunTotalNumber == 0)
  9217. {
  9218. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9219. goto end;
  9220. }
  9221. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9222. {
  9223. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9224. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9225. goto end;
  9226. }
  9227. else
  9228. {
  9229. //check Transaction active
  9230. if(gunType[connectorIdInt-1] == 'J')
  9231. {
  9232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9233. {
  9234. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9235. }
  9236. else
  9237. {
  9238. tempIndex = connectorIdInt -1;
  9239. }
  9240. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9241. {
  9242. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9243. {
  9244. //stop Transaction
  9245. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9246. }
  9247. }
  9248. }
  9249. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9250. {
  9251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9252. {
  9253. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9254. }
  9255. else
  9256. {
  9257. tempIndex = connectorIdInt -1;
  9258. }
  9259. for (int index = 0; index < CCS_QUANTITY; index++)
  9260. {
  9261. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9262. {
  9263. //stop Transaction
  9264. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9265. }
  9266. }
  9267. }
  9268. else if(gunType[connectorIdInt-1] == 'G')
  9269. {
  9270. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9271. {
  9272. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9273. }
  9274. else
  9275. {
  9276. tempIndex = connectorIdInt -1;
  9277. }
  9278. for (int index = 0; index < GB_QUANTITY; index++)
  9279. {
  9280. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9281. {
  9282. //stop Transaction
  9283. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9284. }
  9285. }
  9286. }
  9287. else
  9288. {
  9289. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9290. {
  9291. tempIndex = 2;
  9292. }
  9293. else
  9294. {
  9295. tempIndex = connectorIdInt-1;
  9296. }
  9297. for (int index = 0; index < AC_QUANTITY; index++)
  9298. {
  9299. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9300. {
  9301. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9302. }
  9303. }
  9304. }
  9305. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9306. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9307. result = TRUE;
  9308. return result;
  9309. }
  9310. end:
  9311. //json_object_put(obj); --- remove temporally
  9312. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9313. return result;
  9314. }
  9315. static char UpdateFirmwarepayloadData[300]={0};
  9316. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9317. {
  9318. mtrace();
  9319. int result = FAIL;
  9320. pthread_t t;
  9321. sendUpdateFirmwareConfirmation(uuid);
  9322. memset(UpdateFirmwarepayloadData, 0, 300);
  9323. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9324. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9325. ////pthread_join(t, NULL); //
  9326. //pthread_detach(t);
  9327. //sendUpdateFirmwareConfirmation(uuid);
  9328. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9329. return result;
  9330. }
  9331. void *UpdateFirmwareProcess(void *data)
  9332. {
  9333. pthread_detach(pthread_self());
  9334. mtrace();
  9335. int retriesInt =0, retryIntervalInt=0;
  9336. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9337. int port=0;
  9338. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9339. int isSuccess = 0;
  9340. char ftpbuf[200];
  9341. char temp[100];
  9342. char * pch;
  9343. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9344. json_object *UpdateFirmware;
  9345. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9346. if(!is_error(UpdateFirmware))
  9347. {
  9348. // Required data
  9349. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9350. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9351. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9352. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9353. // Optional data
  9354. if(json_object_object_get(UpdateFirmware, "retries"))
  9355. {
  9356. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9357. }
  9358. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9359. {
  9360. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9361. }
  9362. }
  9363. json_object_put(UpdateFirmware);
  9364. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9365. memset(path, 0, ARRAY_SIZE(path));
  9366. system("rm -f /mnt/*");
  9367. if(strncmp(locationstr,"http", 4) == 0)
  9368. {
  9369. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9370. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9371. // protocol, user, password, host, path);
  9372. sprintf(ftppath,"/%s", path);
  9373. DEBUG_INFO("locationstr: %s\n", locationstr);
  9374. DEBUG_INFO("protocol: %s\n",protocol);
  9375. DEBUG_INFO("host: %s\n",host);
  9376. DEBUG_INFO("path: %s\n",path);
  9377. DEBUG_INFO("ftppath: %s\n",ftppath);
  9378. int ftppathlen=strlen(ftppath);
  9379. int i=1;
  9380. char filenametemp[50];
  9381. while(i < ftppathlen)
  9382. {
  9383. int len=ftppathlen-i;
  9384. if(ftppath[len]== 47) // '/' ascll code: 47
  9385. {
  9386. DEBUG_INFO("compare '/' all right\n");
  9387. break;
  9388. }
  9389. i=i+1;
  9390. }
  9391. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9392. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9393. filenametemp[i+1] = 0;
  9394. do
  9395. {
  9396. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9397. sleep(3);
  9398. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9399. if(!isSuccess)
  9400. {
  9401. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9402. sleep(retryIntervalInt);
  9403. }
  9404. else
  9405. {
  9406. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9407. }
  9408. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9409. }
  9410. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9411. {
  9412. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9413. memset(temp, 0, ARRAY_SIZE(temp));
  9414. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9415. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9416. int ftppathlen=strlen(ftpbuf);
  9417. int i=1;
  9418. char filenametemp[50];
  9419. while(i < ftppathlen)
  9420. {
  9421. int len=ftppathlen-i;
  9422. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9423. {
  9424. DEBUG_INFO(" compare '/' all right\n");
  9425. break;
  9426. }
  9427. i=i+1;
  9428. }
  9429. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9430. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9431. filenametemp[i+1] = 0;
  9432. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9433. pch=strchr(temp,'@');
  9434. if(pch==NULL)
  9435. {
  9436. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9437. protocol, host, &port, path);
  9438. strcpy(user,"anonymous");
  9439. strcpy(password,"");
  9440. }
  9441. else
  9442. {
  9443. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9444. protocol, user, password, host, &port, path);
  9445. }
  9446. sscanf(host,"%[^/]%s",host1, path1);
  9447. sprintf(ftppath,"%s", path1);
  9448. //DEBUG_INFO("protocol =%s\n",protocol);
  9449. //DEBUG_INFO("user =%s\n",user);
  9450. //DEBUG_INFO("password =%s\n",password);
  9451. //DEBUG_INFO("host1 =%s\n",host1);
  9452. //DEBUG_INFO("port =%d\n",port);
  9453. //DEBUG_INFO("path1 =%s\n",path1);
  9454. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9455. //ftpFile(host, user, password, port, ftppath, fname);
  9456. //download firmware pthred
  9457. if(port == 0)
  9458. {
  9459. port = 21;
  9460. }
  9461. do
  9462. {
  9463. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9464. sleep(3);
  9465. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9466. if(!isSuccess)
  9467. {
  9468. //BulldogUtil.sleepMs(interval*1000);
  9469. DEBUG_INFO("Update firmware request and download file fail.\n");
  9470. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9471. sleep(retryIntervalInt);
  9472. }
  9473. else
  9474. {
  9475. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9476. }
  9477. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9478. }
  9479. else
  9480. {
  9481. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9482. }
  9483. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9484. pthread_exit(NULL);
  9485. }
  9486. //==========================================
  9487. // Handle server response routine
  9488. //==========================================
  9489. void handleAuthorizeResponse(char *payload, int gun_index)
  9490. {
  9491. mtrace();
  9492. char expiryDatestr[30]={0};
  9493. char parentIdTagstr[20]={0};
  9494. char statusstr[20]={0};
  9495. char expiryDatestrtemp[30]={0};
  9496. char parentIdTagstrtemp[20]={0};
  9497. char IdTagstrtemp[20]={0};
  9498. char statusstrtemp[20]={0};
  9499. int expiryDateISNULL=FALSE;
  9500. int parentIdTagISNULL=FALSE;
  9501. char sstr[160]={0};
  9502. char* filename = AuthorizationCache_JSON;
  9503. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9504. char *loc;
  9505. int resultRename=0;
  9506. int responseIdTagInfoAsZero= 0;
  9507. char rmFileCmd[50]={0};
  9508. DEBUG_INFO("handleAuthorizeResponse...\n");
  9509. json_object *Authorize;
  9510. Authorize = json_tokener_parse(payload);
  9511. if(!is_error(Authorize))
  9512. {
  9513. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9514. {
  9515. // Required data
  9516. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9517. // Optional data
  9518. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9519. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9520. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9521. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9522. }
  9523. }
  9524. json_object_put(Authorize);
  9525. if(expiryDateISNULL == FALSE)
  9526. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9527. if(parentIdTagISNULL == FALSE)
  9528. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9529. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9530. //Update idTag information to authorization cache if supproted
  9531. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9532. {
  9533. if((access(filename,F_OK))!=-1)
  9534. {
  9535. printf("AuthorizationCache exist.\n");
  9536. }
  9537. else
  9538. {
  9539. printf("AuthorizationCache not exist\n");
  9540. FILE *log = fopen(filename, "w+");
  9541. if(log == NULL)
  9542. {
  9543. printf("log is NULL\n");
  9544. goto out;
  9545. }
  9546. else
  9547. {
  9548. fclose(log);
  9549. }
  9550. }
  9551. FILE *infile;
  9552. FILE *outfile;
  9553. // open file for writing
  9554. infile = fopen (filename, "r");
  9555. outfile = fopen (tempfile, "w");
  9556. int c;
  9557. c = fgetc(infile);
  9558. //DEBUG_INFO("c:%d\n",c);
  9559. rewind(infile);
  9560. if(c == EOF)
  9561. {
  9562. DEBUG_INFO("Orignal File is NULL\n");
  9563. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9564. {
  9565. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9566. }
  9567. else
  9568. {
  9569. strcpy(expiryDatestrtemp, "");
  9570. }
  9571. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9572. {
  9573. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9574. }
  9575. else
  9576. {
  9577. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9578. }
  9579. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9580. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9581. fclose(infile);
  9582. fclose(outfile);
  9583. sprintf(rmFileCmd,"rm -f %s",filename);
  9584. system(rmFileCmd);
  9585. resultRename = rename(tempfile, filename);
  9586. if(resultRename == 0)
  9587. {
  9588. printf("File renamed successfully");
  9589. }
  9590. else
  9591. {
  9592. printf("Error: unable to rename the file");
  9593. }
  9594. }
  9595. else
  9596. {
  9597. char buf[160]={0};
  9598. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9599. {
  9600. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9601. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9602. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9603. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9604. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9605. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9606. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9607. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9608. //------------------IdTag-----------------------
  9609. loc = strstr(buf, "idTag");
  9610. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9611. c = 0;
  9612. while (loc[3+strlen("idTag")+c] != '\"')
  9613. {
  9614. sstr[c] = loc[3+strlen("idTag")+c];
  9615. c++;
  9616. }
  9617. sstr[c] = '\0';
  9618. strcpy(IdTagstrtemp,sstr);
  9619. //*********************expiryDate***************/
  9620. loc = strstr(buf, "expiryDate");
  9621. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9622. c = 0;
  9623. while (loc[3+strlen("expiryDate")+c] != '\"')
  9624. {
  9625. sstr[c] = loc[3+strlen("expiryDate")+c];
  9626. c++;
  9627. }
  9628. sstr[c] = '\0';
  9629. strcpy(expiryDatestr,sstr);
  9630. //*********************parentIdTag***************/
  9631. loc = strstr(buf, "parentIdTag");
  9632. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9633. c = 0;
  9634. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9635. {
  9636. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9637. c++;
  9638. }
  9639. sstr[c] = '\0';
  9640. strcpy(parentIdTagstr,sstr);
  9641. //*********************status***************/
  9642. loc = strstr(buf, "status");
  9643. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9644. c = 0;
  9645. while (loc[3+strlen("status")+c] != '\"')
  9646. {
  9647. sstr[c] = loc[3+strlen("status")+c];
  9648. c++;
  9649. }
  9650. sstr[c] = '\0';
  9651. strcpy(statusstr,sstr);
  9652. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9653. {
  9654. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9655. responseIdTagInfoAsZero = 1;
  9656. }
  9657. else
  9658. {
  9659. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9660. }
  9661. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9662. {
  9663. //modify item
  9664. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9665. {
  9666. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9667. }
  9668. else
  9669. {
  9670. strcpy(expiryDatestrtemp, "");
  9671. }
  9672. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9673. {
  9674. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9675. }
  9676. else
  9677. {
  9678. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9679. }
  9680. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9681. }
  9682. else
  9683. {
  9684. //wrie original item
  9685. strcpy(expiryDatestrtemp, expiryDatestr);
  9686. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9687. strcpy(statusstrtemp, statusstr);
  9688. }
  9689. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9690. }
  9691. fclose(infile);
  9692. fclose(outfile);
  9693. sprintf(rmFileCmd,"rm -f %s",filename);
  9694. system(rmFileCmd);
  9695. resultRename = rename(tempfile, filename);
  9696. if(resultRename == 0)
  9697. {
  9698. DEBUG_INFO("File renamed successfully");
  9699. }
  9700. else
  9701. {
  9702. DEBUG_INFO("Error: unable to rename the file");
  9703. }
  9704. }
  9705. }
  9706. out:
  9707. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9708. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9709. authorizeRetryTimes = 0;
  9710. }
  9711. char * strtrimc( char * s )
  9712. {
  9713. char * p1 = s;
  9714. char * p2 = s;
  9715. while(*p1 != '\0')
  9716. {
  9717. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9718. {
  9719. if(*p1 != ',')
  9720. {
  9721. p1 ++;
  9722. }
  9723. else
  9724. {
  9725. break;
  9726. }
  9727. }
  9728. if(*p1 != ',')
  9729. {
  9730. * p2 ++ = *p1 ++;
  9731. //printf("p2=%s\n",p2);
  9732. }
  9733. else
  9734. {
  9735. break;
  9736. }
  9737. }
  9738. *p2 = '\0';
  9739. return (s);
  9740. }
  9741. void handleBootNotificationResponse(char *payload, int gun_index)
  9742. {
  9743. mtrace();
  9744. char statusStr[12]={0};
  9745. char currentTimeStr[30]={0};
  9746. int intervalInt = 0;
  9747. struct tm tp;
  9748. char buf[28]={0};
  9749. char timebuf[50]={0};
  9750. DEBUG_INFO("handleBootNotificationResponse...\n");
  9751. json_object *BootNotification;
  9752. BootNotification = json_tokener_parse(payload);
  9753. if(!is_error(BootNotification))
  9754. {
  9755. // Required data
  9756. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9757. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9758. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9759. }
  9760. json_object_put(BootNotification);
  9761. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9762. BootNotificationInterval = intervalInt;
  9763. HeartBeatWaitTime = intervalInt;
  9764. //write back to ShmOCPP16Data->BootNotification
  9765. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9766. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9767. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9768. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9769. {
  9770. server_sign = TRUE;
  9771. server_pending =FALSE;
  9772. }
  9773. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9774. {
  9775. server_pending = TRUE;
  9776. }
  9777. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9778. tp.tm_isdst = -1;
  9779. //time_t utc = mktime(&tp);
  9780. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9781. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9782. sprintf(timebuf,"date -s '%s'",buf);
  9783. system(timebuf);
  9784. srand(time(NULL));
  9785. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9786. //==============================================
  9787. // RTC sync
  9788. //==============================================
  9789. system("/sbin/hwclock -w --systohc");
  9790. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9791. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9792. }
  9793. void handleDataTransferResponse(char *payload, int gun_index)
  9794. {
  9795. char sstr[160]={0};//sstr[200]={ 0 };
  9796. int c = 0;
  9797. char *loc;
  9798. DEBUG_INFO("handleDataTransferResponse ...\n");
  9799. loc = strstr(payload, "status");
  9800. printf("loc=%s\n",loc);
  9801. c = 0;
  9802. while (loc[3+strlen("status")+c] != '\"')
  9803. {
  9804. sstr[c] = loc[3+strlen("status")+c];
  9805. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9806. c++;
  9807. }
  9808. sstr[c] = '\0';
  9809. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9810. }
  9811. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9812. {
  9813. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9814. //struct json_object *obj;
  9815. // obj = json_tokener_parse(payload);
  9816. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9817. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9818. //No fields are defined.
  9819. }
  9820. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9821. {
  9822. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9823. //struct json_object *obj;
  9824. // obj = json_tokener_parse(payload);
  9825. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9826. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9827. //No fields are defined.
  9828. }
  9829. void handleHeartbeatResponse(char *payload, int gun_index)
  9830. {
  9831. mtrace();
  9832. struct tm tp;
  9833. char buf[28]={0};
  9834. char timebuf[50]={0};
  9835. DEBUG_INFO("handleHeartbeatResponse...\n");
  9836. json_object *Heartbeat;
  9837. Heartbeat = json_tokener_parse(payload);
  9838. if(!is_error(Heartbeat))
  9839. {
  9840. // Required data
  9841. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9842. }
  9843. json_object_put(BootNotification);
  9844. if(FirstHeartBeat == 0)
  9845. {
  9846. FirstHeartBeat = 1;
  9847. DEBUG_INFO("FirstHeartBeat \n");
  9848. }
  9849. HeartBeatWithNOResponse = 0;
  9850. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9851. tp.tm_isdst = -1;
  9852. //time_t utc = mktime(&tp);
  9853. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9854. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9855. sprintf(timebuf,"date -s '%s'",buf);
  9856. system(timebuf);
  9857. //==============================================
  9858. // RTC sync
  9859. //==============================================
  9860. system("/sbin/hwclock -w --systohc");
  9861. //===============================================
  9862. //Print Out HeartBeat log
  9863. //===============================================
  9864. {
  9865. double diff_t;
  9866. struct tm tp,tp1;
  9867. // BootNotification Receive Time
  9868. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9869. tp.tm_isdst = -1;
  9870. time_t BootNotificationReceiveTime = mktime(&tp);
  9871. //HeartBeat Receive Time
  9872. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9873. tp1.tm_isdst = -1;
  9874. time_t HeartBeatReceiveTime = mktime(&tp1);
  9875. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9876. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9877. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9878. {
  9879. HeartBeatCountPerHour = (int)diff_t / 3600;
  9880. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9881. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9882. }
  9883. }
  9884. }
  9885. void handleMeterValuesResponse(char *payload, int gun_index)
  9886. {
  9887. mtrace();
  9888. DEBUG_INFO("handleMeterValuesResponse...\n");
  9889. }
  9890. void handleStartTransactionResponse(char *payload, int gun_index)
  9891. {
  9892. mtrace();
  9893. //int transactionIdInt = 0;
  9894. FILE *outfile;
  9895. char data[100]={0};
  9896. DEBUG_INFO("handleStartTransactionResponse...\n");
  9897. json_object *StartTransaction;
  9898. StartTransaction = json_tokener_parse(payload);
  9899. if(!is_error(StartTransaction))
  9900. {
  9901. // Required data
  9902. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9903. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9904. // Optional data
  9905. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9906. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9907. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9908. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9909. }
  9910. json_object_put(StartTransaction);
  9911. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9912. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9913. //-----------Start : write to the Queue TransactionId file -----------------//
  9914. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9915. {}
  9916. else
  9917. {
  9918. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9919. if(log == NULL)
  9920. {
  9921. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9922. return ;
  9923. }
  9924. else
  9925. {
  9926. fclose(log);
  9927. }
  9928. }
  9929. // open file for writing
  9930. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9931. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9932. {
  9933. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9934. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9935. fputs(data, outfile);
  9936. fclose (outfile);
  9937. }
  9938. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9939. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9940. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9941. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9942. }
  9943. void handleStatusNotificationResponse(char *payload, int gun_index)
  9944. {
  9945. mtrace();
  9946. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9947. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9948. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9949. }
  9950. void handleStopTransactionnResponse(char *payload, int gun_index)
  9951. {
  9952. mtrace();
  9953. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9954. json_object *StopTransaction;
  9955. StopTransaction = json_tokener_parse(payload);
  9956. if(!is_error(StopTransaction))
  9957. {
  9958. // Optional data
  9959. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9960. {
  9961. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9962. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9963. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9964. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9965. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9966. }
  9967. }
  9968. json_object_put(StopTransaction);
  9969. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9970. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9971. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9972. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9973. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9974. }
  9975. //==========================================
  9976. // Handle Error routine
  9977. //==========================================
  9978. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9979. {
  9980. mtrace();
  9981. #ifdef SystemLogMessage
  9982. DEBUG_INFO("errorCode: %s\n", errorCode);
  9983. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9984. DEBUG_INFO("errorDetails: %s\n", payload);
  9985. #endif
  9986. }
  9987. //===============================================
  9988. // Common routine
  9989. //===============================================
  9990. int initialConfigurationTable(void)
  9991. {
  9992. //clock_t start_t, end_t, total_t;
  9993. FILE *fp;
  9994. FILE *outfile;
  9995. char str[200]={0};
  9996. char sstr[100]={0};
  9997. int c = 0;
  9998. char *loc;
  9999. DEBUG_INFO("initialConfigurationTable...\n");
  10000. //start_t = clock();
  10001. //printf("Starting of the program, start_t = %ld\n", start_t);
  10002. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10003. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10004. {
  10005. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10006. if(outfile == NULL)
  10007. {
  10008. DEBUG_INFO("Error opening file\n");
  10009. return FALSE;
  10010. }
  10011. /*Core Profile*/
  10012. //AllowOfflineTxForUnknownId
  10013. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10017. //AuthorizationCacheEnabled
  10018. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10022. //AuthorizeRemoteTxRequests
  10023. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10027. //BlinkRepeat
  10028. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10032. //ClockAlignedDataInterval
  10033. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10037. //ConnectionTimeOut
  10038. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10042. //GetConfigurationMaxKeys
  10043. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10047. // HeartbeatInterval
  10048. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10052. // LightIntensity
  10053. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10057. // LocalAuthorizeOffline
  10058. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10062. // LocalPreAuthorize
  10063. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10067. // MaxEnergyOnInvalidId
  10068. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10071. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10073. // MeterValuesAlignedData
  10074. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10076. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10078. else
  10079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10081. // MeterValuesAlignedDataMaxLength
  10082. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10084. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10086. else
  10087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10089. // MeterValuesSampledData
  10090. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10092. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10094. else
  10095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10097. // MeterValuesSampledDataMaxLength
  10098. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10100. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10102. else
  10103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10105. // MeterValueSampleInterval
  10106. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10110. // MinimumStatusDuration
  10111. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10114. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10116. // NumberOfConnectors
  10117. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10120. {
  10121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10122. }
  10123. else
  10124. {
  10125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10126. }
  10127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10128. // ResetRetries
  10129. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10133. // ConnectorPhaseRotation
  10134. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10138. // ConnectorPhaseRotationMaxLength
  10139. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10143. // StopTransactionOnEVSideDisconnect
  10144. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10148. // StopTransactionOnInvalidId
  10149. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10153. // StopTxnAlignedData
  10154. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10158. // StopTxnAlignedDataMaxLength
  10159. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10163. // StopTxnSampledData
  10164. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10166. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10168. else
  10169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10171. // StopTxnSampledDataMaxLength
  10172. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10174. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10175. {
  10176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10177. }
  10178. else
  10179. {
  10180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10181. }
  10182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10183. // SupportedFeatureProfiles
  10184. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10188. // SupportedFeatureProfilesMaxLength
  10189. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10193. // TransactionMessageAttempts
  10194. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10197. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10199. // TransactionMessageRetryInterval
  10200. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10203. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10205. // UnlockConnectorOnEVSideDisconnect
  10206. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10210. // WebSocketPingInterval
  10211. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10215. // QueueOffLineStartTransactionMessage
  10216. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10220. // AuthorizationKey
  10221. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10225. // SecurityProfile
  10226. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10230. //* Local Auth List Management Profile*/
  10231. #if 0
  10232. //For OCTT Test Case
  10233. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10236. #endif
  10237. #if 1
  10238. //LocalAuthListEnabled
  10239. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10243. #endif
  10244. //LocalAuthListMaxLength
  10245. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10249. //SendLocalListMaxLength
  10250. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10254. //ReserveConnectorZeroSupported
  10255. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10259. //* Smart Charging Profile */
  10260. //ChargeProfileMaxStackLevel
  10261. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10265. // ChargingScheduleAllowedChargingRateUnit
  10266. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10270. // ChargingScheduleMaxPeriods
  10271. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10275. // ConnectorSwitch3to1PhaseSupported
  10276. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10280. // MaxChargingProfilesInstalled
  10281. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10285. fclose(outfile);
  10286. }
  10287. else
  10288. {
  10289. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10290. char keystr[60]={0};
  10291. char readonlystr[10]={0};
  10292. char valuestr[100]={0};
  10293. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10294. if(fp == NULL) {
  10295. DEBUG_INFO("Error opening file");
  10296. return FALSE;
  10297. }
  10298. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10299. {
  10300. //DEBUG_INFO("Get Configuration \n");
  10301. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10302. //*************************key*********************************/
  10303. loc = strstr(str, "key");
  10304. c = 0;
  10305. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10306. while (loc[strlen("key")+3+c] != '\"')
  10307. {
  10308. sstr[c] = loc[strlen("key")+3+c];
  10309. c++;
  10310. }
  10311. sstr[c] = '\0';
  10312. strcpy(keystr,sstr);
  10313. //*************************readonly*********************************/
  10314. loc = strstr(str, "readonly");
  10315. c = 0;
  10316. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10317. while (loc[strlen("readonly")+2+c] != ',')
  10318. {
  10319. sstr[c] = loc[strlen("readonly")+2+c];
  10320. c++;
  10321. }
  10322. sstr[c] = '\0';
  10323. strcpy(readonlystr,sstr);
  10324. //*************************value*********************************/
  10325. loc = strstr(str, "value");
  10326. c = 0;
  10327. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10328. while (loc[strlen("value")+3+c] != '\"')
  10329. {
  10330. sstr[c] = loc[strlen("value")+3+c];
  10331. c++;
  10332. }
  10333. sstr[c] = '\0';
  10334. strcpy(valuestr,sstr);
  10335. // DEBUG_INFO("keystr=%s\n",keystr);
  10336. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10337. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10338. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10339. {
  10340. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10341. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10343. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10344. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10345. }
  10346. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10347. {
  10348. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10349. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10351. }
  10352. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10353. {
  10354. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10356. }
  10357. if(strcmp(keystr, "BlinkRepeat") == 0)
  10358. {
  10359. //Charger.BlinkRepeat = Integer.parseInt(value);
  10360. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10362. }
  10363. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10364. {
  10365. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10367. }
  10368. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10369. {
  10370. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10372. }
  10373. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10374. {
  10375. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10377. }
  10378. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10379. {
  10380. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10382. HeartBeatWaitTime = atoi(valuestr);
  10383. }
  10384. if(strcmp(keystr, "LightIntensity") == 0)
  10385. {
  10386. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10388. }
  10389. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10390. {
  10391. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10393. }
  10394. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10395. {
  10396. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10398. }
  10399. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10400. {
  10401. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10403. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10404. }
  10405. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10406. {
  10407. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10409. }
  10410. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10411. {
  10412. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10414. }
  10415. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10416. {
  10417. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10419. }
  10420. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10421. {
  10422. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10424. }
  10425. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10426. {
  10427. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10429. }
  10430. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10431. {
  10432. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10434. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10435. }
  10436. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10437. {
  10438. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10440. }
  10441. if(strcmp(keystr, "ResetRetries") == 0)
  10442. {
  10443. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10445. }
  10446. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10447. {
  10448. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10450. }
  10451. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10452. {
  10453. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10455. }
  10456. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10457. {
  10458. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10460. }
  10461. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10462. {
  10463. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10465. }
  10466. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10467. {
  10468. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10470. }
  10471. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10472. {
  10473. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10475. }
  10476. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10477. {
  10478. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10480. }
  10481. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10482. {
  10483. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10485. }
  10486. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10487. {
  10488. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10490. }
  10491. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10492. {
  10493. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10495. }
  10496. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10497. {
  10498. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10500. TransactionMessageAttemptsValue = atoi(valuestr);
  10501. }
  10502. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10503. {
  10504. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10506. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10507. }
  10508. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10509. {
  10510. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10512. }
  10513. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10514. {
  10515. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10517. }
  10518. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10519. {
  10520. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10522. }
  10523. if(strcmp(keystr, "AuthorizationKey") == 0)
  10524. {
  10525. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10527. }
  10528. if(strcmp(keystr, "SecurityProfile") == 0)
  10529. {
  10530. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10532. }
  10533. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10534. {
  10535. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10537. }
  10538. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10539. {
  10540. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10542. }
  10543. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10544. {
  10545. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10547. }
  10548. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10549. {
  10550. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10552. }
  10553. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10554. {
  10555. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10557. }
  10558. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10559. {
  10560. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10562. }
  10563. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10564. {
  10565. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10567. }
  10568. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10569. {
  10570. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10572. }
  10573. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10574. {
  10575. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10577. }
  10578. }
  10579. fclose(fp);
  10580. }
  10581. return 0;
  10582. }
  10583. void StoreConfigurationTable(void)
  10584. {
  10585. FILE *outfile;
  10586. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10587. if(outfile == NULL)
  10588. {
  10589. DEBUG_INFO("Error opening file");
  10590. return ;
  10591. }
  10592. /*Core Profile*/
  10593. //AllowOfflineTxForUnknownId
  10594. /*
  10595. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10596. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10599. */
  10600. //DEBUG_INFO("data=%s\n",data);
  10601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10602. //AuthorizationCacheEnabled
  10603. /*
  10604. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10607. */
  10608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10609. //AuthorizeRemoteTxRequests
  10610. /*
  10611. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10614. */
  10615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10616. //BlinkRepeat
  10617. /*
  10618. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10621. */
  10622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10623. //ClockAlignedDataInterval
  10624. /*
  10625. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10628. */
  10629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10630. //ConnectionTimeOut
  10631. /*
  10632. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10635. */
  10636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10637. //GetConfigurationMaxKeys
  10638. /*
  10639. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10642. */
  10643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10644. // HeartbeatInterval
  10645. /*
  10646. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10649. */
  10650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10651. // LightIntensity
  10652. /*
  10653. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10656. */
  10657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10658. // LocalAuthorizeOffline
  10659. /*
  10660. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10663. */
  10664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10665. // LocalPreAuthorize
  10666. /*
  10667. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10670. */
  10671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10672. // MaxEnergyOnInvalidId
  10673. /*
  10674. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10677. */
  10678. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10680. // MeterValuesAlignedData
  10681. /*
  10682. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10685. */
  10686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10687. // MeterValuesAlignedDataMaxLength
  10688. /*
  10689. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10692. */
  10693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10694. // MeterValuesSampledData
  10695. /*
  10696. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10699. */
  10700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10701. // MeterValuesSampledDataMaxLength
  10702. /*
  10703. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10706. */
  10707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10708. // MeterValueSampleInterval
  10709. /*
  10710. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10713. */
  10714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10715. // MinimumStatusDuration
  10716. /*
  10717. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10720. */
  10721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10722. // NumberOfConnectors
  10723. /*
  10724. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10726. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10727. {
  10728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10729. }
  10730. else
  10731. {
  10732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10733. }
  10734. */
  10735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10736. // ResetRetries
  10737. /*
  10738. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10741. */
  10742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10743. // ConnectorPhaseRotation
  10744. /*
  10745. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10748. */
  10749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10750. // ConnectorPhaseRotationMaxLength
  10751. /*
  10752. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10755. */
  10756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10757. // StopTransactionOnEVSideDisconnect
  10758. /*
  10759. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10762. */
  10763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10764. // StopTransactionOnInvalidId
  10765. /*
  10766. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10769. */
  10770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10771. // StopTxnAlignedData
  10772. /*
  10773. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10776. */
  10777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10778. // StopTxnAlignedDataMaxLength
  10779. /*
  10780. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10783. */
  10784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10785. // StopTxnSampledData
  10786. /*
  10787. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10790. */
  10791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10792. // StopTxnSampledDataMaxLength
  10793. /*
  10794. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10797. */
  10798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10799. // SupportedFeatureProfiles
  10800. /*
  10801. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10804. */
  10805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10806. // SupportedFeatureProfilesMaxLength
  10807. /*
  10808. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10811. */
  10812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10813. // TransactionMessageAttempts
  10814. /*
  10815. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10818. */
  10819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10820. // TransactionMessageRetryInterval
  10821. /*
  10822. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10825. */
  10826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10827. // UnlockConnectorOnEVSideDisconnect
  10828. /*
  10829. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10832. */
  10833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10834. // WebSocketPingInterval
  10835. /*
  10836. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10839. */
  10840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10841. // QueueOffLineStartTransactionMessage
  10842. /*
  10843. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10846. */
  10847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10848. // AuthorizationKey
  10849. /*
  10850. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10853. */
  10854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10855. // SecurityProfile
  10856. /*
  10857. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10860. */
  10861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10862. //* Local Auth List Management Profile*/
  10863. //LocalAuthListEnabled
  10864. /*
  10865. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10868. */
  10869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10870. //LocalAuthListMaxLength
  10871. /*
  10872. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10875. */
  10876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10877. //SendLocalListMaxLength
  10878. /*
  10879. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10882. */
  10883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10884. //ReserveConnectorZeroSupported
  10885. /*
  10886. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10889. */
  10890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10891. //* Smart Charging Profile */
  10892. //ChargeProfileMaxStackLevel
  10893. /*
  10894. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10897. */
  10898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10899. // ChargingScheduleAllowedChargingRateUnit
  10900. /*
  10901. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10904. */
  10905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10906. // ChargingScheduleMaxPeriods
  10907. /*
  10908. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10911. */
  10912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10913. // ConnectorSwitch3to1PhaseSupported
  10914. /*
  10915. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10918. */
  10919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10920. // MaxChargingProfilesInstalled
  10921. /*
  10922. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10925. */
  10926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10927. fclose(outfile);
  10928. }
  10929. void getKeyValue(char *keyReq)
  10930. {
  10931. int isEmpty = FALSE;
  10932. int isKnowKey = FALSE;
  10933. DEBUG_INFO("keyReq = %s\n", keyReq);
  10934. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10935. isEmpty = TRUE;
  10936. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10937. {
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10940. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10941. {
  10942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10943. }
  10944. else
  10945. {
  10946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10947. }
  10948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10949. isKnowKey = TRUE;
  10950. }
  10951. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10952. {
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10955. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10956. {
  10957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10958. }
  10959. else
  10960. {
  10961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10962. }
  10963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10964. isKnowKey = TRUE;
  10965. }
  10966. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10967. {
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10971. {
  10972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10973. }
  10974. else
  10975. {
  10976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10977. }
  10978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10979. isKnowKey = TRUE;
  10980. }
  10981. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10982. {
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10986. {
  10987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10988. }
  10989. else
  10990. {
  10991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10992. }
  10993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10994. isKnowKey = TRUE;
  10995. }
  10996. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10997. {
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11001. {
  11002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11003. }
  11004. else
  11005. {
  11006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11007. }
  11008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11009. isKnowKey = TRUE;
  11010. }
  11011. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11012. {
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11016. {
  11017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11018. }
  11019. else
  11020. {
  11021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11022. }
  11023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11024. isKnowKey = TRUE;
  11025. }
  11026. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11027. {
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11030. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11031. {
  11032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11033. }
  11034. else
  11035. {
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11037. }
  11038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11039. isKnowKey = TRUE;
  11040. }
  11041. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11042. {
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11046. {
  11047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11048. }
  11049. else
  11050. {
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11052. }
  11053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11054. isKnowKey = TRUE;
  11055. }
  11056. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11057. {
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11061. {
  11062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11063. }
  11064. else
  11065. {
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11067. }
  11068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11069. isKnowKey = TRUE;
  11070. }
  11071. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11072. {
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11076. {
  11077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11078. }
  11079. else
  11080. {
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11082. }
  11083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11084. isKnowKey = TRUE;
  11085. }
  11086. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11087. {
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11091. {
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11093. }
  11094. else
  11095. {
  11096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11097. }
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11099. isKnowKey = TRUE;
  11100. }
  11101. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11102. {
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11106. {
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11108. }
  11109. else
  11110. {
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11112. }
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11114. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11115. isKnowKey = TRUE;
  11116. }
  11117. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11118. {
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11121. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11122. {
  11123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11124. }
  11125. else
  11126. {
  11127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11128. }
  11129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11130. isKnowKey = TRUE;
  11131. }
  11132. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11133. {
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11136. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11137. {
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11139. }
  11140. else
  11141. {
  11142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11143. }
  11144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11145. isKnowKey = TRUE;
  11146. }
  11147. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11148. {
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11152. {
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11154. }
  11155. else
  11156. {
  11157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11158. }
  11159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11160. isKnowKey = TRUE;
  11161. }
  11162. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11163. {
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11166. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11167. {
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11169. }
  11170. else
  11171. {
  11172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11173. }
  11174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11175. isKnowKey = TRUE;
  11176. }
  11177. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11178. {
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11182. {
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11184. }
  11185. else
  11186. {
  11187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11188. }
  11189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11190. isKnowKey = TRUE;
  11191. }
  11192. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11193. {
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11197. {
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11199. }
  11200. else
  11201. {
  11202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11203. }
  11204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11205. isKnowKey = TRUE;
  11206. }
  11207. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11208. {
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11211. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11212. {
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11214. }
  11215. else
  11216. {
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11218. }
  11219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11220. isKnowKey = TRUE;
  11221. }
  11222. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11223. {
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11227. {
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11229. }
  11230. else
  11231. {
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11233. }
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11235. isKnowKey = TRUE;
  11236. }
  11237. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11238. {
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11244. }
  11245. else
  11246. {
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11248. }
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11250. isKnowKey = TRUE;
  11251. }
  11252. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11253. {
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11259. }
  11260. else
  11261. {
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11263. }
  11264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11265. isKnowKey = TRUE;
  11266. }
  11267. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11268. {
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11272. {
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11274. }
  11275. else
  11276. {
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11278. }
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11280. isKnowKey = TRUE;
  11281. }
  11282. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11283. {
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11287. {
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11289. }
  11290. else
  11291. {
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11293. }
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11295. isKnowKey = TRUE;
  11296. }
  11297. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11298. {
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11302. {
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11304. }
  11305. else
  11306. {
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11308. }
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11310. isKnowKey = TRUE;
  11311. }
  11312. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11313. {
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11317. {
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11319. }
  11320. else
  11321. {
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11323. }
  11324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11325. isKnowKey = TRUE;
  11326. }
  11327. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11328. {
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11332. {
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11334. }
  11335. else
  11336. {
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11338. }
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11340. isKnowKey = TRUE;
  11341. }
  11342. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11343. {
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11347. {
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11349. }
  11350. else
  11351. {
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11353. }
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11355. isKnowKey = TRUE;
  11356. }
  11357. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11358. {
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11362. {
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11364. }
  11365. else
  11366. {
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11368. }
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11370. isKnowKey = TRUE;
  11371. }
  11372. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11373. {
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11377. {
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11379. }
  11380. else
  11381. {
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11383. }
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11385. isKnowKey = TRUE;
  11386. }
  11387. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11388. {
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11392. {
  11393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11394. }
  11395. else
  11396. {
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11398. }
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11400. isKnowKey = TRUE;
  11401. }
  11402. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11403. {
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11407. {
  11408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11409. }
  11410. else
  11411. {
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11413. }
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11415. isKnowKey = TRUE;
  11416. }
  11417. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11418. {
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11422. {
  11423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11424. }
  11425. else
  11426. {
  11427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11428. }
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11430. isKnowKey = TRUE;
  11431. }
  11432. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11433. {
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11437. {
  11438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11439. }
  11440. else
  11441. {
  11442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11443. }
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11445. isKnowKey = TRUE;
  11446. }
  11447. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11448. {
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11452. {
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11454. }
  11455. else
  11456. {
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11458. }
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11460. isKnowKey = TRUE;
  11461. }
  11462. /*
  11463. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11464. {
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11467. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11468. {
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11470. }
  11471. else
  11472. {
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11474. }
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11476. isKnowKey = TRUE;
  11477. }*/
  11478. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11479. {
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11482. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11483. {
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11485. }
  11486. else
  11487. {
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11489. }
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11491. isKnowKey = TRUE;
  11492. }
  11493. #if 1
  11494. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11495. {
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11498. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11501. }
  11502. else
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11505. }
  11506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11507. isKnowKey = TRUE;
  11508. }
  11509. #endif
  11510. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11511. {
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11514. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11515. {
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11517. }
  11518. else
  11519. {
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11521. }
  11522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11523. isKnowKey = TRUE;
  11524. }
  11525. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11526. {
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11529. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11530. {
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11532. }
  11533. else
  11534. {
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11536. }
  11537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11538. isKnowKey = TRUE;
  11539. }
  11540. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11541. {
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11544. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11545. {
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11547. }
  11548. else
  11549. {
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11551. }
  11552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11553. isKnowKey = TRUE;
  11554. }
  11555. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11556. {
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11559. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11560. {
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11562. }
  11563. else
  11564. {
  11565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11566. }
  11567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11568. isKnowKey = TRUE;
  11569. }
  11570. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11571. {
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11574. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11575. {
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11577. }
  11578. else
  11579. {
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11581. }
  11582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11583. isKnowKey = TRUE;
  11584. }
  11585. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11586. {
  11587. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11589. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11590. {
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11592. }
  11593. else
  11594. {
  11595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11596. }
  11597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11598. isKnowKey = TRUE;
  11599. }
  11600. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11601. {
  11602. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11604. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11605. {
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11607. }
  11608. else
  11609. {
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11611. }
  11612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11613. isKnowKey = TRUE;
  11614. }
  11615. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11616. {
  11617. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11619. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11620. {
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11622. }
  11623. else
  11624. {
  11625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11626. }
  11627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11628. isKnowKey = TRUE;
  11629. }
  11630. //=========================================================
  11631. if(!isEmpty && !isKnowKey)
  11632. {
  11633. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11634. strcpy(unknownkey[UnknownKeynum], keyReq);
  11635. UnknownKeynum = UnknownKeynum + 1;
  11636. }
  11637. }
  11638. void processUnkownKey(void)
  11639. {
  11640. DEBUG_INFO("processUnkownKey...\n");
  11641. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11642. for(int index=0; index < UnknownKeynum; index++)
  11643. {
  11644. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11645. {
  11646. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11647. }
  11648. }
  11649. }
  11650. int setKeyValue(char *key, char *value)
  11651. {
  11652. int isSuccess = NotSupported;
  11653. int check_ascii=0;
  11654. char str[10]={0};
  11655. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11656. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11657. {
  11658. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11659. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11660. {
  11661. strcpy(str, (const char*)value);
  11662. for(int i = 0; str[i]; i++){
  11663. str[i] = tolower(str[i]);
  11664. }
  11665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11666. isSuccess = ConfigurationStatus_Accepted;
  11667. }
  11668. else
  11669. {
  11670. isSuccess = ConfigurationStatus_Rejected;
  11671. }
  11672. }
  11673. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11674. {
  11675. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11677. {
  11678. strcpy(str, (const char*)value);
  11679. for(int i = 0; str[i]; i++){
  11680. str[i] = tolower(str[i]);
  11681. }
  11682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11683. isSuccess = ConfigurationStatus_Accepted;
  11684. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11685. }
  11686. else
  11687. {
  11688. isSuccess = ConfigurationStatus_Rejected;
  11689. }
  11690. }
  11691. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11692. {
  11693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11694. {
  11695. strcpy(str, (const char*)value);
  11696. for(int i = 0; str[i]; i++)
  11697. {
  11698. str[i] = tolower(str[i]);
  11699. }
  11700. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11702. isSuccess = ConfigurationStatus_Accepted;
  11703. }
  11704. else
  11705. {
  11706. isSuccess = ConfigurationStatus_Rejected;
  11707. }
  11708. }
  11709. if(strcmp(key, "BlinkRepeat") == 0)
  11710. {
  11711. //Charger.BlinkRepeat = Integer.parseInt(value);
  11712. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11713. {
  11714. check_ascii = value[0];
  11715. if( (check_ascii < 48) || (check_ascii > 57) )
  11716. {
  11717. isSuccess = ConfigurationStatus_Rejected;
  11718. }
  11719. else
  11720. {
  11721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11722. isSuccess = ConfigurationStatus_Accepted;
  11723. }
  11724. }
  11725. else
  11726. {
  11727. isSuccess = ConfigurationStatus_Rejected;
  11728. }
  11729. }
  11730. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11731. {
  11732. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11733. {
  11734. check_ascii = value[0];
  11735. if( (check_ascii < 48) || (check_ascii > 57) )
  11736. {
  11737. isSuccess = ConfigurationStatus_Rejected;
  11738. }
  11739. else
  11740. {
  11741. if((atoi(value) == 0) || (atoi(value) >= 10))
  11742. {
  11743. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11745. isSuccess = ConfigurationStatus_Accepted;
  11746. }
  11747. else
  11748. isSuccess = ConfigurationStatus_Rejected;
  11749. }
  11750. }
  11751. else
  11752. {
  11753. isSuccess = ConfigurationStatus_Rejected;
  11754. }
  11755. }
  11756. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11757. {
  11758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11759. {
  11760. check_ascii = value[0];
  11761. if( (check_ascii < 48) || (check_ascii > 57) )
  11762. {
  11763. isSuccess = ConfigurationStatus_Rejected;
  11764. }
  11765. else
  11766. {
  11767. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11769. isSuccess = ConfigurationStatus_Accepted;
  11770. }
  11771. }
  11772. else
  11773. {
  11774. isSuccess = ConfigurationStatus_Rejected;
  11775. }
  11776. }
  11777. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11778. {
  11779. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11780. {
  11781. check_ascii = value[0];
  11782. if( (check_ascii < 48) || (check_ascii > 57) )
  11783. {
  11784. isSuccess = ConfigurationStatus_Rejected;
  11785. }
  11786. else
  11787. {
  11788. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11790. isSuccess = ConfigurationStatus_Accepted;
  11791. }
  11792. }
  11793. else
  11794. {
  11795. isSuccess = ConfigurationStatus_Rejected;
  11796. }
  11797. }
  11798. if(strcmp(key, "HeartbeatInterval") == 0)
  11799. {
  11800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11801. {
  11802. check_ascii = value[0];
  11803. if( (check_ascii < 48) || (check_ascii > 57) )
  11804. {
  11805. isSuccess = ConfigurationStatus_Rejected;
  11806. }
  11807. else
  11808. {
  11809. if((atoi(value) == 0) || (atoi(value) >= 10))
  11810. {
  11811. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11813. HeartBeatWaitTime = atoi(value);
  11814. isSuccess = ConfigurationStatus_Accepted;
  11815. }
  11816. else
  11817. {
  11818. isSuccess = ConfigurationStatus_Rejected;
  11819. }
  11820. }
  11821. }
  11822. else
  11823. {
  11824. isSuccess = ConfigurationStatus_Rejected;
  11825. }
  11826. }
  11827. if(strcmp(key, "LightIntensity") == 0)
  11828. {
  11829. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11830. {
  11831. check_ascii = value[0];
  11832. if( (check_ascii < 48) || (check_ascii > 57) )
  11833. {
  11834. isSuccess = ConfigurationStatus_Rejected;
  11835. }
  11836. else
  11837. {
  11838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11839. isSuccess = ConfigurationStatus_Accepted;
  11840. }
  11841. }
  11842. else
  11843. {
  11844. isSuccess = ConfigurationStatus_Rejected;
  11845. }
  11846. }
  11847. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11848. {
  11849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].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. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11857. isSuccess = ConfigurationStatus_Accepted;
  11858. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11859. }
  11860. else
  11861. {
  11862. isSuccess = ConfigurationStatus_Rejected;
  11863. }
  11864. }
  11865. if(strcmp(key, "LocalPreAuthorize") == 0)
  11866. {
  11867. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11868. {
  11869. strcpy(str, (const char*)value);
  11870. for(int i = 0; str[i]; i++)
  11871. {
  11872. str[i] = tolower(str[i]);
  11873. }
  11874. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11875. isSuccess = ConfigurationStatus_Accepted;
  11876. }
  11877. else
  11878. {
  11879. isSuccess = ConfigurationStatus_Rejected;
  11880. }
  11881. }
  11882. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11883. {
  11884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11885. {
  11886. check_ascii = value[0];
  11887. if( (check_ascii < 48) || (check_ascii > 57) )
  11888. {
  11889. isSuccess = ConfigurationStatus_Rejected;
  11890. }
  11891. else
  11892. {
  11893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11894. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11895. isSuccess = ConfigurationStatus_Accepted;
  11896. }
  11897. }
  11898. else
  11899. {
  11900. isSuccess = ConfigurationStatus_Rejected;
  11901. }
  11902. }
  11903. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11904. {
  11905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11906. {
  11907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11908. isSuccess = ConfigurationStatus_Accepted;
  11909. }
  11910. else
  11911. {
  11912. isSuccess = ConfigurationStatus_Rejected;
  11913. }
  11914. }
  11915. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11916. {
  11917. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11918. {
  11919. check_ascii = value[0];
  11920. if( (check_ascii < 48) || (check_ascii > 57) )
  11921. {
  11922. isSuccess = ConfigurationStatus_Rejected;
  11923. }
  11924. else
  11925. {
  11926. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11928. isSuccess = ConfigurationStatus_Accepted;
  11929. }
  11930. }
  11931. else
  11932. {
  11933. isSuccess = ConfigurationStatus_Rejected;
  11934. }
  11935. }
  11936. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11937. {
  11938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11939. {
  11940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11941. isSuccess = ConfigurationStatus_Accepted;
  11942. }
  11943. else
  11944. {
  11945. isSuccess = ConfigurationStatus_Rejected;
  11946. }
  11947. }
  11948. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11949. {
  11950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11951. {
  11952. check_ascii = value[0];
  11953. if( (check_ascii < 48) || (check_ascii > 57) )
  11954. {
  11955. isSuccess = ConfigurationStatus_Rejected;
  11956. }
  11957. else
  11958. {
  11959. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11961. isSuccess = ConfigurationStatus_Accepted;
  11962. }
  11963. }
  11964. else
  11965. {
  11966. isSuccess = ConfigurationStatus_Rejected;
  11967. }
  11968. }
  11969. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11970. {
  11971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11972. {
  11973. check_ascii = value[0];
  11974. if( (check_ascii < 48) || (check_ascii > 57) )
  11975. {
  11976. isSuccess = ConfigurationStatus_Rejected;
  11977. }
  11978. else
  11979. {
  11980. if((atoi(value) == 0) || (atoi(value) >= 10))
  11981. {
  11982. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11984. isSuccess = ConfigurationStatus_Accepted;
  11985. }
  11986. else
  11987. {
  11988. isSuccess = ConfigurationStatus_Rejected;
  11989. }
  11990. }
  11991. }
  11992. else
  11993. {
  11994. isSuccess = ConfigurationStatus_Rejected;
  11995. }
  11996. }
  11997. if(strcmp(key, "MinimumStatusDuration") == 0)
  11998. {
  11999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12000. {
  12001. check_ascii = value[0];
  12002. if( (check_ascii < 48) || (check_ascii > 57) )
  12003. {
  12004. isSuccess = ConfigurationStatus_Rejected;
  12005. }
  12006. else
  12007. {
  12008. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12009. {
  12010. isSuccess = ConfigurationStatus_Rejected;
  12011. }
  12012. else
  12013. {
  12014. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12016. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12017. isSuccess = ConfigurationStatus_Accepted;
  12018. }
  12019. }
  12020. }
  12021. else
  12022. {
  12023. isSuccess = ConfigurationStatus_Rejected;
  12024. }
  12025. }
  12026. if(strcmp(key, "NumberOfConnectors") == 0)
  12027. {
  12028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12029. {
  12030. check_ascii = value[0];
  12031. if( (check_ascii < 48) || (check_ascii > 57) )
  12032. {
  12033. isSuccess = ConfigurationStatus_Rejected;
  12034. }
  12035. else
  12036. {
  12037. //Charger.ResetRetries = Integer.parseInt(value);
  12038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12039. isSuccess = ConfigurationStatus_Accepted;
  12040. }
  12041. }
  12042. else
  12043. {
  12044. isSuccess = ConfigurationStatus_Rejected;
  12045. }
  12046. }
  12047. if(strcmp(key, "ResetRetries") == 0)
  12048. {
  12049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12050. {
  12051. check_ascii = value[0];
  12052. if( (check_ascii < 48) || (check_ascii > 57) )
  12053. {
  12054. isSuccess = ConfigurationStatus_Rejected;
  12055. }
  12056. else
  12057. {
  12058. //Charger.ResetRetries = Integer.parseInt(value);
  12059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12060. isSuccess = ConfigurationStatus_Accepted;
  12061. }
  12062. }
  12063. else
  12064. {
  12065. isSuccess = ConfigurationStatus_Rejected;
  12066. }
  12067. }
  12068. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12069. {
  12070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12071. {
  12072. strcpy(str, (const char*)value);
  12073. for(int i = 0; str[i]; i++)
  12074. {
  12075. str[i] = tolower(str[i]);
  12076. }
  12077. if(strcmp(str, "notapplicable")== 0)
  12078. {
  12079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12080. isSuccess = ConfigurationStatus_Accepted;
  12081. }
  12082. else if(strcmp(str, "unknown")== 0)
  12083. {
  12084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12085. isSuccess = ConfigurationStatus_Accepted;
  12086. }
  12087. else if(strcmp(str, "rst")== 0)
  12088. {
  12089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12090. isSuccess = ConfigurationStatus_Accepted;
  12091. }
  12092. else if(strcmp(str, "rts")== 0)
  12093. {
  12094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12095. isSuccess = ConfigurationStatus_Accepted;
  12096. }
  12097. else if(strcmp(str, "srt")== 0)
  12098. {
  12099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12100. isSuccess = ConfigurationStatus_Accepted;
  12101. }
  12102. else if(strcmp(str, "str")== 0)
  12103. {
  12104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12105. isSuccess = ConfigurationStatus_Accepted;
  12106. }
  12107. else if(strcmp(str, "trs")== 0)
  12108. {
  12109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12110. isSuccess = ConfigurationStatus_Accepted;
  12111. }
  12112. else if(strcmp(str, "tsr")== 0)
  12113. {
  12114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12115. isSuccess = ConfigurationStatus_Accepted;
  12116. }
  12117. else
  12118. {
  12119. isSuccess = ConfigurationStatus_Rejected;
  12120. }
  12121. }
  12122. else
  12123. {
  12124. isSuccess = ConfigurationStatus_Rejected;
  12125. }
  12126. }
  12127. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12128. {
  12129. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12130. {
  12131. check_ascii = value[0];
  12132. if( (check_ascii < 48) || (check_ascii > 57) )
  12133. {
  12134. isSuccess = ConfigurationStatus_Rejected;
  12135. }
  12136. else
  12137. {
  12138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12139. isSuccess = ConfigurationStatus_Accepted;
  12140. }
  12141. }
  12142. else
  12143. {
  12144. isSuccess = ConfigurationStatus_Rejected;
  12145. }
  12146. }
  12147. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12148. {
  12149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12150. {
  12151. strcpy(str, (const char*)value);
  12152. for(int i = 0; str[i]; i++)
  12153. {
  12154. str[i] = tolower(str[i]);
  12155. }
  12156. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12158. isSuccess = ConfigurationStatus_Accepted;
  12159. }
  12160. else
  12161. {
  12162. isSuccess = ConfigurationStatus_Rejected;
  12163. }
  12164. }
  12165. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12166. {
  12167. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12168. {
  12169. strcpy(str, (const char*)value);
  12170. for(int i = 0; str[i]; i++)
  12171. {
  12172. str[i] = tolower(str[i]);
  12173. }
  12174. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12176. isSuccess = ConfigurationStatus_Accepted;
  12177. }
  12178. else
  12179. {
  12180. isSuccess = ConfigurationStatus_Rejected;
  12181. }
  12182. }
  12183. if(strcmp(key, "StopTxnAlignedData") == 0)
  12184. {
  12185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12186. {
  12187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12188. isSuccess = ConfigurationStatus_Accepted;
  12189. }
  12190. else
  12191. {
  12192. isSuccess = ConfigurationStatus_Rejected;
  12193. }
  12194. }
  12195. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12196. {
  12197. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12198. {
  12199. check_ascii = value[0];
  12200. if( (check_ascii < 48) || (check_ascii > 57) )
  12201. {
  12202. isSuccess = ConfigurationStatus_Rejected;
  12203. }
  12204. else
  12205. {
  12206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12207. isSuccess = ConfigurationStatus_Accepted;
  12208. }
  12209. }
  12210. else
  12211. {
  12212. isSuccess = ConfigurationStatus_Rejected;
  12213. }
  12214. }
  12215. if(strcmp(key, "StopTxnSampledData") == 0)
  12216. {
  12217. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12218. {
  12219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12220. isSuccess = ConfigurationStatus_Accepted;
  12221. }
  12222. else
  12223. {
  12224. isSuccess = ConfigurationStatus_Rejected;
  12225. }
  12226. }
  12227. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12228. {
  12229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12230. {
  12231. check_ascii = value[0];
  12232. if( (check_ascii < 48) || (check_ascii > 57) )
  12233. {
  12234. isSuccess = ConfigurationStatus_Rejected;
  12235. }
  12236. else
  12237. {
  12238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12239. isSuccess = ConfigurationStatus_Accepted;
  12240. }
  12241. }
  12242. else
  12243. {
  12244. isSuccess = ConfigurationStatus_Rejected;
  12245. }
  12246. }
  12247. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12248. {
  12249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12250. {
  12251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12252. isSuccess = ConfigurationStatus_Accepted;
  12253. }
  12254. else
  12255. {
  12256. isSuccess = ConfigurationStatus_Rejected;
  12257. }
  12258. }
  12259. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12260. {
  12261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12262. {
  12263. check_ascii = value[0];
  12264. if( (check_ascii < 48) || (check_ascii > 57) )
  12265. {
  12266. isSuccess = ConfigurationStatus_Rejected;
  12267. }
  12268. else
  12269. {
  12270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12271. isSuccess = ConfigurationStatus_Accepted;
  12272. }
  12273. }
  12274. else
  12275. {
  12276. isSuccess = ConfigurationStatus_Rejected;
  12277. }
  12278. }
  12279. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12280. {
  12281. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12282. {
  12283. check_ascii = value[0];
  12284. if( (check_ascii < 48) || (check_ascii > 57) )
  12285. {
  12286. isSuccess = ConfigurationStatus_Rejected;
  12287. }
  12288. else
  12289. {
  12290. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12292. TransactionMessageAttemptsValue = atoi(value);
  12293. isSuccess = ConfigurationStatus_Accepted;
  12294. }
  12295. }
  12296. else
  12297. {
  12298. isSuccess = ConfigurationStatus_Rejected;
  12299. }
  12300. }
  12301. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12302. {
  12303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12304. {
  12305. check_ascii = value[0];
  12306. if( (check_ascii < 48) || (check_ascii > 57) )
  12307. {
  12308. isSuccess = ConfigurationStatus_Rejected;
  12309. }
  12310. else
  12311. {
  12312. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12314. TransactionMessageRetryIntervalValue = atoi(value);
  12315. isSuccess = ConfigurationStatus_Accepted;
  12316. }
  12317. }
  12318. else
  12319. {
  12320. isSuccess = ConfigurationStatus_Rejected;
  12321. }
  12322. }
  12323. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12324. {
  12325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12326. {
  12327. strcpy(str, (const char*)value);
  12328. for(int i = 0; str[i]; i++)
  12329. {
  12330. str[i] = tolower(str[i]);
  12331. }
  12332. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12334. isSuccess = ConfigurationStatus_Accepted;
  12335. }
  12336. else
  12337. {
  12338. isSuccess = ConfigurationStatus_Rejected;
  12339. }
  12340. }
  12341. if(strcmp(key, "WebSocketPingInterval") == 0)
  12342. {
  12343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12344. {
  12345. check_ascii = value[0];
  12346. if( (check_ascii < 48) || (check_ascii > 57) )
  12347. {
  12348. isSuccess = ConfigurationStatus_Rejected;
  12349. }
  12350. else
  12351. {
  12352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12353. isSuccess = ConfigurationStatus_Accepted;
  12354. }
  12355. }
  12356. else
  12357. {
  12358. isSuccess = ConfigurationStatus_Rejected;
  12359. }
  12360. }
  12361. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12362. {
  12363. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12364. {
  12365. strcpy(str, (const char*)value);
  12366. for(int i = 0; str[i]; i++)
  12367. {
  12368. str[i] = tolower(str[i]);
  12369. }
  12370. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12372. isSuccess = ConfigurationStatus_Accepted;
  12373. }
  12374. else
  12375. {
  12376. isSuccess = ConfigurationStatus_Rejected;
  12377. }
  12378. }
  12379. if(strcmp(key, "AuthorizationKey") == 0)
  12380. {
  12381. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12382. {
  12383. strcpy(str, (const char*)value);
  12384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12385. isSuccess = ConfigurationStatus_Accepted;
  12386. }
  12387. else
  12388. {
  12389. isSuccess = ConfigurationStatus_Rejected;
  12390. }
  12391. }
  12392. if(strcmp(key, "SecurityProfile") == 0)
  12393. {
  12394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12395. {
  12396. check_ascii = value[0];
  12397. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12398. {
  12399. isSuccess = ConfigurationStatus_Rejected;
  12400. }
  12401. else if(check_ascii == 0x33)
  12402. {
  12403. isSuccess = NotSupported;
  12404. }
  12405. else
  12406. {
  12407. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12408. {
  12409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12410. isSuccess = ConfigurationStatus_Accepted;
  12411. }
  12412. else
  12413. isSuccess = ConfigurationStatus_Rejected;
  12414. }
  12415. }
  12416. else
  12417. {
  12418. isSuccess = ConfigurationStatus_Rejected;
  12419. }
  12420. }
  12421. #if 0
  12422. //For OCPP Test Case
  12423. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12424. {
  12425. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12426. {
  12427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12428. isSuccess = ConfigurationStatus_Accepted;
  12429. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12430. }
  12431. else
  12432. {
  12433. isSuccess = ConfigurationStatus_Rejected;
  12434. }
  12435. }
  12436. #endif
  12437. #if 1
  12438. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12439. {
  12440. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12441. {
  12442. strcpy(str, (const char*)value);
  12443. for(int i = 0; str[i]; i++)
  12444. {
  12445. str[i] = tolower(str[i]);
  12446. }
  12447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12448. isSuccess = ConfigurationStatus_Accepted;
  12449. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12450. }
  12451. else
  12452. {
  12453. isSuccess = ConfigurationStatus_Rejected;
  12454. }
  12455. }
  12456. #endif
  12457. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12458. {
  12459. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].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. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12469. isSuccess = ConfigurationStatus_Accepted;
  12470. }
  12471. }
  12472. else
  12473. {
  12474. isSuccess = ConfigurationStatus_Rejected;
  12475. }
  12476. }
  12477. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12478. {
  12479. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12480. {
  12481. check_ascii = value[0];
  12482. if( (check_ascii < 48) || (check_ascii > 57) )
  12483. {
  12484. isSuccess = ConfigurationStatus_Rejected;
  12485. }
  12486. else
  12487. {
  12488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12489. isSuccess = ConfigurationStatus_Accepted;
  12490. }
  12491. }
  12492. else
  12493. {
  12494. isSuccess = ConfigurationStatus_Rejected;
  12495. }
  12496. }
  12497. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12498. {
  12499. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12500. {
  12501. strcpy(str, (const char*)value);
  12502. for(int i = 0; str[i]; i++)
  12503. {
  12504. str[i] = tolower(str[i]);
  12505. }
  12506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12507. isSuccess = ConfigurationStatus_Accepted;
  12508. }
  12509. else
  12510. {
  12511. isSuccess = ConfigurationStatus_Rejected;
  12512. }
  12513. }
  12514. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12515. {
  12516. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12517. {
  12518. check_ascii = value[0];
  12519. if( (check_ascii < 48) || (check_ascii > 57) )
  12520. {
  12521. isSuccess = ConfigurationStatus_Rejected;
  12522. }
  12523. else
  12524. {
  12525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12526. isSuccess = ConfigurationStatus_Accepted;
  12527. }
  12528. }
  12529. else
  12530. {
  12531. isSuccess = ConfigurationStatus_Rejected;
  12532. }
  12533. }
  12534. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12535. {
  12536. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12537. {
  12538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12539. isSuccess = ConfigurationStatus_Accepted;
  12540. }
  12541. else
  12542. {
  12543. isSuccess = ConfigurationStatus_Rejected;
  12544. }
  12545. }
  12546. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12547. {
  12548. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12549. {
  12550. check_ascii = value[0];
  12551. if( (check_ascii < 48) || (check_ascii > 57) )
  12552. {
  12553. isSuccess = ConfigurationStatus_Rejected;
  12554. }
  12555. else
  12556. {
  12557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12558. isSuccess = ConfigurationStatus_Accepted;
  12559. }
  12560. }
  12561. else
  12562. {
  12563. isSuccess = ConfigurationStatus_Rejected;
  12564. }
  12565. }
  12566. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12567. {
  12568. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12569. {
  12570. strcpy(str, (const char*)value);
  12571. for(int i = 0; str[i]; i++)
  12572. {
  12573. str[i] = tolower(str[i]);
  12574. }
  12575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12576. isSuccess = ConfigurationStatus_Accepted;
  12577. }
  12578. else
  12579. {
  12580. isSuccess = ConfigurationStatus_Rejected;
  12581. }
  12582. }
  12583. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12584. {
  12585. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12586. {
  12587. check_ascii = value[0];
  12588. if( (check_ascii < 48) || (check_ascii > 57) )
  12589. {
  12590. isSuccess = ConfigurationStatus_Rejected;
  12591. }
  12592. else
  12593. {
  12594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12595. isSuccess = ConfigurationStatus_Accepted;
  12596. }
  12597. }
  12598. else
  12599. {
  12600. isSuccess = ConfigurationStatus_Rejected;
  12601. }
  12602. }
  12603. return isSuccess;
  12604. }
  12605. int TransactionMessageAttemptsGet(void)
  12606. {
  12607. return TransactionMessageAttemptsValue;
  12608. }
  12609. int FirstHeartBeatResponse(void)
  12610. {
  12611. return FirstHeartBeat;
  12612. }
  12613. int TransactionMessageRetryIntervalGet(void)
  12614. {
  12615. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12616. }
  12617. int ReadHttpStatus(int sock)
  12618. {
  12619. //char c;
  12620. char buff[1024]="",*ptr=buff+1;
  12621. int bytes_received, status;
  12622. DEBUG_INFO("Begin Response ..\n");
  12623. while((bytes_received = recv(sock, ptr, 1, 0))){
  12624. if(bytes_received==-1){
  12625. perror("ReadHttpStatus");
  12626. exit(1);
  12627. }
  12628. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12629. ptr++;
  12630. }
  12631. *ptr=0;
  12632. ptr=buff+1;
  12633. sscanf(ptr,"%*s %d ", &status);
  12634. DEBUG_INFO("%s\n",ptr);
  12635. DEBUG_INFO("status=%d\n",status);
  12636. DEBUG_INFO("End Response ..\n");
  12637. return (bytes_received>0)?status:0;
  12638. }
  12639. //the only filed that it parsed is 'Content-Length'
  12640. int ParseHeader(int sock)
  12641. {
  12642. //char c;
  12643. char buff[1024]="",*ptr=buff+4;
  12644. int bytes_received;
  12645. DEBUG_INFO("Begin HEADER ..\n");
  12646. while((bytes_received = recv(sock, ptr, 1, 0))){
  12647. if(bytes_received==-1){
  12648. perror("Parse Header");
  12649. exit(1);
  12650. }
  12651. if(
  12652. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12653. (ptr[-1]=='\r') && (*ptr=='\n' )
  12654. ) break;
  12655. ptr++;
  12656. }
  12657. *ptr=0;
  12658. ptr=buff+4;
  12659. //printf("%s",ptr);
  12660. if(bytes_received){
  12661. ptr=strstr(ptr,"Content-Length:");
  12662. if(ptr){
  12663. sscanf(ptr,"%*s %d",&bytes_received);
  12664. }else
  12665. bytes_received=-1; //unknown size
  12666. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12667. }
  12668. DEBUG_INFO("End HEADER ..\n");
  12669. return bytes_received ;
  12670. }
  12671. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12672. {
  12673. char rmFileCmd[100]={0};
  12674. char FilePath[100]={0};
  12675. char ftpbuf[200];
  12676. int systemresult;
  12677. //DEBUG_INFO("filename=%s\n",filename);
  12678. //DEBUG_INFO("url=%s\n",url);
  12679. sprintf(FilePath,"/mnt/%s",filename);
  12680. if((access(FilePath,F_OK))!=-1)
  12681. {
  12682. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12683. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12684. system(rmFileCmd);
  12685. }
  12686. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12687. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12688. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12689. systemresult = system(ftpbuf);
  12690. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12691. if(systemresult != 0)
  12692. {
  12693. DEBUG_INFO("http DownLoad error!\n");
  12694. return FALSE;
  12695. }
  12696. return TRUE;
  12697. }
  12698. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12699. {
  12700. char rmFileCmd[100]={0};
  12701. char FilePath[100]={0};
  12702. char ftpbuf[200];
  12703. int systemresult;
  12704. //char temp[100];
  12705. sprintf(FilePath,"/mnt/%s",filename);
  12706. if((access(FilePath,F_OK))!=-1)
  12707. {
  12708. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12709. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12710. system(rmFileCmd);
  12711. }
  12712. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12713. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12714. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12715. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12716. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12717. systemresult = system(ftpbuf);
  12718. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12719. if(systemresult != 0)
  12720. {
  12721. printf("wget error!\n");
  12722. return FALSE;
  12723. }
  12724. return TRUE;
  12725. }
  12726. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12727. {
  12728. char rmFileCmd[100]={0};
  12729. char FilePath[100]={0};
  12730. char ftpbuf[200];
  12731. int systemresult;
  12732. //DEBUG_INFO("filename=%s\n",filename);
  12733. //DEBUG_INFO("url=%s\n",url);
  12734. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12735. if((access(FilePath,F_OK))!=-1)
  12736. {
  12737. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12738. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12739. system(rmFileCmd);
  12740. }
  12741. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12742. if(fp == NULL)
  12743. {
  12744. DEBUG_INFO("log is NULL\n");
  12745. return FALSE;
  12746. }
  12747. else
  12748. {
  12749. fprintf(fp, "%s\n", url);
  12750. fprintf(fp, "%s\n", filename);
  12751. fclose(fp);
  12752. }
  12753. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12754. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12755. systemresult = system(ftpbuf);
  12756. DEBUG_INFO("systemresult = %d\n",systemresult);
  12757. if(systemresult != 0)
  12758. {
  12759. DEBUG_INFO("http upload error!\n");
  12760. return FALSE;
  12761. }
  12762. return TRUE;
  12763. }
  12764. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12765. {
  12766. struct hostent* server;
  12767. char *IPbuffer;
  12768. char ftpbuf[200];
  12769. int systemresult;
  12770. // To retrieve host information
  12771. server = gethostbyname(location);
  12772. // To convert an Internet network
  12773. // address into ASCII string
  12774. IPbuffer = inet_ntoa(*((struct in_addr*)
  12775. server->h_addr_list[0]));
  12776. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12777. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12778. /* format : ftpput -u username -p passwd IP target source*/
  12779. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12780. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12781. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12782. systemresult = system(ftpbuf);
  12783. DEBUG_INFO("systemresult=%d\n",systemresult);
  12784. if(systemresult != 0)
  12785. {
  12786. DEBUG_INFO("ftpput error!\n");
  12787. return FALSE;
  12788. }
  12789. return TRUE;
  12790. }
  12791. /**
  12792. * Place the contents of the specified file into a memory buffer
  12793. *
  12794. * @param[in] filename The path and name of the file to read
  12795. * @param[out] filebuffer A pointer to the contents in memory
  12796. * @return status 0 success, 1 on failure
  12797. */
  12798. int get_file_contents(const char* filename, char** outbuffer) {
  12799. FILE* file = NULL;
  12800. long filesize;
  12801. const int blocksize = 1;
  12802. size_t readsize;
  12803. char* filebuffer;
  12804. // Open the file
  12805. file = fopen(filename, "r");
  12806. if (NULL == file)
  12807. {
  12808. printf("'%s' not opened\n", filename);
  12809. exit(EXIT_FAILURE);
  12810. }
  12811. // Determine the file size
  12812. fseek(file, 0, SEEK_END);
  12813. filesize = ftell(file);
  12814. rewind (file);
  12815. // Allocate memory for the file contents
  12816. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12817. *outbuffer = filebuffer;
  12818. if (filebuffer == NULL)
  12819. {
  12820. fputs ("malloc out-of-memory", stderr);
  12821. exit(EXIT_FAILURE);
  12822. }
  12823. // Read in the file
  12824. readsize = fread(filebuffer, blocksize, filesize, file);
  12825. if (readsize != filesize)
  12826. {
  12827. fputs ("didn't read file completely",stderr);
  12828. exit(EXIT_FAILURE);
  12829. }
  12830. // Clean exit
  12831. fclose(file);
  12832. return EXIT_SUCCESS;
  12833. }
  12834. static int selectSqlCount = 0;
  12835. static int callback(void *data, int argc, char **argv, char **azColName){
  12836. int i;
  12837. //printf("%s: ", (const char*)data);
  12838. selectSqlCount = argc;
  12839. for(i = 0; i<argc; i++){
  12840. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12841. }
  12842. //printf("\n");
  12843. return 0;
  12844. }
  12845. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12846. //int i;
  12847. //printf("%s:\n", (const char*)data);
  12848. localversion = argv[5] ? atoi(argv[5]) : 0;
  12849. //printf("localversion=%d\n", localversion);
  12850. return 0;
  12851. }
  12852. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12853. //int i;
  12854. //printf("%s:\n", (const char*)data);
  12855. //idTag
  12856. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12857. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12858. //parentIdTag
  12859. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12860. //expir_date
  12861. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12862. //status
  12863. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12864. //version
  12865. idTagQuery.listVersionInt = atoi(argv[5]);
  12866. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12867. return 0;
  12868. }
  12869. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12870. {
  12871. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12872. // printf("localversion=%d\n", localversion);
  12873. return 0;
  12874. }
  12875. //=========================================
  12876. // Sqlite3 related function
  12877. //=========================================
  12878. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12879. {
  12880. for (int i = 0; i < n_columns; i++)
  12881. {
  12882. DEBUG_INFO("%s\t", col_values[i]);
  12883. }
  12884. DEBUG_INFO("\n");
  12885. return 0;
  12886. }
  12887. void OCPP_getListVerion()
  12888. {
  12889. int rc = 0;
  12890. // const char* data = "Callback function called";
  12891. char sql[100];
  12892. char zErrMsg[100];
  12893. memset(sql, 0, 100);
  12894. memset(zErrMsg, 0, 100);
  12895. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12896. /* Execute SQL statement */
  12897. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12898. if( rc != SQLITE_OK )
  12899. {
  12900. DEBUG_INFO("SQL error: %s", zErrMsg);
  12901. }
  12902. }
  12903. void OCPP_getIdTag(char idTag[])
  12904. {
  12905. int rc = 0;
  12906. // const char* data = "Callback function called";
  12907. char sql[100];
  12908. char zErrMsg[100];
  12909. memset(sql, 0, 100);
  12910. memset(zErrMsg, 0, 100);
  12911. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12912. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12913. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12914. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12915. /* Execute SQL statement */
  12916. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12917. if( rc != SQLITE_OK )
  12918. {
  12919. DEBUG_INFO("SQL error: %s", zErrMsg);
  12920. }
  12921. //return ver;
  12922. }
  12923. void OCPP_get_TableAuthlocalAllData(void)
  12924. {
  12925. int rc = 0;
  12926. char sql[100];
  12927. char zErrMsg[100];
  12928. memset(sql, 0, 100);
  12929. memset(zErrMsg, 0, 100);
  12930. sprintf(sql,"select * from ocpp_auth_local ");
  12931. /* Execute SQL statement */
  12932. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12933. if( rc != SQLITE_OK )
  12934. {
  12935. DEBUG_INFO("SQL error: %s", zErrMsg);
  12936. }
  12937. //return ver;
  12938. }
  12939. int OCPP_cleanLocalList()
  12940. {
  12941. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12942. char *errMsg = 0;
  12943. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12944. if (SQLITE_OK != rc)
  12945. {
  12946. DEBUG_INFO("%s\n",errMsg);
  12947. return FALSE;
  12948. }
  12949. return TRUE;
  12950. }
  12951. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12952. {
  12953. int isSuccess = FALSE;
  12954. int ret = 0;
  12955. //const char* data = "Callback function called";
  12956. char sql[300];
  12957. char zErrMsg[200];
  12958. memset(sql, 0, 300);
  12959. memset(zErrMsg, 0, 200);
  12960. 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);
  12961. //* Execute SQL statement */
  12962. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12963. if( ret != SQLITE_OK )
  12964. {
  12965. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12966. return isSuccess;
  12967. }
  12968. memset(sql, 0, 300);
  12969. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12970. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12971. if( ret != SQLITE_OK )
  12972. {
  12973. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12974. return isSuccess;
  12975. }
  12976. isSuccess = TRUE;
  12977. return isSuccess;
  12978. }
  12979. void OCPP_deleteIdTag(char idTag[])
  12980. {
  12981. //int ver = 0;
  12982. //int isSuccess = FALSE;
  12983. int rc = 0;
  12984. char sql[100];
  12985. char zErrMsg[100];
  12986. memset(sql, 0, 100);
  12987. memset(zErrMsg, 0, 100);
  12988. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12989. //* Execute SQL statement */
  12990. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12991. if( rc != SQLITE_OK )
  12992. {
  12993. DEBUG_INFO("SQL error: %s", zErrMsg);
  12994. }
  12995. }
  12996. int GetOcppServerURL()
  12997. {
  12998. int result = FALSE;
  12999. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13000. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13001. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13002. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13003. {
  13004. #if 1
  13005. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13006. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13007. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13008. #endif
  13009. result = TRUE;
  13010. goto End;
  13011. }
  13012. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13013. {
  13014. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13015. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13016. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13017. result = TRUE;
  13018. goto End;
  13019. }
  13020. else
  13021. {
  13022. strcpy(OcppHost,"");
  13023. }
  13024. End:
  13025. return result;
  13026. }
  13027. int GetOcppPath()
  13028. {
  13029. int result = FALSE;
  13030. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13031. {
  13032. if(OcppTempPath == NULL)
  13033. {
  13034. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13035. }
  13036. else
  13037. {
  13038. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13039. }
  13040. result = TRUE;
  13041. goto End;
  13042. }
  13043. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13044. {
  13045. if(OcppTempPath == NULL)
  13046. {
  13047. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13048. }
  13049. else
  13050. {
  13051. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13052. }
  13053. result = TRUE;
  13054. goto End;
  13055. }
  13056. else
  13057. {
  13058. strcpy(OcppPath,"");
  13059. }
  13060. End:
  13061. return result;
  13062. }
  13063. int GetOcppPort()
  13064. {
  13065. return OcppPort;
  13066. }
  13067. int GetOcppConnStatus(void)
  13068. {
  13069. return ShmOCPP16Data->OcppConnStatus;
  13070. }
  13071. void SetOcppConnStatus(uint8_t status)
  13072. {
  13073. ShmOCPP16Data->OcppConnStatus = status;
  13074. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13075. }
  13076. int GetHeartBeatWithNOResponse(void)
  13077. {
  13078. return HeartBeatWithNOResponse;
  13079. }
  13080. void SetHeartBeatWithNOResponse(void)
  13081. {
  13082. HeartBeatWithNOResponse = 0;
  13083. }
  13084. void GetStartTransactionIdTag(int gun_index)
  13085. {
  13086. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13087. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13088. }
  13089. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13090. {
  13091. char ch;
  13092. FILE *fptr1;
  13093. int temptransactionId;
  13094. char str[100]={0};
  13095. temptransactionId = 0;
  13096. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13097. {
  13098. DEBUG_INFO("IdTag is empty.\n");
  13099. return temptransactionId;
  13100. }
  13101. /*------ Read the file ----------------*/
  13102. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13103. if (!fptr1)
  13104. {
  13105. DEBUG_INFO("QueueTransactionId file open error.\n");
  13106. //printf(" File not found or unable to open the input file!!\n");
  13107. return temptransactionId;
  13108. }
  13109. ch=fgetc(fptr1);
  13110. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13111. rewind(fptr1);
  13112. if(ch!=EOF)
  13113. {
  13114. // printf("%c",ch);
  13115. while (fgets(str, 100, fptr1) != NULL)
  13116. {
  13117. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13118. if(str[0]=='\0')
  13119. {
  13120. break;
  13121. }
  13122. char *revbuf[8] = {0}; //存放分割後的子字串
  13123. int num = 0;//分割後子字串的個數
  13124. DEBUG_INFO("str: %s\n", str);
  13125. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13126. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13127. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13128. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13129. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13130. {
  13131. if(isStopTransaction)
  13132. {
  13133. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13134. {
  13135. temptransactionId = atoi(revbuf[2]);
  13136. break;
  13137. }
  13138. }
  13139. else
  13140. {
  13141. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13142. {
  13143. temptransactionId = atoi(revbuf[2]);
  13144. break;
  13145. }
  13146. }
  13147. }
  13148. }
  13149. }
  13150. else
  13151. DEBUG_INFO("EOF\n");
  13152. fclose(fptr1);
  13153. /*------- End of reading ---------------*/
  13154. return temptransactionId;
  13155. }
  13156. void SetTransactionIdZero(int transactionId)
  13157. {
  13158. char ch;
  13159. FILE *fptr1, *fptr2;
  13160. int temptransactionId = 0;
  13161. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13162. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13163. if (!fptr1)
  13164. {
  13165. //printf(" File not found or unable to open the input file!!\n");
  13166. return ;
  13167. }
  13168. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13169. if (!fptr2)
  13170. {
  13171. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13172. fclose(fptr1);
  13173. return ;
  13174. }
  13175. ch=fgetc(fptr1);
  13176. rewind(fptr1);
  13177. if(ch!=EOF)
  13178. {
  13179. // copy all contents to the temporary file except the specific line
  13180. while (fgets(str, 100, fptr1) != NULL)
  13181. {
  13182. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13183. if(str[0]=='\0')
  13184. {
  13185. break;
  13186. }
  13187. char *revbuf[8] = {0};
  13188. int num = 0;
  13189. strcpy(strtemp, str);
  13190. splitstring(str,",",revbuf,&num);
  13191. if(revbuf[2][0] != '\0')
  13192. {
  13193. temptransactionId = atoi(revbuf[2]);
  13194. if(transactionId != temptransactionId)
  13195. {
  13196. fprintf(fptr2, "%s\n", strtemp);
  13197. }
  13198. }
  13199. }
  13200. }
  13201. fclose(fptr1);
  13202. fclose(fptr2);
  13203. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13204. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13205. /*------ Read the file ----------------*/
  13206. }
  13207. int InternetDisconnect(void)
  13208. {
  13209. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13210. }
  13211. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13212. void storeTempStopTransaction(int gun_index)
  13213. {
  13214. char guid[37]={0};
  13215. int tempIndex = 0;
  13216. char TempStopTransaction[256];
  13217. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13218. DEBUG_INFO("storeTempStopTransaction...\n");
  13219. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13220. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13221. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13222. if(gunType[gun_index] == 'J')
  13223. {
  13224. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13225. {
  13226. tempIndex = ((gun_index==2) ? 1: 0);
  13227. }
  13228. else
  13229. {
  13230. tempIndex = gun_index;
  13231. }
  13232. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13233. {
  13234. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13235. {
  13236. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13237. }
  13238. }// END OF CHAdeMO_QUANTITY
  13239. }
  13240. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13241. {
  13242. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13243. {
  13244. tempIndex = ((gun_index==2) ? 1: 0);
  13245. }
  13246. else
  13247. {
  13248. tempIndex = gun_index;
  13249. }
  13250. for (int index = 0; index < CCS_QUANTITY; index++)
  13251. {
  13252. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13253. {
  13254. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13255. }
  13256. }// END OF CCS_QUANTITY
  13257. }
  13258. else if(gunType[gun_index] == 'G')
  13259. {
  13260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13261. {
  13262. tempIndex = ((gun_index==2) ? 1: 0);
  13263. }
  13264. else
  13265. {
  13266. tempIndex = gun_index;
  13267. }
  13268. for (int index = 0; index < GB_QUANTITY; index++)
  13269. {
  13270. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13271. {
  13272. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13273. }
  13274. }// END OF GB_QUANTITY
  13275. }
  13276. else
  13277. {
  13278. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13279. {
  13280. tempIndex = 2;
  13281. }
  13282. else
  13283. {
  13284. tempIndex = gun_index;
  13285. }
  13286. for (int index = 0; index < AC_QUANTITY; index++)
  13287. {
  13288. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13289. {
  13290. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13291. }
  13292. }// END OF AC_QUANTITY
  13293. }
  13294. //Stop Transaction Time
  13295. struct timeval tmnow;
  13296. struct tm *tm;
  13297. char buf[28];//, usec_buf[6];
  13298. gettimeofday(&tmnow, NULL);
  13299. time_t t;
  13300. t = time(NULL);
  13301. /*UTC time and date*/
  13302. tm = gmtime(&t);
  13303. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13305. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13307. random_uuid(guid);
  13308. /***********************************transactionData******************************************************/
  13309. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13311. //=================================
  13312. //1. Transaction_Begin
  13313. //=================================
  13314. //============================== Energy.Active.Import.Interval ===========================================
  13315. //idx_sample=0;
  13316. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13319. 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*/]);
  13320. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13321. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13322. {
  13323. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13324. }
  13325. else
  13326. {
  13327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13328. }
  13329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13331. //=================================
  13332. //2. Transaction_End
  13333. //=================================
  13334. //2.1====================================== Current.Import L1 ==============================================
  13335. //idx_sample=1;
  13336. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13337. if(gunType[gun_index] == 'J')
  13338. {
  13339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13340. {
  13341. tempIndex = ((gun_index==2) ? 1: 0);
  13342. }
  13343. else
  13344. {
  13345. tempIndex = gun_index;
  13346. }
  13347. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13348. {
  13349. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13350. {
  13351. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13352. }
  13353. }// End of for CHAdeMO_QUANTITY
  13354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13355. }
  13356. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13357. {
  13358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13359. {
  13360. tempIndex = ((gun_index==2) ? 1: 0);
  13361. }
  13362. else
  13363. {
  13364. tempIndex = gun_index;
  13365. }
  13366. for (int index = 0; index < CCS_QUANTITY; index++)
  13367. {
  13368. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13369. {
  13370. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13371. }
  13372. }// End of for CCS_QUANTITY
  13373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13374. }
  13375. else if(gunType[gun_index] == 'G')
  13376. {
  13377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13378. {
  13379. tempIndex = ((gun_index==2) ? 1: 0);
  13380. }
  13381. else
  13382. {
  13383. tempIndex = gun_index;
  13384. }
  13385. for (int index = 0; index < GB_QUANTITY; index++)
  13386. {
  13387. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13388. {
  13389. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13390. }
  13391. }// End of for GB_QUANTITY
  13392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13393. }
  13394. else
  13395. {
  13396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13397. {
  13398. tempIndex = 2;
  13399. }
  13400. else
  13401. {
  13402. tempIndex = gun_index;
  13403. }
  13404. for (int index = 0; index < AC_QUANTITY; index++)
  13405. {
  13406. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13407. {
  13408. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13409. }
  13410. }// End of for AC_QUANTITY
  13411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13412. }
  13413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13416. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13419. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13420. //idx_sample=2;
  13421. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13422. if(gunType[gun_index] == 'J')
  13423. {
  13424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13425. {
  13426. tempIndex = ((gun_index==2) ? 1: 0);
  13427. }
  13428. else
  13429. {
  13430. tempIndex = gun_index;
  13431. }
  13432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13433. {
  13434. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13435. {
  13436. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13437. }
  13438. }// END OF CHAdeMO_QUANTITY
  13439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13440. }
  13441. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13442. {
  13443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13444. {
  13445. tempIndex = ((gun_index==2) ? 1: 0);
  13446. }
  13447. else
  13448. {
  13449. tempIndex = gun_index;
  13450. }
  13451. for (int index = 0; index < CCS_QUANTITY; index++)
  13452. {
  13453. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13454. {
  13455. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13456. }
  13457. }// END OF CCS_QUANTITY
  13458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13459. }
  13460. else if(gunType[gun_index] == 'G')
  13461. {
  13462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13463. {
  13464. tempIndex = ((gun_index==2) ? 1: 0);
  13465. }
  13466. else
  13467. {
  13468. tempIndex = gun_index;
  13469. }
  13470. for (int index = 0; index < GB_QUANTITY; index++)
  13471. {
  13472. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13473. {
  13474. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13475. }
  13476. }// END OF GB_QUANTITY
  13477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13478. }
  13479. else
  13480. {
  13481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13482. {
  13483. tempIndex = 2;
  13484. }
  13485. else
  13486. {
  13487. tempIndex = gun_index;
  13488. }
  13489. for (int index = 0; index < AC_QUANTITY; index++)
  13490. {
  13491. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13492. {
  13493. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13494. }
  13495. }// END OF AC_QUANTITY
  13496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13497. }
  13498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13501. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13504. //2.3====================================== Power.Active.Import =========================================
  13505. //idx_sample=3;
  13506. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13507. if(gunType[gun_index] == 'J')
  13508. {
  13509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13510. {
  13511. tempIndex = ((gun_index==2) ? 1: 0);
  13512. }
  13513. else
  13514. {
  13515. tempIndex = gun_index;
  13516. }
  13517. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13518. {
  13519. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13520. {
  13521. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13522. }
  13523. } // End for CHAdeMO_QUANTITY
  13524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13525. }
  13526. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13527. {
  13528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13529. {
  13530. tempIndex = ((gun_index==2) ? 1: 0);
  13531. }
  13532. else
  13533. {
  13534. tempIndex = gun_index;
  13535. }
  13536. for (int index = 0; index < CCS_QUANTITY; index++)
  13537. {
  13538. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13539. {
  13540. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13541. }
  13542. } // END for CCS_QUANTITY
  13543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13544. }
  13545. else if(gunType[gun_index] == 'G')
  13546. {
  13547. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13548. {
  13549. tempIndex = ((gun_index==2) ? 1: 0);
  13550. }
  13551. else
  13552. {
  13553. tempIndex = gun_index;
  13554. }
  13555. for (int index = 0; index < GB_QUANTITY; index++)
  13556. {
  13557. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13558. {
  13559. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13560. }
  13561. }// END for GB_QUANTITY
  13562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13563. }
  13564. else
  13565. {
  13566. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13567. {
  13568. tempIndex = 2;
  13569. }
  13570. else
  13571. {
  13572. tempIndex = gun_index;
  13573. }
  13574. for (int index = 0; index < AC_QUANTITY; index++)
  13575. {
  13576. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13577. {
  13578. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13579. }
  13580. } // END for AC_QUANTITY
  13581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13582. }
  13583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13586. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13589. //2.4====================================== Voltage L1 ====================================================
  13590. //idx_sample=4;
  13591. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13592. if(gunType[gun_index] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  13603. {
  13604. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13605. {
  13606. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13607. }
  13608. } // END OF FOR CHAdeMO_QUANTITY
  13609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13610. }
  13611. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13612. {
  13613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13614. {
  13615. tempIndex = ((gun_index==2) ? 1: 0);
  13616. }
  13617. else
  13618. {
  13619. tempIndex = gun_index;
  13620. }
  13621. for (int index = 0; index < CCS_QUANTITY; index++)
  13622. {
  13623. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13624. {
  13625. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13626. }
  13627. } // END OF FOR CCS_QUANTITY
  13628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13629. }
  13630. else if(gunType[gun_index] == 'G')
  13631. {
  13632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13633. {
  13634. tempIndex = ((gun_index==2) ? 1: 0);
  13635. }
  13636. else
  13637. {
  13638. tempIndex = gun_index;
  13639. }
  13640. for (int index = 0; index < GB_QUANTITY; index++)
  13641. {
  13642. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13643. {
  13644. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13645. }
  13646. } // END OF FOR GB_QUANTITY
  13647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13648. }
  13649. else
  13650. {
  13651. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13652. {
  13653. tempIndex = 2;
  13654. }
  13655. else
  13656. {
  13657. tempIndex = gun_index;
  13658. }
  13659. for (int index = 0; index < AC_QUANTITY; index++)
  13660. {
  13661. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13662. {
  13663. 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
  13664. }
  13665. } // END OF FOR AC_QUANTITY
  13666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13667. }
  13668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13671. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13674. //2.5============================================== SoC =========================================================
  13675. //idx_sample=5;
  13676. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13677. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13678. {
  13679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13680. {
  13681. tempIndex = ((gun_index==2) ? 1: 0);
  13682. }
  13683. else
  13684. {
  13685. tempIndex = gun_index;
  13686. }
  13687. if(gunType[gun_index] == 'J')
  13688. {
  13689. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13690. {
  13691. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13692. {
  13693. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13694. }
  13695. }
  13696. }
  13697. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13698. {
  13699. for (int index = 0; index < CCS_QUANTITY; index++)
  13700. {
  13701. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13702. {
  13703. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13704. }
  13705. }
  13706. }
  13707. else if(gunType[gun_index] == 'G')
  13708. {
  13709. for (int index = 0; index < GB_QUANTITY; index++)
  13710. {
  13711. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13712. {
  13713. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13714. }
  13715. }
  13716. }
  13717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13723. } // END FOR DC CASE
  13724. //2.6====================================== Current.Import L2 ==============================================
  13725. // idx_sample=6;
  13726. // AC 3 phase L2 current
  13727. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13728. {
  13729. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13730. {
  13731. tempIndex = 2;
  13732. }
  13733. else
  13734. {
  13735. tempIndex = gun_index;
  13736. }
  13737. for (int index = 0; index < AC_QUANTITY; index++)
  13738. {
  13739. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13740. {
  13741. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13742. }
  13743. }// End of for AC_QUANTITY
  13744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13745. }
  13746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13751. //2.7====================================== Current.Import L3 ==============================================
  13752. // idx_sample=7;
  13753. // AC 3 phase L3 current
  13754. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13755. {
  13756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13757. {
  13758. tempIndex = 2;
  13759. }
  13760. else
  13761. {
  13762. tempIndex = gun_index;
  13763. }
  13764. for (int index = 0; index < AC_QUANTITY; index++)
  13765. {
  13766. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13767. {
  13768. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13769. }
  13770. }// End of for AC_QUANTITY
  13771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13772. }
  13773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13778. //2.9====================================== Voltage L2 ====================================================
  13779. //idx_sample=8;
  13780. // AC 3 phase L2 volatge
  13781. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13782. {
  13783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13784. {
  13785. tempIndex = 2;
  13786. }
  13787. else
  13788. {
  13789. tempIndex = gun_index;
  13790. }
  13791. for (int index = 0; index < AC_QUANTITY; index++)
  13792. {
  13793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13794. {
  13795. 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
  13796. }
  13797. } // END OF FOR AC_QUANTITY
  13798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13799. }
  13800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13805. //2.10====================================== Voltage L3 ====================================================
  13806. //idx_sample=9;
  13807. // AC 3 phase L3 volatge
  13808. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13809. {
  13810. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13811. {
  13812. tempIndex = 2;
  13813. }
  13814. else
  13815. {
  13816. tempIndex = gun_index;
  13817. }
  13818. for (int index = 0; index < AC_QUANTITY; index++)
  13819. {
  13820. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13821. {
  13822. 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
  13823. }
  13824. } // END OF FOR AC_QUANTITY
  13825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13826. }
  13827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13830. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13832. //======================================== Message create ==============================================
  13833. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13834. {
  13835. 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\"}]}]}]"
  13836. ,gun_index+1
  13837. ,MESSAGE_TYPE_CALL
  13838. ,guid
  13839. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13840. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13841. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13843. ,"PowerLoss"
  13844. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13887. );
  13888. }
  13889. else
  13890. {
  13891. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13892. {
  13893. 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\"}]}]}]"
  13894. ,gun_index+1
  13895. ,MESSAGE_TYPE_CALL
  13896. ,guid
  13897. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13898. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13899. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13901. ,"PowerLoss"
  13902. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13938. );
  13939. }
  13940. else
  13941. {
  13942. 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\"}]}]}]"
  13943. ,gun_index+1
  13944. ,MESSAGE_TYPE_CALL
  13945. ,guid
  13946. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13947. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13948. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13950. ,"PowerLoss"
  13951. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  13988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  13989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  13990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  13991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  13992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  13993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  13994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  13995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  13996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  13997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  13998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  13999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  14000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  14001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  14002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  14003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  14004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  14005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  14006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  14007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  14008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  14009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  14010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  14011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  14012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  14013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  14014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  14015. );
  14016. }
  14017. }
  14018. // Check File "TempStopTransaction" Exist
  14019. if((access(TempStopTransaction,F_OK))!=-1)
  14020. {
  14021. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14022. fclose(fopen(TempStopTransaction, "w"));
  14023. }
  14024. else
  14025. {
  14026. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14027. FILE *log = fopen(TempStopTransaction, "w+");
  14028. if(log == NULL)
  14029. {
  14030. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14031. return ;
  14032. }
  14033. else
  14034. {
  14035. fclose(log);
  14036. }
  14037. }
  14038. //Add TempStopTransaction | Update TempStopTransaction
  14039. // open file for writing
  14040. FILE *outfile;
  14041. outfile = fopen (TempStopTransaction, "a");
  14042. //DEBUG_INFO("data = %s\n", queuedata);
  14043. fputs(queuedata, outfile);
  14044. fputs("\n", outfile);
  14045. fclose (outfile);
  14046. }
  14047. void checkTempStopTransaction(int gun_index)
  14048. {
  14049. FILE *fptr1;
  14050. char ch;
  14051. char str[QUEUE_MESSAGE_LENGTH]={0};
  14052. char guid[37]={0};
  14053. char tempdata[65]={0};
  14054. char connectorStr[2]={0};
  14055. char TempStopTransaction[256];
  14056. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14057. fptr1 = fopen(TempStopTransaction, "r");
  14058. //TempStopTransaction格式: 槍號,StopTransaction封包
  14059. if (!fptr1)
  14060. {
  14061. //printf(" File not found or unable to open the input file!!\n");
  14062. return ;
  14063. }
  14064. ch=fgetc(fptr1);
  14065. //printf(" Now the content of the file %s is : \n",fname);
  14066. rewind(fptr1);
  14067. if(ch!=EOF)
  14068. {
  14069. // copy all contents to the temporary file except the specific line
  14070. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14071. {
  14072. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14073. if(str[0]=='\0')
  14074. {
  14075. break;
  14076. }
  14077. //TempStopTransaction格式: 槍號,StopTransaction封包
  14078. strncpy(connectorStr, str, 1);
  14079. if(atoi(connectorStr) != (gun_index+1))
  14080. {
  14081. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14082. fclose(fptr1);
  14083. return ;
  14084. }
  14085. //random_uuid(guid);
  14086. strncpy(guid, str+6, 36); //copy guid
  14087. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14088. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14089. {
  14090. DEBUG_INFO("StopTransaction mapitem pass\n");
  14091. }
  14092. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14093. memset(str,0,ARRAY_SIZE(str));
  14094. }
  14095. }
  14096. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14097. fclose(fptr1);
  14098. remove(TempStopTransaction); // remove the original file
  14099. }
  14100. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14101. {
  14102. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14103. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14104. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14105. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14106. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14107. }
  14108. int GetWebSocketPingInterval(void)
  14109. {
  14110. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14111. }
  14112. int GetServerSign(void)
  14113. {
  14114. return server_sign;
  14115. }
  14116. uint8_t GetOcppSecurityProfile()
  14117. {
  14118. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14119. }
  14120. void GetOcppChargerBoxId(uint8_t *data)
  14121. {
  14122. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14123. }
  14124. void GetOcppSecurityPassword(uint8_t *data)
  14125. {
  14126. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14127. }
  14128. void SetServerSign(int value)
  14129. {
  14130. server_sign = value;
  14131. }
  14132. int GetBootNotificationInterval(void)
  14133. {
  14134. return BootNotificationInterval;
  14135. }
  14136. int GetInternetConn(void)
  14137. {
  14138. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14139. }
  14140. void InitialSystemValue(void)
  14141. {
  14142. int connectorIndex = 0;
  14143. //int valueASCII = 0;
  14144. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14145. gunTotalNumber=0;
  14146. SystemInitial = 0;
  14147. localversion=0;
  14148. BootNotificationInterval = 0;
  14149. authorizeRetryTimes = 0;
  14150. GunStatusInterval = 10;
  14151. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14152. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14153. //Hear Beat
  14154. HeartBeatWithNOResponse = 0;
  14155. HeartBeatCountPerHour = 0;
  14156. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14157. FirstHeartBeat = 0;
  14158. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14159. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14160. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14161. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14162. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14163. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14164. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14165. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14166. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14167. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14168. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14169. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14170. memset(gunType, 0, ARRAY_SIZE(gunType));
  14171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14172. {
  14173. //check connector / socket type (index: 8, 9, 10)
  14174. for(int index=7; index <10 ; index++)
  14175. {
  14176. if(index != 8)
  14177. {
  14178. // DC Connector
  14179. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14180. {
  14181. SystemInitial = SystemInitial + 1;
  14182. gunTotalNumber = gunTotalNumber + 1;
  14183. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14184. connectorIndex = connectorIndex + 1;
  14185. }
  14186. }
  14187. else
  14188. {
  14189. // AC Connector
  14190. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14191. {
  14192. SystemInitial = SystemInitial + 1;
  14193. gunTotalNumber = gunTotalNumber + 1;
  14194. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14195. connectorIndex = connectorIndex + 1;
  14196. }
  14197. }
  14198. }
  14199. //DEBUG_INFO("DC ...\n");
  14200. }
  14201. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14202. {
  14203. //check connector / socket type (index: 8, 9, 10)
  14204. for(int index=7; index <10 ; index++)
  14205. {
  14206. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14207. {
  14208. SystemInitial = SystemInitial + 1;
  14209. gunTotalNumber = gunTotalNumber + 1;
  14210. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14211. connectorIndex = connectorIndex + 1;
  14212. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14213. }
  14214. }
  14215. }
  14216. //Status && ConnectorPlugIn Setting
  14217. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14218. {
  14219. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14220. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14221. }
  14222. for (int index = 0; index < CCS_QUANTITY; index++)
  14223. {
  14224. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14225. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14226. }
  14227. for (int index = 0; index < GB_QUANTITY; index++)
  14228. {
  14229. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14230. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14231. }
  14232. for (int index = 0; index < AC_QUANTITY; index++)
  14233. {
  14234. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14235. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14236. }
  14237. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14238. {
  14239. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14240. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14241. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14242. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14243. }
  14244. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14245. clientTime.Heartbeat=time((time_t*)NULL);
  14246. sleep(1);
  14247. }
  14248. void LWS_Send(char * str)
  14249. {
  14250. //=====================================================
  14251. // Check InternetConn 0: disconnected, 1: connected
  14252. //====================================================
  14253. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14254. {
  14255. DEBUG_INFO("offline now !!!\n");
  14256. return;
  14257. }
  14258. pthread_mutex_lock(&lock_send);
  14259. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14260. sprintf((char *)SendBuffer, "%s", str);
  14261. SendBufLen = strlen(str);
  14262. pthread_mutex_unlock(&lock_send);
  14263. lws_callback_on_writable(wsi_client);
  14264. //lws_service(context, 0);
  14265. //sleep(1);
  14266. }
  14267. void LWS_SendNow(char * str)
  14268. {
  14269. //=====================================================
  14270. // Check InternetConn 0: disconnected, 1: connected
  14271. //====================================================
  14272. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14273. {
  14274. DEBUG_INFO("offline now !!!\n");
  14275. return;
  14276. }
  14277. pthread_mutex_lock(&lock_send);
  14278. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14279. sprintf((char *)SendBuffer, "%s", str);
  14280. SendBufLen = strlen(str);
  14281. pthread_mutex_unlock(&lock_send);
  14282. lws_callback_on_writable(wsi_client);
  14283. lws_service(context, 0);
  14284. //sleep(1);
  14285. }