MessageHandler.c 700 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698
  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. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknownkey
  21. //===============================
  22. static char unknownkey[10][20] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int localversion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[20];
  75. char parentIdTag[20];
  76. char expiryDate[30];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //==========================================
  354. // Check time passed since today
  355. //==========================================
  356. long long DiffTimebWithNow(struct timeb ST)
  357. {
  358. //return milli-second
  359. struct timeb ET;
  360. long long StartTime,StopTime;
  361. ftime(&ET);
  362. StartTime=(long long)ST.time;
  363. StopTime=(long long)ET.time;
  364. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  365. }
  366. int getTimePassSinceToday()
  367. {
  368. int result = -1;
  369. static time_t lastTime;
  370. time_t t;
  371. struct tm *tmStartToday;
  372. struct timeb tbStartToday;
  373. t=time(NULL);
  374. if(difftime(t, lastTime)>0)
  375. {
  376. tmStartToday=localtime(&t);
  377. tmStartToday->tm_hour = 0;
  378. tmStartToday->tm_min = 0;
  379. tmStartToday->tm_sec = 0;
  380. tbStartToday.time = mktime(tmStartToday);
  381. tbStartToday.millitm = 0;
  382. result = DiffTimebWithNow(tbStartToday)/1000;
  383. lastTime = t;
  384. }
  385. return result;
  386. }
  387. void getNowDatetime(uint8_t *data)
  388. {
  389. time_t t = time(NULL);
  390. struct tm tm = *localtime(&t);
  391. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  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 = NO;
  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. else
  458. result = YES;
  459. }
  460. else
  461. {
  462. DEBUG_WARN("Start date parsing error.\n");
  463. }
  464. return result;
  465. }
  466. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  467. {
  468. int result = -1;
  469. struct tm tmStart;
  470. struct timeb tbStart;
  471. struct tm tmStop;
  472. struct timeb tbStop;
  473. 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) &&
  474. (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))
  475. {
  476. tmStart.tm_year -= 1900;
  477. tmStart.tm_mon -= 1;
  478. tbStart.time = mktime(&tmStart);
  479. tbStart.millitm = 0;
  480. tmStop.tm_year -= 1900;
  481. tmStop.tm_mon -= 1;
  482. tbStop.time = mktime(&tmStop);
  483. tbStop.millitm = 0;
  484. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  485. }
  486. return result;
  487. }
  488. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  489. {
  490. FILE *fp;
  491. char profileFileName[128];
  492. char *line = NULL;
  493. size_t len = 0;
  494. time_t CurrentTime;
  495. struct tm *tmComposite;
  496. struct StructChargingProfile maxProfile;
  497. struct StructChargingProfile defaultTxProfile;
  498. struct StructChargingProfile txProfile;
  499. struct StructChargingSchedulePeriod tmpPeriod;
  500. uint8_t limitMax=0;
  501. uint8_t limitDef=0;
  502. uint8_t limitTx=0;
  503. int compositePeriodIdx = 0;
  504. CurrentTime = time(NULL);
  505. tmComposite=localtime(&CurrentTime);
  506. 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);
  507. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  508. compositeProfile->ChargingSchedule.Duration = durationReq;
  509. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  510. {
  511. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  512. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  513. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  514. }
  515. compositeProfile->ChargingProfileId = 0;
  516. compositeProfile->StackLevel = 99 ;
  517. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  518. maxProfile.ChargingProfileId = -1;
  519. defaultTxProfile.ChargingProfileId = -1;
  520. txProfile.ChargingProfileId = -1;
  521. maxProfile.ChargingSchedule.Duration = -1;
  522. defaultTxProfile.ChargingSchedule.Duration = -1;
  523. txProfile.ChargingSchedule.Duration = -1;
  524. system("yes|rm /tmp/*.json");
  525. system("cp /Storage/OCPP/*.json /tmp");
  526. /*
  527. * Search valid charging profile
  528. */
  529. //DEBUG_INFO("====================================\n");
  530. // Search tx profile
  531. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  532. if((access(profileFileName, F_OK))!=-1)
  533. {
  534. fp = fopen(profileFileName, "r");
  535. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  536. {
  537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  538. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  539. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  540. }
  541. txProfile.ChargingProfileId = -1;
  542. txProfile.StackLevel = -1;
  543. while(getline(&line, &len, fp) != -1)
  544. {
  545. json_object *obj = NULL;
  546. obj = json_tokener_parse(line);
  547. if(is_error(obj))
  548. {
  549. DEBUG_ERROR("Parse txProfile from file error.\n");
  550. }
  551. else
  552. {
  553. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  554. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  555. )
  556. {
  557. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  558. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  559. )
  560. {
  561. struct tm tmFrom, tmTo;
  562. struct timeb tbFrom, tbTo;
  563. 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) &&
  564. (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))
  565. {
  566. tmFrom.tm_year -= 1900;
  567. tmFrom.tm_mon -= 1;
  568. tbFrom.time = mktime(&tmFrom);
  569. tmTo.tm_year -= 1900;
  570. tmTo.tm_mon -= 1;
  571. tbTo.time = mktime(&tmTo);
  572. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  573. {
  574. if(txProfile.ChargingProfileId == -1)
  575. DEBUG_INFO("TxProfile found.\n");
  576. else
  577. DEBUG_INFO("TxProfile updated.\n");
  578. // Required item
  579. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  580. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  581. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  582. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  583. 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++)
  584. {
  585. 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"));
  586. 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?
  587. 3:
  588. 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")));
  589. 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*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  590. }
  591. // Optional item
  592. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  593. {
  594. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  595. }
  596. else
  597. {
  598. sprintf((char*)txProfile.ValidFrom, " ");
  599. }
  600. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  601. {
  602. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  603. }
  604. else
  605. {
  606. sprintf((char*)txProfile.ValidTo, " ");
  607. }
  608. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  609. {
  610. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  611. }
  612. else
  613. {
  614. sprintf((char*)txProfile.RecurrencyKind, " ");
  615. }
  616. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  617. {
  618. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  619. }
  620. else
  621. {
  622. txProfile.TransactionId = -1;
  623. }
  624. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  625. {
  626. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  627. }
  628. else
  629. {
  630. txProfile.ChargingSchedule.Duration = 86400;
  631. }
  632. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  633. {
  634. 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")));
  635. }
  636. else
  637. {
  638. 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));
  639. }
  640. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  641. {
  642. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  643. }
  644. else
  645. {
  646. txProfile.ChargingSchedule.MinChargingRate = -1;
  647. }
  648. }
  649. }
  650. }
  651. else
  652. {
  653. if(txProfile.ChargingProfileId == -1)
  654. DEBUG_INFO("TxProfile found.\n");
  655. else
  656. DEBUG_INFO("TxProfile updated.\n");
  657. // Required item
  658. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  659. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  660. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  661. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  662. 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++)
  663. {
  664. 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"));
  665. 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?
  666. 3:
  667. 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")));
  668. 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*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  669. }
  670. // Optional item
  671. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  672. {
  673. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  674. }
  675. else
  676. {
  677. sprintf((char*)txProfile.ValidFrom, " ");
  678. }
  679. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  680. {
  681. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  682. }
  683. else
  684. {
  685. sprintf((char*)txProfile.ValidTo, " ");
  686. }
  687. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  688. {
  689. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  690. }
  691. else
  692. {
  693. sprintf((char*)txProfile.RecurrencyKind, " ");
  694. }
  695. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  696. {
  697. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  698. }
  699. else
  700. {
  701. txProfile.TransactionId = -1;
  702. }
  703. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  704. {
  705. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  706. }
  707. else
  708. {
  709. txProfile.ChargingSchedule.Duration = 86400;
  710. }
  711. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  712. {
  713. 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")));
  714. }
  715. else
  716. {
  717. 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));
  718. }
  719. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  720. {
  721. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  722. }
  723. else
  724. {
  725. txProfile.ChargingSchedule.MinChargingRate = -1;
  726. }
  727. }
  728. }
  729. }
  730. json_object_put(obj);
  731. }
  732. fclose(fp);
  733. /*
  734. if(txProfile.ChargingProfileId != -1)
  735. {
  736. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  737. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  738. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  739. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  740. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  741. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  742. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  743. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  744. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  745. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  746. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  747. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  748. {
  749. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  750. {
  751. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  752. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  753. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  754. }
  755. }
  756. }
  757. else
  758. DEBUG_INFO("TxProfile not found.\n");*/
  759. }
  760. // Search default tx profile
  761. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  762. if((access(profileFileName, F_OK))==-1)
  763. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  764. if((access(profileFileName, F_OK))!=-1)
  765. {
  766. fp = fopen(profileFileName, "r");
  767. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  768. {
  769. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  770. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  771. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  772. }
  773. defaultTxProfile.ChargingProfileId = -1;
  774. defaultTxProfile.StackLevel = -1;
  775. while(getline(&line, &len, fp) != -1)
  776. {
  777. json_object *obj = NULL;
  778. obj = json_tokener_parse(line);
  779. if(is_error(obj))
  780. {
  781. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  782. }
  783. else
  784. {
  785. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  786. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  787. )
  788. {
  789. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  790. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  791. )
  792. {
  793. struct tm tmFrom, tmTo;
  794. struct timeb tbFrom, tbTo;
  795. 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) &&
  796. (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))
  797. {
  798. tmFrom.tm_year -= 1900;
  799. tmFrom.tm_mon -= 1;
  800. tbFrom.time = mktime(&tmFrom);
  801. tmTo.tm_year -= 1900;
  802. tmTo.tm_mon -= 1;
  803. tbTo.time = mktime(&tmTo);
  804. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  805. {
  806. if(defaultTxProfile.ChargingProfileId == -1)
  807. DEBUG_INFO("TxDefaultProfile found.\n");
  808. else
  809. DEBUG_INFO("TxDefaultProfile updated.\n");
  810. // Required item
  811. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  812. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  813. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  814. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  815. 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++)
  816. {
  817. 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"));
  818. 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?
  819. 3:
  820. 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")));
  821. 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*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  822. }
  823. // Optional item
  824. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  825. {
  826. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  827. }
  828. else
  829. {
  830. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  831. }
  832. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  833. {
  834. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  835. }
  836. else
  837. {
  838. sprintf((char*)defaultTxProfile.ValidTo, " ");
  839. }
  840. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  841. {
  842. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  843. }
  844. else
  845. {
  846. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  847. }
  848. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  849. {
  850. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  851. }
  852. else
  853. {
  854. defaultTxProfile.TransactionId = -1;
  855. }
  856. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  857. {
  858. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  859. }
  860. else
  861. {
  862. defaultTxProfile.ChargingSchedule.Duration = 86400;
  863. }
  864. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  865. {
  866. 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")));
  867. }
  868. else
  869. {
  870. 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));
  871. }
  872. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  873. {
  874. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  875. }
  876. else
  877. {
  878. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  879. }
  880. }
  881. }
  882. }
  883. else
  884. {
  885. if(defaultTxProfile.ChargingProfileId == -1)
  886. DEBUG_INFO("TxDefaultProfile found.\n");
  887. else
  888. DEBUG_INFO("TxDefaultProfile updated.\n");
  889. // Required item
  890. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  891. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  892. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  893. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  894. 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++)
  895. {
  896. 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"));
  897. 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?
  898. 3:
  899. 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")));
  900. 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*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  901. }
  902. // Optional item
  903. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  904. {
  905. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  906. }
  907. else
  908. {
  909. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  910. }
  911. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  912. {
  913. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  914. }
  915. else
  916. {
  917. sprintf((char*)defaultTxProfile.ValidTo, " ");
  918. }
  919. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  920. {
  921. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  922. }
  923. else
  924. {
  925. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  926. }
  927. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  928. {
  929. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  930. }
  931. else
  932. {
  933. defaultTxProfile.TransactionId = -1;
  934. }
  935. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  936. {
  937. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  938. }
  939. else
  940. {
  941. defaultTxProfile.ChargingSchedule.Duration = 86400;
  942. }
  943. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  944. {
  945. 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")));
  946. }
  947. else
  948. {
  949. 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));
  950. }
  951. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  952. {
  953. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  954. }
  955. else
  956. {
  957. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  958. }
  959. }
  960. }
  961. }
  962. json_object_put(obj);
  963. }
  964. fclose(fp);
  965. /*
  966. if(defaultTxProfile.ChargingProfileId != -1)
  967. {
  968. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  969. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  970. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  971. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  972. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  973. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  974. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  975. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  976. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  977. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  978. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  979. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  980. {
  981. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  982. {
  983. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  984. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  985. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  986. }
  987. }
  988. }
  989. else
  990. DEBUG_INFO("TxDefaultProfile not found.\n");
  991. DEBUG_INFO("------------------------------------\n");*/
  992. }
  993. // Search max profile
  994. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  995. if((access(profileFileName, F_OK))!=-1)
  996. {
  997. fp = fopen(profileFileName, "r");
  998. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  999. {
  1000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1001. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1002. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1003. }
  1004. maxProfile.ChargingProfileId = -1;
  1005. maxProfile.StackLevel = -1;
  1006. while(getline(&line, &len, fp) != -1)
  1007. {
  1008. json_object *obj = NULL;
  1009. obj = json_tokener_parse(line);
  1010. if(is_error(obj))
  1011. {
  1012. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1013. }
  1014. else
  1015. {
  1016. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1017. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1018. )
  1019. {
  1020. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1021. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1022. )
  1023. {
  1024. struct tm tmFrom, tmTo;
  1025. struct timeb tbFrom, tbTo;
  1026. 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) &&
  1027. (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))
  1028. {
  1029. tmFrom.tm_year -= 1900;
  1030. tmFrom.tm_mon -= 1;
  1031. tbFrom.time = mktime(&tmFrom);
  1032. tmTo.tm_year -= 1900;
  1033. tmTo.tm_mon -= 1;
  1034. tbTo.time = mktime(&tmTo);
  1035. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1036. {
  1037. if(maxProfile.ChargingProfileId == -1)
  1038. DEBUG_INFO("MaxProfile found.\n");
  1039. else
  1040. DEBUG_INFO("MaxProfile updated.\n");
  1041. // Required item
  1042. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1043. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1044. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1045. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1046. 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++)
  1047. {
  1048. 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"));
  1049. 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?
  1050. 3:
  1051. 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")));
  1052. 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*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  1053. }
  1054. // Optional item
  1055. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1056. {
  1057. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1058. }
  1059. else
  1060. {
  1061. sprintf((char*)maxProfile.ValidFrom, " ");
  1062. }
  1063. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1064. {
  1065. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1066. }
  1067. else
  1068. {
  1069. sprintf((char*)maxProfile.ValidTo, " ");
  1070. }
  1071. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1072. {
  1073. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1074. }
  1075. else
  1076. {
  1077. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1078. }
  1079. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1080. {
  1081. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1082. }
  1083. else
  1084. {
  1085. maxProfile.TransactionId = -1;
  1086. }
  1087. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1088. {
  1089. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1090. }
  1091. else
  1092. {
  1093. maxProfile.ChargingSchedule.Duration = 86400;
  1094. }
  1095. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1096. {
  1097. 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")));
  1098. }
  1099. else
  1100. {
  1101. 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));
  1102. }
  1103. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1104. {
  1105. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1106. }
  1107. else
  1108. {
  1109. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1110. }
  1111. }
  1112. }
  1113. }
  1114. else
  1115. {
  1116. if(maxProfile.ChargingProfileId == -1)
  1117. DEBUG_INFO("MaxProfile found.\n");
  1118. else
  1119. DEBUG_INFO("MaxProfile updated.\n");
  1120. // Required item
  1121. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1122. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1123. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1124. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1125. 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++)
  1126. {
  1127. 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"));
  1128. 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?
  1129. 3:
  1130. 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")));
  1131. 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*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  1132. }
  1133. // Optional item
  1134. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1135. {
  1136. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1137. }
  1138. else
  1139. {
  1140. sprintf((char*)maxProfile.ValidFrom, " ");
  1141. }
  1142. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1143. {
  1144. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1145. }
  1146. else
  1147. {
  1148. sprintf((char*)maxProfile.ValidTo, " ");
  1149. }
  1150. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1151. {
  1152. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1153. }
  1154. else
  1155. {
  1156. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1157. }
  1158. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1159. {
  1160. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1161. }
  1162. else
  1163. {
  1164. maxProfile.TransactionId = -1;
  1165. }
  1166. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1167. {
  1168. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1169. }
  1170. else
  1171. {
  1172. maxProfile.ChargingSchedule.Duration = 86400;
  1173. }
  1174. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1175. {
  1176. 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")));
  1177. }
  1178. else
  1179. {
  1180. 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));
  1181. }
  1182. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1183. {
  1184. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1185. }
  1186. else
  1187. {
  1188. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1189. }
  1190. }
  1191. }
  1192. }
  1193. json_object_put(obj);
  1194. }
  1195. fclose(fp);
  1196. /*
  1197. if(maxProfile.ChargingProfileId !=-1)
  1198. {
  1199. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1200. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1201. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1202. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1203. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1204. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1205. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1206. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1207. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1208. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1209. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1210. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1211. {
  1212. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1213. {
  1214. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1215. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1216. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1217. }
  1218. }
  1219. }
  1220. else
  1221. DEBUG_INFO("MaxProfile not found.\n");
  1222. DEBUG_INFO("------------------------------------\n");*/
  1223. }
  1224. /*
  1225. * Align found profile start schedule & periods
  1226. */
  1227. //DEBUG_INFO("====================================\n");
  1228. /*
  1229. // For local test usage, force modify found profile start schedule info
  1230. 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);
  1231. 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);
  1232. 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);
  1233. */
  1234. if(txProfile.ChargingProfileId != -1)
  1235. {
  1236. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1237. {
  1238. if(txProfile.ChargingSchedule.Duration != -1)
  1239. {
  1240. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1241. 0:
  1242. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1243. }
  1244. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1245. {
  1246. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1247. {
  1248. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1249. 0:
  1250. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1251. if(idxPeriod > 0)
  1252. {
  1253. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1254. {
  1255. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1256. }
  1257. }
  1258. }
  1259. }
  1260. }
  1261. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1262. {
  1263. if(txProfile.ChargingSchedule.Duration != -1)
  1264. {
  1265. 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?
  1266. 0:
  1267. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1268. }
  1269. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1270. {
  1271. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1272. {
  1273. 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?
  1274. 0:
  1275. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1276. if(idxPeriod > 0)
  1277. {
  1278. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1279. {
  1280. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1281. }
  1282. }
  1283. }
  1284. }
  1285. }
  1286. else
  1287. {
  1288. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1289. {
  1290. if(txProfile.ChargingSchedule.Duration != -1)
  1291. {
  1292. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1293. 0:
  1294. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1295. }
  1296. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1297. {
  1298. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1299. {
  1300. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1301. 0:
  1302. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1303. if(idxPeriod > 0)
  1304. {
  1305. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1306. {
  1307. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1308. }
  1309. }
  1310. }
  1311. }
  1312. }
  1313. else
  1314. {
  1315. if(txProfile.ChargingSchedule.Duration != -1)
  1316. {
  1317. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1318. 0:
  1319. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1320. }
  1321. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1322. {
  1323. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1324. {
  1325. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1326. 0:
  1327. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1328. if(idxPeriod > 0)
  1329. {
  1330. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1331. {
  1332. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1333. }
  1334. }
  1335. }
  1336. }
  1337. }
  1338. }
  1339. /*
  1340. DEBUG_INFO("txProfile after align.\n");
  1341. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1342. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1343. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1344. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1345. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1346. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1347. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1348. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1349. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1350. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1351. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1352. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1353. {
  1354. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1355. {
  1356. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1357. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1358. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1359. }
  1360. }*/
  1361. }
  1362. if(defaultTxProfile.ChargingProfileId != -1)
  1363. {
  1364. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1365. {
  1366. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1367. {
  1368. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1369. 0:
  1370. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1371. }
  1372. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1373. {
  1374. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1375. {
  1376. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1377. 0:
  1378. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1379. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1380. {
  1381. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1382. }
  1383. if(idxPeriod > 0)
  1384. {
  1385. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1386. {
  1387. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1388. }
  1389. }
  1390. }
  1391. }
  1392. }
  1393. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1394. {
  1395. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1396. {
  1397. 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?
  1398. 0:
  1399. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1400. }
  1401. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1402. {
  1403. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1404. {
  1405. 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?
  1406. 0:
  1407. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1408. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1409. {
  1410. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1411. }
  1412. if(idxPeriod > 0)
  1413. {
  1414. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1415. {
  1416. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1417. }
  1418. }
  1419. }
  1420. }
  1421. }
  1422. else
  1423. {
  1424. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1425. {
  1426. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1427. {
  1428. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1429. 0:
  1430. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1431. }
  1432. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1433. {
  1434. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1435. {
  1436. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1437. 0:
  1438. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1439. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1440. {
  1441. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1442. }
  1443. if(idxPeriod > 0)
  1444. {
  1445. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1446. {
  1447. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. else
  1454. {
  1455. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1456. {
  1457. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1458. 0:
  1459. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1460. }
  1461. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1462. {
  1463. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1464. {
  1465. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1466. 0:
  1467. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1468. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1469. {
  1470. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1471. }
  1472. if(idxPeriod > 0)
  1473. {
  1474. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1475. {
  1476. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1477. }
  1478. }
  1479. }
  1480. }
  1481. }
  1482. }
  1483. /*
  1484. DEBUG_INFO("defaultTxProfile after align.\n");
  1485. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1486. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1487. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1488. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1489. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1490. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1491. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1492. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1493. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1494. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1495. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1496. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1497. {
  1498. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1499. {
  1500. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1501. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1502. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1503. }
  1504. }
  1505. DEBUG_INFO("------------------------------------\n");*/
  1506. }
  1507. if(maxProfile.ChargingProfileId != -1)
  1508. {
  1509. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1510. {
  1511. if(maxProfile.ChargingSchedule.Duration != -1)
  1512. {
  1513. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1514. 0:
  1515. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1516. }
  1517. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1518. {
  1519. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1520. {
  1521. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1522. 0:
  1523. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1524. if(idxPeriod > 0)
  1525. {
  1526. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1527. {
  1528. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1529. }
  1530. }
  1531. }
  1532. }
  1533. }
  1534. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1535. {
  1536. if(maxProfile.ChargingSchedule.Duration != -1)
  1537. {
  1538. 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?
  1539. 0:
  1540. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1541. }
  1542. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1543. {
  1544. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1545. {
  1546. 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?
  1547. 0:
  1548. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1549. if(idxPeriod > 0)
  1550. {
  1551. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1552. {
  1553. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1554. }
  1555. }
  1556. }
  1557. }
  1558. }
  1559. else
  1560. {
  1561. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1562. {
  1563. if(maxProfile.ChargingSchedule.Duration != -1)
  1564. {
  1565. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1566. 0:
  1567. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1568. }
  1569. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1570. {
  1571. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1572. {
  1573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1574. 0:
  1575. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1576. if(idxPeriod > 0)
  1577. {
  1578. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1579. {
  1580. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1581. }
  1582. }
  1583. }
  1584. }
  1585. }
  1586. else
  1587. {
  1588. if(maxProfile.ChargingSchedule.Duration != -1)
  1589. {
  1590. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1591. 0:
  1592. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1593. }
  1594. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1595. {
  1596. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1597. {
  1598. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1599. 0:
  1600. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1601. if(idxPeriod > 0)
  1602. {
  1603. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1604. {
  1605. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1606. }
  1607. }
  1608. }
  1609. }
  1610. }
  1611. }
  1612. /*
  1613. DEBUG_INFO("MaxProfile after align.\n");
  1614. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1615. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1616. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1617. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1618. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1619. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1620. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1621. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1622. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1623. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1624. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1626. {
  1627. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1628. {
  1629. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1630. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1631. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1632. }
  1633. }
  1634. DEBUG_INFO("------------------------------------\n");*/
  1635. }
  1636. /*
  1637. * Merge to conposite schedule
  1638. */
  1639. //DEBUG_INFO("====================================\n");
  1640. // Find each profile period quantity
  1641. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1642. {
  1643. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1644. limitMax = idx+1;
  1645. }
  1646. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1647. {
  1648. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1649. limitDef = idx+1;
  1650. }
  1651. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1652. {
  1653. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1654. limitTx = idx+1;
  1655. }
  1656. // TxProfile found, composite schedule based on it
  1657. if(txProfile.ChargingProfileId != -1)
  1658. {
  1659. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1660. {
  1661. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1662. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1663. (txProfile.ChargingSchedule.Duration > 0))
  1664. {
  1665. if(maxProfile.ChargingProfileId != -1)
  1666. {
  1667. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1668. {
  1669. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1670. {
  1671. if((maxProfile.ChargingSchedule.Duration > 0))
  1672. {
  1673. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1674. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1675. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1676. }
  1677. else
  1678. {
  1679. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1680. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1681. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1682. }
  1683. }
  1684. if(idxMaxPeriod == (limitMax-1))
  1685. {
  1686. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1687. {
  1688. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1689. {
  1690. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1691. compositePeriodIdx++;
  1692. }
  1693. else
  1694. {
  1695. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1696. }
  1697. }
  1698. }
  1699. }
  1700. }
  1701. else
  1702. {
  1703. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1704. {
  1705. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1706. compositePeriodIdx++;
  1707. }
  1708. else
  1709. {
  1710. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1711. }
  1712. }
  1713. }
  1714. if(idxTxPeriod == (limitTx-1))
  1715. {
  1716. if(defaultTxProfile.ChargingProfileId != -1)
  1717. {
  1718. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1719. {
  1720. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1721. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1722. (defaultTxProfile.ChargingSchedule.Duration>0))
  1723. {
  1724. if(maxProfile.ChargingProfileId != -1)
  1725. {
  1726. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1727. {
  1728. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1729. {
  1730. if((maxProfile.ChargingSchedule.Duration > 0))
  1731. {
  1732. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1733. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1734. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1735. }
  1736. else
  1737. {
  1738. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1739. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1740. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1741. }
  1742. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1743. {
  1744. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1745. {
  1746. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1747. compositePeriodIdx++;
  1748. }
  1749. else
  1750. {
  1751. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1752. }
  1753. }
  1754. break;
  1755. }
  1756. }
  1757. }
  1758. else
  1759. {
  1760. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1761. {
  1762. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1763. compositePeriodIdx++;
  1764. }
  1765. else
  1766. {
  1767. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1768. }
  1769. }
  1770. }
  1771. }
  1772. }
  1773. }
  1774. }
  1775. }
  1776. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1777. else if(defaultTxProfile.ChargingProfileId != -1)
  1778. {
  1779. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1780. {
  1781. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1782. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1783. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1784. {
  1785. if(maxProfile.ChargingProfileId != -1)
  1786. {
  1787. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1788. {
  1789. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1790. {
  1791. if((maxProfile.ChargingSchedule.Duration > 0))
  1792. {
  1793. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1794. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1795. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1796. }
  1797. else
  1798. {
  1799. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1800. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1801. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1802. }
  1803. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1804. {
  1805. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1806. {
  1807. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1808. compositePeriodIdx++;
  1809. }
  1810. else
  1811. {
  1812. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1813. }
  1814. }
  1815. break;
  1816. }
  1817. }
  1818. }
  1819. else
  1820. {
  1821. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1822. {
  1823. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1824. compositePeriodIdx++;
  1825. }
  1826. else
  1827. {
  1828. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1829. }
  1830. }
  1831. }
  1832. }
  1833. }
  1834. // Fill other period by MaxProfile
  1835. if(maxProfile.ChargingProfileId != -1)
  1836. {
  1837. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1838. {
  1839. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1840. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1841. (maxProfile.ChargingSchedule.Duration > 0))
  1842. {
  1843. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1844. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1845. {
  1846. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1847. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1848. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1849. }
  1850. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1851. {
  1852. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1853. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1854. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1855. }
  1856. if(tmpPeriod.Limit != -1)
  1857. {
  1858. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1859. {
  1860. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1861. {
  1862. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1863. compositePeriodIdx++;
  1864. }
  1865. else
  1866. {
  1867. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  1875. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1876. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1877. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1878. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1879. {
  1880. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1881. {
  1882. compositeProfile->ChargingProfileId = 1;
  1883. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1884. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1885. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1886. }
  1887. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1888. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1889. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1890. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1891. }
  1892. if(line)
  1893. free(line);
  1894. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  1895. }
  1896. //==========================================
  1897. // Init all share memory
  1898. //==========================================
  1899. int InitShareMemory()
  1900. {
  1901. int result = PASS;
  1902. int MeterSMId;
  1903. //creat ShmSysConfigAndInfo
  1904. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1905. {
  1906. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1907. result = FAIL;
  1908. }
  1909. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1910. {
  1911. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1912. result = FAIL;
  1913. }
  1914. else
  1915. {}
  1916. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1917. {
  1918. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1919. result = FAIL;
  1920. }
  1921. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1922. {
  1923. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1924. result = FAIL;
  1925. }
  1926. else
  1927. {}
  1928. //creat ShmPsuData
  1929. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1930. {
  1931. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1932. result = FAIL;
  1933. }
  1934. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1935. {
  1936. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1937. result = FAIL;
  1938. }
  1939. else
  1940. {}
  1941. //creat ShmOCPP16Data
  1942. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1943. {
  1944. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  1945. result = FAIL;
  1946. }
  1947. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1948. {
  1949. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  1950. result = FAIL;
  1951. }
  1952. else
  1953. {}
  1954. /****************************** For Initial Settings************************************************/
  1955. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1956. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1957. // allocate Configuration memory address
  1958. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1959. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1960. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1961. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1962. //offline MeterValue Interval
  1963. TempMeterValueInterval = 0;
  1964. return result;
  1965. }
  1966. int ProcessShareMemory()
  1967. {
  1968. if(InitShareMemory() == FAIL)
  1969. {
  1970. DEBUG_ERROR("InitShareMemory NG\n");
  1971. if(ShmStatusCodeData!=NULL)
  1972. {
  1973. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1974. }
  1975. sleep(5);
  1976. return FAIL;
  1977. }
  1978. return PASS;
  1979. }
  1980. //---------------------common routine---------------------------//
  1981. //---------------------------------------------
  1982. // new:
  1983. // enum SYSTEM_STATUS
  1984. // {
  1985. // SYS_MODE_BOOTING = 0,
  1986. // SYS_MODE_IDLE = 1,
  1987. // SYS_MODE_AUTHORIZING = 2,
  1988. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1989. // SYS_MODE_REASSIGN = 4,
  1990. // SYS_MODE_PREPARING = 5,
  1991. // SYS_MODE_PREPARE_FOR_EV = 6,
  1992. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1993. // SYS_MODE_CHARGING = 8,
  1994. // SYS_MODE_TERMINATING = 9,
  1995. // SYS_MODE_COMPLETE = 10,
  1996. // SYS_MODE_ALARM = 11,
  1997. // SYS_MODE_FAULT = 12,
  1998. // SYS_MODE_RESERVATION = 13,
  1999. // SYS_MODE_BOOKING = 14,
  2000. // SYS_MODE_MAINTAIN = 15,
  2001. // SYS_MODE_DEBUG = 16,
  2002. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2003. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2004. // SYS_MODE_UPDATE = 19
  2005. // };
  2006. //
  2007. //
  2008. //-----------------------------------------
  2009. void CheckSystemValue(void)
  2010. {
  2011. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2012. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2013. char filenmae[100]={0};
  2014. char str[100]={0};
  2015. int tempIndex = 0;
  2016. //===============================
  2017. // send Heartbeat
  2018. //===============================
  2019. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2020. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2021. {
  2022. clientTime.Heartbeat=time((time_t*)NULL);
  2023. if(server_sign == TRUE)
  2024. {
  2025. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2026. }
  2027. else
  2028. {
  2029. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2030. }
  2031. }
  2032. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2033. {
  2034. //parameter for test
  2035. sendHeartbeatRequest(0);
  2036. //==============================================
  2037. // Reset Waiting Time
  2038. //==============================================
  2039. HeartBeatWithNOResponse += 1;
  2040. }
  2041. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2042. {
  2043. //==========================================
  2044. // csu trigger DataTransferReq
  2045. //==========================================
  2046. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2047. {
  2048. sendDataTransferRequest(gun_index);
  2049. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2050. }
  2051. //===============================
  2052. // CSU Trigger Reset Conf
  2053. //===============================
  2054. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2055. {
  2056. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2057. }
  2058. //===============================
  2059. // CSU Trigger Authorize Request
  2060. //===============================
  2061. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2062. {
  2063. sendAuthorizeRequest(0);
  2064. authorizeRetryTimes = authorizeRetryTimes + 1;
  2065. if(authorizeRetryTimes < 3)
  2066. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2067. }
  2068. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2069. {
  2070. authorizeRetryTimes = 0;
  2071. SetOcppConnStatus(FALSE);
  2072. server_sign = FALSE;
  2073. }
  2074. 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))
  2075. {
  2076. sendAuthorizeRequest(0);
  2077. }
  2078. //===============================
  2079. // CSU Trigger Smart Charging Profilw
  2080. //===============================
  2081. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2082. {
  2083. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2084. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2085. }
  2086. //==============================================
  2087. // Charger start transaction
  2088. //==============================================
  2089. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2090. {
  2091. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2092. sendStartTransactionRequest(gun_index);
  2093. clientTime.StartTransaction = time((time_t*)NULL);
  2094. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2095. storeTempStopTransaction(gun_index);
  2096. }
  2097. //==============================================
  2098. // Charger stop transaction
  2099. //==============================================
  2100. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2101. {
  2102. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2103. sendStopTransactionRequest(gun_index);
  2104. clientTime.StopTransaction = time((time_t*)NULL);
  2105. }
  2106. //==============================================
  2107. // Charger status report
  2108. //==============================================
  2109. //--- Check Mode Change ---//
  2110. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2111. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2112. {
  2113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2114. {
  2115. tempIndex = ((gun_index==2) ? 1: 0);
  2116. }
  2117. else
  2118. {
  2119. tempIndex = gun_index;
  2120. }
  2121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2122. {
  2123. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2124. {
  2125. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2126. {
  2127. // Sent unplug message for California pricing logic
  2128. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2129. {
  2130. uint8_t ts[20];
  2131. getNowDatetime(ts);
  2132. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2133. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2134. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2135. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2136. }
  2137. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2138. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2139. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2140. statusModeChage[gun_index] = TRUE;
  2141. }
  2142. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2143. {
  2144. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2145. if((access(filenmae,F_OK))!=-1)
  2146. {
  2147. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2148. sprintf(str,"rm -f %s",filenmae);
  2149. system(str);
  2150. }
  2151. }
  2152. #if 1 // for TempStopTransaction
  2153. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2154. {
  2155. checkTempStopTransaction(gun_index);
  2156. }
  2157. #endif
  2158. }
  2159. }
  2160. }
  2161. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2162. {
  2163. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2164. {
  2165. tempIndex = ((gun_index==2) ? 1: 0);
  2166. }
  2167. else
  2168. {
  2169. tempIndex = gun_index;
  2170. }
  2171. for (int index = 0; index < CCS_QUANTITY; index++)
  2172. {
  2173. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2174. {
  2175. 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]*/ )
  2176. {
  2177. // Sent unplug message for California pricing logic
  2178. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2179. {
  2180. uint8_t ts[20];
  2181. getNowDatetime(ts);
  2182. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2183. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2184. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2185. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2186. }
  2187. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2188. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2189. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2190. statusModeChage[gun_index] = TRUE;
  2191. }
  2192. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2193. {
  2194. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2195. if((access(filenmae,F_OK))!=-1)
  2196. {
  2197. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2198. sprintf(str,"rm -f %s",filenmae);
  2199. system(str);
  2200. }
  2201. }
  2202. #if 1 // for TempStopTransaction
  2203. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2204. {
  2205. checkTempStopTransaction(gun_index);
  2206. }
  2207. #endif
  2208. }
  2209. }
  2210. }
  2211. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2212. {
  2213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2214. {
  2215. tempIndex = ((gun_index==2) ? 1: 0);
  2216. }
  2217. else
  2218. {
  2219. tempIndex = gun_index;
  2220. }
  2221. for (int index = 0; index < GB_QUANTITY; index++)
  2222. {
  2223. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2224. {
  2225. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2226. {
  2227. // Sent unplug message for California pricing logic
  2228. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2229. {
  2230. uint8_t ts[20];
  2231. getNowDatetime(ts);
  2232. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2233. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2234. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2235. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2236. }
  2237. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2238. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2239. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2240. statusModeChage[gun_index] = TRUE;
  2241. }
  2242. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2243. {
  2244. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2245. if((access(filenmae,F_OK))!=-1)
  2246. {
  2247. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2248. sprintf(str,"rm -f %s",filenmae);
  2249. system(str);
  2250. }
  2251. }
  2252. #if 1 // for TempStopTransaction
  2253. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2254. {
  2255. checkTempStopTransaction(gun_index);
  2256. }
  2257. #endif
  2258. }
  2259. }
  2260. }
  2261. else if(gunType[gun_index] == GUN_TYPE_DO)
  2262. {
  2263. tempIndex = gun_index;
  2264. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2265. {
  2266. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2267. {
  2268. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2269. {
  2270. // Sent unplug message for California pricing logic
  2271. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2272. {
  2273. uint8_t ts[20];
  2274. getNowDatetime(ts);
  2275. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2276. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2277. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2278. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2279. }
  2280. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2281. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2282. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2283. statusModeChage[gun_index] = TRUE;
  2284. }
  2285. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  2286. {
  2287. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2288. if((access(filenmae,F_OK))!=-1)
  2289. {
  2290. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2291. sprintf(str,"rm -f %s",filenmae);
  2292. system(str);
  2293. }
  2294. }
  2295. #if 1 // for TempStopTransaction
  2296. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2297. {
  2298. checkTempStopTransaction(gun_index);
  2299. }
  2300. #endif
  2301. }
  2302. }
  2303. }
  2304. else
  2305. {
  2306. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2307. {
  2308. tempIndex = 2;
  2309. }
  2310. else
  2311. {
  2312. tempIndex = gun_index;
  2313. }
  2314. for (int index = 0; index < AC_QUANTITY; index++)
  2315. {
  2316. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2317. {
  2318. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2319. {
  2320. // Sent unplug message for California pricing logic
  2321. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2322. {
  2323. uint8_t ts[20];
  2324. getNowDatetime(ts);
  2325. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2326. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2327. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2328. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2329. }
  2330. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2331. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2332. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2333. statusModeChage[gun_index] = TRUE;
  2334. }
  2335. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2336. {
  2337. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2338. if((access(filenmae,F_OK))!=-1)
  2339. {
  2340. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2341. sprintf(str,"rm -f %s",filenmae);
  2342. system(str);
  2343. }
  2344. }
  2345. #if 1 // for TempStopTransaction
  2346. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2347. {
  2348. checkTempStopTransaction(gun_index);
  2349. }
  2350. #endif
  2351. }
  2352. }// END
  2353. }
  2354. if(isWebsocketSendable &&
  2355. (
  2356. (statusModeChage[gun_index] == TRUE) ||
  2357. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2358. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2359. )
  2360. )
  2361. {
  2362. if(SystemInitial > 0)
  2363. SystemInitial -= 1;
  2364. sendStatusNotificationRequest(gun_index);
  2365. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2366. statusModeChage[gun_index] = FALSE;
  2367. }
  2368. //==============================================
  2369. // Meter report
  2370. //==============================================
  2371. // Trigger MeterValue
  2372. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2373. {
  2374. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2375. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2376. }
  2377. // ClockAlign MeterValue
  2378. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2379. {
  2380. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2381. {
  2382. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2383. {
  2384. tempIndex = ((gun_index==2) ? 1: 0);
  2385. }
  2386. else
  2387. {
  2388. tempIndex = gun_index;
  2389. }
  2390. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2391. {
  2392. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2393. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2394. {
  2395. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2396. {
  2397. reqClockAlignMeter[gun_index] = 1;
  2398. }
  2399. }
  2400. }// End for CHAdeMO
  2401. }
  2402. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2403. {
  2404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2405. {
  2406. tempIndex = ((gun_index==2) ? 1: 0);
  2407. }
  2408. else
  2409. {
  2410. tempIndex = gun_index;
  2411. }
  2412. for (int index = 0; index < CCS_QUANTITY; index++)
  2413. {
  2414. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2415. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2416. {
  2417. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2418. {
  2419. reqClockAlignMeter[gun_index] = 1;
  2420. }
  2421. }
  2422. } // End for CCS
  2423. }
  2424. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2425. {
  2426. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2427. {
  2428. tempIndex = ((gun_index==2) ? 1: 0);
  2429. }
  2430. else
  2431. {
  2432. tempIndex = gun_index;
  2433. }
  2434. for (int index = 0; index < GB_QUANTITY; index++)
  2435. {
  2436. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2437. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2438. {
  2439. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2440. {
  2441. reqClockAlignMeter[gun_index] = 1;
  2442. }
  2443. }
  2444. }// End for GB
  2445. }
  2446. else if(gunType[gun_index] == GUN_TYPE_DO)
  2447. {
  2448. tempIndex = gun_index;
  2449. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2450. {
  2451. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2452. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2453. {
  2454. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2455. {
  2456. reqClockAlignMeter[gun_index] = 1;
  2457. }
  2458. }
  2459. }
  2460. }
  2461. else
  2462. {
  2463. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2464. {
  2465. tempIndex = 2;
  2466. }
  2467. else
  2468. {
  2469. tempIndex = gun_index;
  2470. }
  2471. for (int index = 0; index < AC_QUANTITY; index++)
  2472. {
  2473. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2474. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2475. {
  2476. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2477. {
  2478. reqClockAlignMeter[gun_index] = 1;
  2479. }
  2480. }
  2481. }//End for AC
  2482. }
  2483. if(reqClockAlignMeter[gun_index] == 1)
  2484. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2485. }
  2486. // Sample period MeterValue
  2487. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2488. {
  2489. //check Transaction active
  2490. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2491. {
  2492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2493. {
  2494. tempIndex = ((gun_index==2) ? 1: 0);
  2495. }
  2496. else
  2497. {
  2498. tempIndex = gun_index;
  2499. }
  2500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2501. {
  2502. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2503. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2504. {
  2505. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2506. {
  2507. reqSampleMeter[gun_index] = 1;
  2508. }
  2509. }
  2510. }// End for CHAdeMO
  2511. }
  2512. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2513. {
  2514. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2515. {
  2516. tempIndex = ((gun_index==2) ? 1: 0);
  2517. }
  2518. else
  2519. {
  2520. tempIndex = gun_index;
  2521. }
  2522. for (int index = 0; index < CCS_QUANTITY; index++)
  2523. {
  2524. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2525. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2526. {
  2527. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2528. {
  2529. reqSampleMeter[gun_index] = 1;
  2530. }
  2531. }
  2532. } // End for CCS
  2533. }
  2534. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2535. {
  2536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2537. {
  2538. tempIndex = ((gun_index==2) ? 1: 0);
  2539. }
  2540. else
  2541. {
  2542. tempIndex = gun_index;
  2543. }
  2544. for (int index = 0; index < GB_QUANTITY; index++)
  2545. {
  2546. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2547. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2548. {
  2549. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2550. {
  2551. reqSampleMeter[gun_index] = 1;
  2552. }
  2553. }
  2554. }// End for GB
  2555. }
  2556. else if(gunType[gun_index] == GUN_TYPE_DO)
  2557. {
  2558. tempIndex = gun_index;
  2559. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2560. {
  2561. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2562. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2563. {
  2564. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2565. {
  2566. reqSampleMeter[gun_index] = 1;
  2567. }
  2568. }
  2569. }
  2570. }
  2571. else
  2572. {
  2573. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2574. {
  2575. tempIndex = 2;
  2576. }
  2577. else
  2578. {
  2579. tempIndex = gun_index;
  2580. }
  2581. for (int index = 0; index < AC_QUANTITY; index++)
  2582. {
  2583. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2584. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2585. {
  2586. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2587. {
  2588. reqSampleMeter[gun_index] = 1;
  2589. }
  2590. }
  2591. }//End for AC
  2592. }
  2593. if(reqSampleMeter[gun_index] == 1)
  2594. {
  2595. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2596. storeTempStopTransaction(gun_index);
  2597. }
  2598. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2599. }
  2600. //==============================================
  2601. // Check Connector reserved
  2602. //==============================================
  2603. //===============================
  2604. // Check if Reserve is expired
  2605. //===============================
  2606. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2607. {
  2608. double diff_t;
  2609. struct tm tp;
  2610. // current time
  2611. time_t t = time(NULL);
  2612. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2613. tp.tm_isdst = -1;
  2614. time_t utc = mktime(&tp);
  2615. diff_t = difftime(utc, t);
  2616. if(diff_t <= 0)
  2617. {
  2618. DEBUG_INFO("reserve expired.\n");
  2619. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2620. }
  2621. }//END OF Check if Reserve is expired
  2622. //==========================================
  2623. // csu trigger FirmwareStatusNotificationReq
  2624. //==========================================
  2625. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2626. {
  2627. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2628. }
  2629. //==========================================
  2630. // csu trigger CancelReservationConf
  2631. //==========================================
  2632. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2633. {
  2634. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2635. }
  2636. //==========================================
  2637. // csu trigger ChangeAvailabilityConf
  2638. //==========================================
  2639. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2640. {
  2641. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2642. }
  2643. //==========================================
  2644. // csu trigger UnlockConnectorConf
  2645. //==========================================
  2646. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2647. {
  2648. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2649. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2650. }
  2651. //==========================================
  2652. // csu trigger ReserveNowConf
  2653. //==========================================
  2654. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2655. {
  2656. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2657. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2658. }
  2659. }
  2660. }
  2661. //==========================================
  2662. // send request routine
  2663. //==========================================
  2664. int sendAuthorizeRequest(int gun_index)
  2665. {
  2666. mtrace();
  2667. int result = FAIL;
  2668. char message[100]={0};
  2669. char guid[37];
  2670. char tempdata[65]={0};
  2671. DEBUG_INFO("sendAuthorizeRequest...\n");
  2672. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2673. //Local Authorize
  2674. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2675. {
  2676. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2677. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2678. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2679. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2680. result = PASS;
  2681. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2682. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2683. authorizeRetryTimes = 0;
  2684. return result;
  2685. }
  2686. 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))||
  2687. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2688. {
  2689. // Query from cache
  2690. DEBUG_INFO("Authorize from cache.\n");
  2691. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2692. // Query from list
  2693. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2694. {
  2695. DEBUG_INFO("Authorize from list.\n");
  2696. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2697. }
  2698. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2699. {
  2700. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2701. {
  2702. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2703. }
  2704. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2705. {
  2706. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2707. }
  2708. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  2709. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2710. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2711. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2712. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2713. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2714. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2715. authorizeRetryTimes = 0;
  2716. return result;
  2717. }
  2718. else
  2719. {
  2720. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  2721. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2722. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2723. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2724. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2725. else
  2726. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2727. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2728. result = PASS;
  2729. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2730. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2731. authorizeRetryTimes = 0;
  2732. return result;
  2733. }
  2734. }
  2735. //initialize struct Authorize
  2736. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2737. //get data from shared memory
  2738. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2739. random_uuid(guid);
  2740. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2741. LWS_Send(message);
  2742. sprintf(tempdata, "Authorize,%d", gun_index);
  2743. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2744. {
  2745. result = PASS;
  2746. DEBUG_INFO("Authorize mapItem pass\n");
  2747. }
  2748. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2749. return result;
  2750. }
  2751. int sendBootNotificationRequest(void)
  2752. {
  2753. mtrace();
  2754. int result = FAIL;
  2755. char message[500]={0}, payload[700]={0};
  2756. char guid[37]={0};
  2757. char tempdata[65]={0};
  2758. // Fill BootNotification fields
  2759. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2760. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2761. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2762. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2763. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2764. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2765. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2766. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2767. ShmOCPP16Data->ChargeBoxId
  2768. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2769. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2770. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2771. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2772. ,ShmOCPP16Data->BootNotification.CpIccid
  2773. ,ShmOCPP16Data->BootNotification.CpImsi);
  2774. random_uuid(guid);
  2775. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2776. LWS_Send(message);
  2777. sprintf(tempdata, "BootNotification,0");
  2778. 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*/)
  2779. {
  2780. result = PASS;
  2781. }
  2782. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2783. strcpy(queuedata,message);
  2784. return result;
  2785. }
  2786. int sendDataTransferRequest(int gun_index)
  2787. {
  2788. mtrace();
  2789. char message[1000]={0};
  2790. char guid[37]={0};
  2791. char tempdata[65]={0};
  2792. int result = FAIL;
  2793. random_uuid(guid);
  2794. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2795. MESSAGE_TYPE_CALL,
  2796. guid,
  2797. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2798. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2799. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2800. LWS_Send(message);
  2801. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2802. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2803. {
  2804. result = PASS;
  2805. DEBUG_INFO("DataTransfer mapItem pass\n");
  2806. }
  2807. return result;
  2808. }
  2809. int sendDiagnosticsStatusNotificationRequest(char *status)
  2810. {
  2811. mtrace();
  2812. int result = FAIL;
  2813. char message[110]={0};
  2814. char guid[37]={0};
  2815. char tempdata[65]={0};
  2816. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2817. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2818. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2819. random_uuid(guid);
  2820. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2821. LWS_SendNow(message);
  2822. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2823. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2824. {
  2825. result = PASS;
  2826. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2827. }
  2828. //#ifdef SystemLogMessage
  2829. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2830. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2831. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2832. //#endif
  2833. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2834. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2835. //record status
  2836. if(strcmp(status,"Idle")==0)
  2837. {
  2838. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2839. }
  2840. else if(strcmp(status,"Uploaded")==0)
  2841. {
  2842. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2843. }
  2844. else if(strcmp(status,"UploadFailed")==0)
  2845. {
  2846. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2847. }
  2848. else if(strcmp(status,"Uploading")==0)
  2849. {
  2850. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2851. }
  2852. return result;
  2853. }
  2854. int sendFirmwareStatusNotificationRequest(char *status)
  2855. {
  2856. mtrace();
  2857. int result = FAIL;
  2858. char message[110]={0};
  2859. char guid[37]={0};
  2860. char tempdata[65]={0};
  2861. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2862. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2863. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2864. random_uuid(guid);
  2865. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2866. LWS_SendNow(message);
  2867. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2868. 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*/)
  2869. {
  2870. result = PASS;
  2871. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2872. }
  2873. //#ifdef SystemLogMessage
  2874. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2875. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2876. //#endif
  2877. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2878. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2879. //record status
  2880. if(strcmp(status,"Downloaded")==0)
  2881. {
  2882. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2883. }
  2884. else if(strcmp(status,"DownloadFailed")==0)
  2885. {
  2886. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2887. }
  2888. else if(strcmp(status,"Downloading")==0)
  2889. {
  2890. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2891. }
  2892. else if(strcmp(status,"Idle")==0)
  2893. {
  2894. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2895. }
  2896. else if(strcmp(status,"InstallationFailed")==0)
  2897. {
  2898. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2899. }
  2900. else if(strcmp(status,"Installing")==0)
  2901. {
  2902. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2903. }
  2904. else if(strcmp(status,"Installed")==0)
  2905. {
  2906. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2907. }
  2908. return result;
  2909. }
  2910. int sendHeartbeatRequest(int gun_index)
  2911. {
  2912. mtrace();
  2913. int result = FAIL;
  2914. char message[80]={0};
  2915. char guid[37]={0};
  2916. char tempdata[65]={0};
  2917. random_uuid(guid);
  2918. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2919. , MESSAGE_TYPE_CALL
  2920. , guid );
  2921. LWS_Send(message);
  2922. sprintf(tempdata, "Heartbeat,%d", 0);
  2923. 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*/)
  2924. {
  2925. result = PASS;
  2926. }
  2927. return result;
  2928. }
  2929. int sendStartTransactionRequest(int gun_index)
  2930. {
  2931. mtrace();
  2932. int result = FAIL;
  2933. char message[250]={0};
  2934. char guid[37]={0};
  2935. struct timeval tmnow;
  2936. struct tm *tm;
  2937. char buf[28];//, usec_buf[6];
  2938. char tempdata[65]={0};
  2939. int tempIndex = 0;
  2940. DEBUG_INFO("sendStartTransactionRequest...\n");
  2941. gettimeofday(&tmnow, NULL);
  2942. time_t t;
  2943. t = time(NULL);
  2944. /*UTC time and date*/
  2945. tm = gmtime(&t);
  2946. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2947. #if 0 // remove temporally
  2948. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2949. strcat(buf,".");
  2950. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2951. strcat(buf,usec_buf);
  2952. #endif
  2953. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2954. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2955. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2956. // clear StartTransaction Response
  2957. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2958. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2959. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2960. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2961. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2962. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2963. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2964. {
  2965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2966. {
  2967. tempIndex = ((gun_index==2) ? 1: 0);
  2968. }
  2969. else
  2970. {
  2971. tempIndex = gun_index;
  2972. }
  2973. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2974. {
  2975. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2976. {
  2977. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2978. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2979. }
  2980. }
  2981. }
  2982. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  2993. {
  2994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2995. {
  2996. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2997. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2998. }
  2999. }
  3000. }
  3001. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3002. {
  3003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3004. {
  3005. tempIndex = ((gun_index==2) ? 1: 0);
  3006. }
  3007. else
  3008. {
  3009. tempIndex = gun_index;
  3010. }
  3011. for (int index = 0; index < GB_QUANTITY; index++)
  3012. {
  3013. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3014. {
  3015. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3016. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3017. }
  3018. }
  3019. }
  3020. else if(gunType[gun_index] == GUN_TYPE_DO)
  3021. {
  3022. tempIndex = gun_index;
  3023. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3024. {
  3025. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3026. {
  3027. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3028. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3029. }
  3030. }
  3031. }
  3032. else
  3033. {
  3034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3035. {
  3036. tempIndex = 2;
  3037. }
  3038. else
  3039. {
  3040. tempIndex = gun_index;
  3041. }
  3042. for (int index = 0; index < AC_QUANTITY; index++)
  3043. {
  3044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3045. {
  3046. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3047. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3048. }
  3049. }
  3050. }
  3051. random_uuid(guid);
  3052. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3053. {
  3054. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3055. , gun_index +1
  3056. , MESSAGE_TYPE_CALL
  3057. , guid
  3058. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3059. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3060. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3061. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3062. }
  3063. else
  3064. {
  3065. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3066. , gun_index +1
  3067. , MESSAGE_TYPE_CALL
  3068. , guid
  3069. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3070. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3071. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3072. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3073. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3074. }
  3075. #if 1
  3076. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3077. 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*/)
  3078. {
  3079. result = PASS;
  3080. }
  3081. #endif
  3082. strcpy(queuedata, message);
  3083. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3084. return result;
  3085. }
  3086. int sendStatusNotificationRequest(int gun_index)
  3087. {
  3088. mtrace();
  3089. int result = FAIL;
  3090. char message[600]={0};
  3091. char guid[37];
  3092. int currentStatus = 0;
  3093. struct timeval tmnow;
  3094. struct tm *tm;
  3095. char buf[28];//, usec_buf[6];
  3096. char tempdata[65]={0};
  3097. int tempIndex = 0;
  3098. gettimeofday(&tmnow, NULL);
  3099. time_t t;
  3100. t = time(NULL);
  3101. /*UTC time and date*/
  3102. tm = gmtime(&t);
  3103. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3104. #if 0 // remove temporally
  3105. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3106. strcat(buf,".");
  3107. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3108. strcat(buf,usec_buf);
  3109. #endif
  3110. printf("%s",buf);
  3111. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3112. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3113. // it's option
  3114. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3115. /*
  3116. enum _SYSTEM_STATUS
  3117. {
  3118. S_BOOTING = 0,
  3119. S_IDLE, = 1
  3120. S_AUTHORIZING, =2
  3121. S_REASSIGN_CHECK, =3
  3122. S_REASSIGN, =4
  3123. S_PRECHARGE, =5
  3124. S_PREPARING_FOR_EV, =6
  3125. S_PREPARING_FOR_EVSE, =7
  3126. S_CHARGING, =8
  3127. S_TERMINATING, =9
  3128. S_COMPLETE, =10
  3129. S_ALARM, =11
  3130. S_FAULT =12
  3131. }
  3132. */
  3133. //check Transaction active
  3134. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3135. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3136. {
  3137. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3138. {
  3139. tempIndex = ((gun_index==2) ? 1: 0);
  3140. }
  3141. else
  3142. {
  3143. tempIndex = gun_index;
  3144. }
  3145. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3146. {
  3147. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3148. {
  3149. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3150. {
  3151. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3152. {
  3153. currentStatus = Preparing; //OCPP Status: Preparing
  3154. }
  3155. else
  3156. {
  3157. currentStatus = Available; //OCPP Status: Available
  3158. }
  3159. }
  3160. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3161. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3162. ) //S_PRECHARGE
  3163. {
  3164. currentStatus = Preparing; //OCPP Status: Preparing
  3165. }
  3166. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3167. {
  3168. currentStatus = Charging; //OCPP Status: Charging
  3169. }
  3170. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3171. {
  3172. currentStatus = Finishing; //OCPP Status: Finishing
  3173. }
  3174. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3175. {
  3176. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3177. }
  3178. 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
  3179. {
  3180. currentStatus = Unavailable; //OCPP Status: Unavailable
  3181. }
  3182. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3183. {
  3184. currentStatus = Faulted; //OCPP Status: Faulted
  3185. }
  3186. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3187. {
  3188. currentStatus = Reserved; //OCPP Status: Reserved
  3189. }
  3190. } //end of the same index
  3191. }//end of for CHAdeMO_QUANTITY
  3192. }
  3193. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3194. {
  3195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3196. {
  3197. tempIndex = ((gun_index==2) ? 1: 0);
  3198. }
  3199. else
  3200. {
  3201. tempIndex = gun_index;
  3202. }
  3203. for (int index = 0; index < CCS_QUANTITY; index++)
  3204. {
  3205. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3206. {
  3207. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3208. {
  3209. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3210. {
  3211. currentStatus = Preparing; //OCPP Status: Preparing
  3212. }
  3213. else
  3214. {
  3215. currentStatus = Available; //OCPP Status: Available
  3216. }
  3217. }
  3218. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3219. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3220. ) //S_PRECHARGE
  3221. {
  3222. currentStatus = Preparing; //OCPP Status: Preparing
  3223. }
  3224. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3225. {
  3226. currentStatus = Charging; //OCPP Status: Charging
  3227. }
  3228. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3229. {
  3230. currentStatus = Finishing; //OCPP Status: Finishing
  3231. }
  3232. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3233. {
  3234. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3235. }
  3236. 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
  3237. {
  3238. currentStatus = Unavailable; //OCPP Status : Unavailable
  3239. }
  3240. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3241. {
  3242. currentStatus = Faulted; //OCPP Status: Faulted
  3243. }
  3244. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3245. {
  3246. currentStatus = Reserved; //OCPP Status: Reserved
  3247. }
  3248. } //end of the same index
  3249. } // end of for CCS_QUANTITY
  3250. }
  3251. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3252. {
  3253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3254. {
  3255. tempIndex = ((gun_index==2) ? 1: 0);
  3256. }
  3257. else
  3258. {
  3259. tempIndex = gun_index;
  3260. }
  3261. for (int index = 0; index < GB_QUANTITY; index++)
  3262. {
  3263. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3264. {
  3265. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3266. {
  3267. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3268. {
  3269. currentStatus = Preparing; //OCPP Status: Preparing
  3270. }
  3271. else
  3272. {
  3273. currentStatus = Available; //OCPP Status: Available
  3274. }
  3275. }
  3276. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3277. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3278. ) //S_PRECHARGE
  3279. {
  3280. currentStatus = Preparing; //OCPP Status: Preparing
  3281. }
  3282. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3283. {
  3284. currentStatus = Charging; //OCPP Status: Charging
  3285. }
  3286. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3287. {
  3288. currentStatus = Finishing; //OCPP Status: Finishing
  3289. }
  3290. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3291. {
  3292. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3293. }
  3294. 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
  3295. {
  3296. currentStatus = Unavailable; //OCPP Status: Unavailable
  3297. }
  3298. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3299. {
  3300. currentStatus = Faulted; //OCPP Status: Faulted
  3301. }
  3302. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3303. {
  3304. currentStatus = Reserved; //OCPP Status: Reserved
  3305. }
  3306. } //end of the same index
  3307. } // end of for GB_QUANTITY
  3308. }
  3309. else if(gunType[gun_index] == GUN_TYPE_DO)
  3310. {
  3311. tempIndex = gun_index;
  3312. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3313. {
  3314. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3315. {
  3316. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3317. {
  3318. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3319. {
  3320. currentStatus = Preparing; //OCPP Status: Preparing
  3321. }
  3322. else
  3323. {
  3324. currentStatus = Available; //OCPP Status: Available
  3325. }
  3326. }
  3327. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3328. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3329. ) //S_PRECHARGE
  3330. {
  3331. currentStatus = Preparing; //OCPP Status: Preparing
  3332. }
  3333. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3334. {
  3335. currentStatus = Charging; //OCPP Status: Charging
  3336. }
  3337. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3338. {
  3339. currentStatus = Finishing; //OCPP Status: Finishing
  3340. }
  3341. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3342. {
  3343. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3344. }
  3345. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3346. {
  3347. currentStatus = Unavailable; //OCPP Status: Unavailable
  3348. }
  3349. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3350. {
  3351. currentStatus = Faulted; //OCPP Status: Faulted
  3352. }
  3353. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3354. {
  3355. currentStatus = Reserved; //OCPP Status: Reserved
  3356. }
  3357. } //end of the same index
  3358. }
  3359. }
  3360. else
  3361. {
  3362. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3363. {
  3364. tempIndex = 2;
  3365. }
  3366. else
  3367. {
  3368. tempIndex = gun_index;
  3369. }
  3370. for (int index = 0; index < AC_QUANTITY; index++)
  3371. {
  3372. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3373. {
  3374. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3375. {
  3376. 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))
  3377. {
  3378. currentStatus = Preparing; //OCPP Status: Preparing
  3379. }
  3380. else
  3381. {
  3382. currentStatus = Available; //OCPP Status: Available
  3383. }
  3384. }
  3385. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3386. {
  3387. currentStatus = Preparing; //OCPP Status: Preparing
  3388. }
  3389. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3390. {
  3391. currentStatus = Charging; //OCPP Status: Charging
  3392. }
  3393. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3394. {
  3395. currentStatus = Finishing; //OCPP Status: Finishing
  3396. }
  3397. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3398. {
  3399. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3400. }
  3401. 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
  3402. {
  3403. currentStatus = Unavailable; //OCPP Status: Unavailable
  3404. }
  3405. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3406. {
  3407. currentStatus = Faulted; //OCPP Status: Faulted
  3408. }
  3409. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3410. {
  3411. currentStatus = Reserved; //OCPP Status: Reserved
  3412. }
  3413. }//end of the same index
  3414. }//end of for AC_QUANTITY
  3415. }
  3416. //it's option
  3417. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3418. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3419. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3420. random_uuid(guid);
  3421. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3422. , MESSAGE_TYPE_CALL
  3423. , guid
  3424. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3425. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3426. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3427. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3428. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3429. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3430. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3431. if((server_sign == TRUE))
  3432. {
  3433. LWS_Send(message);
  3434. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3435. 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*/)
  3436. {
  3437. //DEBUG_ERROR("statusNotification mapitem pass");
  3438. result = PASS;
  3439. }
  3440. }
  3441. else
  3442. {
  3443. result = PASS;
  3444. }
  3445. return result;
  3446. }
  3447. int sendStopTransactionRequest(int gun_index)
  3448. {
  3449. mtrace();
  3450. int result = FAIL;
  3451. //char message[1500]={0};
  3452. char guid[37]={0};
  3453. char tempdata[65]={0};
  3454. int tempIndex = 0;
  3455. char TempStopTransaction[256];
  3456. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3457. //int idx_sample=0;
  3458. DEBUG_INFO("sendStopTransactionRequest \n");
  3459. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3460. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3461. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3462. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3463. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3464. {
  3465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3466. {
  3467. tempIndex = ((gun_index==2) ? 1: 0);
  3468. }
  3469. else
  3470. {
  3471. tempIndex = gun_index;
  3472. }
  3473. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3474. {
  3475. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3476. {
  3477. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3478. }
  3479. }// END OF CHAdeMO_QUANTITY
  3480. }
  3481. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3482. {
  3483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3484. {
  3485. tempIndex = ((gun_index==2) ? 1: 0);
  3486. }
  3487. else
  3488. {
  3489. tempIndex = gun_index;
  3490. }
  3491. for (int index = 0; index < CCS_QUANTITY; index++)
  3492. {
  3493. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3494. {
  3495. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3496. }
  3497. }// END OF CCS_QUANTITY
  3498. }
  3499. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3500. {
  3501. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3502. {
  3503. tempIndex = ((gun_index==2) ? 1: 0);
  3504. }
  3505. else
  3506. {
  3507. tempIndex = gun_index;
  3508. }
  3509. for (int index = 0; index < GB_QUANTITY; index++)
  3510. {
  3511. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3512. {
  3513. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3514. }
  3515. }// END OF GB_QUANTITY
  3516. }
  3517. else if(gunType[gun_index] == GUN_TYPE_DO)
  3518. {
  3519. tempIndex = gun_index;
  3520. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3521. {
  3522. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3523. {
  3524. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3525. }
  3526. }// END OF GB_QUANTITY
  3527. }
  3528. else
  3529. {
  3530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3531. {
  3532. tempIndex = 2;
  3533. }
  3534. else
  3535. {
  3536. tempIndex = gun_index;
  3537. }
  3538. for (int index = 0; index < AC_QUANTITY; index++)
  3539. {
  3540. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3541. {
  3542. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3543. }
  3544. }// END OF AC_QUANTITY
  3545. }
  3546. //====================================== Stop Transaction Time =====================================================
  3547. struct timeval tmnow;
  3548. struct tm *tm;
  3549. char buf[28];//, usec_buf[6];
  3550. gettimeofday(&tmnow, NULL);
  3551. time_t t;
  3552. t = time(NULL);
  3553. /*UTC time and date*/
  3554. tm = gmtime(&t);
  3555. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3557. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3558. random_uuid(guid);
  3559. /***********************************transactionData******************************************************/
  3560. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3562. //=================================
  3563. // Transaction_Begin
  3564. //=================================
  3565. //============================================ Energy.Active.Import.Interval ================================
  3566. //idx_sample=0;
  3567. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3570. 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*/]);
  3571. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3572. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  3573. {
  3574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3575. }
  3576. else
  3577. {
  3578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3579. }
  3580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3582. //=================================
  3583. // Transaction_End
  3584. //=================================
  3585. // ================================= Current.Import L1 ===============================================
  3586. //idx_sample=1;
  3587. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3588. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3589. {
  3590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3591. {
  3592. tempIndex = ((gun_index==2) ? 1: 0);
  3593. }
  3594. else
  3595. {
  3596. tempIndex = gun_index;
  3597. }
  3598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3599. {
  3600. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3601. {
  3602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3603. }
  3604. }// End of for CHAdeMO_QUANTITY
  3605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3606. }
  3607. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3608. {
  3609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3610. {
  3611. tempIndex = ((gun_index==2) ? 1: 0);
  3612. }
  3613. else
  3614. {
  3615. tempIndex = gun_index;
  3616. }
  3617. for (int index = 0; index < CCS_QUANTITY; index++)
  3618. {
  3619. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3620. {
  3621. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3622. }
  3623. }// End of for CCS_QUANTITY
  3624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3625. }
  3626. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3627. {
  3628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3629. {
  3630. tempIndex = ((gun_index==2) ? 1: 0);
  3631. }
  3632. else
  3633. {
  3634. tempIndex = gun_index;
  3635. }
  3636. for (int index = 0; index < GB_QUANTITY; index++)
  3637. {
  3638. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3639. {
  3640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3641. }
  3642. }// End of for GB_QUANTITY
  3643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3644. }
  3645. else if(gunType[gun_index] == GUN_TYPE_DO)
  3646. {
  3647. tempIndex = gun_index;
  3648. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3649. {
  3650. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3651. {
  3652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3653. }
  3654. }
  3655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3656. }
  3657. else
  3658. {
  3659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3660. {
  3661. tempIndex = 2;
  3662. }
  3663. else
  3664. {
  3665. tempIndex = gun_index;
  3666. }
  3667. for (int index = 0; index < AC_QUANTITY; index++)
  3668. {
  3669. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3670. {
  3671. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3672. }
  3673. }// End of for AC_QUANTITY
  3674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3675. }
  3676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3681. // ================================= Energy.Active.Import.Interval ==============================================
  3682. //idx_sample=2;
  3683. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3684. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3685. {
  3686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3687. {
  3688. tempIndex = ((gun_index==2) ? 1: 0);
  3689. }
  3690. else
  3691. {
  3692. tempIndex = gun_index;
  3693. }
  3694. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3695. {
  3696. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3697. {
  3698. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3699. }
  3700. }// END OF CHAdeMO_QUANTITY
  3701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3702. }
  3703. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3704. {
  3705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3706. {
  3707. tempIndex = ((gun_index==2) ? 1: 0);
  3708. }
  3709. else
  3710. {
  3711. tempIndex = gun_index;
  3712. }
  3713. for (int index = 0; index < CCS_QUANTITY; index++)
  3714. {
  3715. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3716. {
  3717. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3718. }
  3719. }// END OF CCS_QUANTITY
  3720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3721. }
  3722. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3723. {
  3724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3725. {
  3726. tempIndex = ((gun_index==2) ? 1: 0);
  3727. }
  3728. else
  3729. {
  3730. tempIndex = gun_index;
  3731. }
  3732. for (int index = 0; index < GB_QUANTITY; index++)
  3733. {
  3734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3735. {
  3736. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3737. }
  3738. }// END OF GB_QUANTITY
  3739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3740. }
  3741. else if(gunType[gun_index] == GUN_TYPE_DO)
  3742. {
  3743. tempIndex = gun_index;
  3744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3745. {
  3746. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3747. {
  3748. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3749. }
  3750. }
  3751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3752. }
  3753. else
  3754. {
  3755. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3756. {
  3757. tempIndex = 2;
  3758. }
  3759. else
  3760. {
  3761. tempIndex = gun_index;
  3762. }
  3763. for (int index = 0; index < AC_QUANTITY; index++)
  3764. {
  3765. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3766. {
  3767. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3768. }
  3769. }// END OF AC_QUANTITY
  3770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3771. }
  3772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3777. //=================================== Power.Active.Import ==================================================
  3778. //idx_sample=3;
  3779. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3780. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3781. {
  3782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3783. {
  3784. tempIndex = ((gun_index==2) ? 1: 0);
  3785. }
  3786. else
  3787. {
  3788. tempIndex = gun_index;
  3789. }
  3790. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3791. {
  3792. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3793. {
  3794. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3795. }
  3796. } // End for CHAdeMO_QUANTITY
  3797. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3798. }
  3799. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3800. {
  3801. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3802. {
  3803. tempIndex = ((gun_index==2) ? 1: 0);
  3804. }
  3805. else
  3806. {
  3807. tempIndex = gun_index;
  3808. }
  3809. for (int index = 0; index < CCS_QUANTITY; index++)
  3810. {
  3811. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3812. {
  3813. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3814. }
  3815. } // END for CCS_QUANTITY
  3816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3817. }
  3818. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3819. {
  3820. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3821. {
  3822. tempIndex = ((gun_index==2) ? 1: 0);
  3823. }
  3824. else
  3825. {
  3826. tempIndex = gun_index;
  3827. }
  3828. for (int index = 0; index < GB_QUANTITY; index++)
  3829. {
  3830. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3831. {
  3832. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3833. }
  3834. }// END for GB_QUANTITY
  3835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3836. }
  3837. else if(gunType[gun_index] == GUN_TYPE_DO)
  3838. {
  3839. tempIndex = gun_index;
  3840. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3841. {
  3842. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3843. {
  3844. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3845. }
  3846. }
  3847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3848. }
  3849. else
  3850. {
  3851. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3852. {
  3853. tempIndex = 2;
  3854. }
  3855. else
  3856. {
  3857. tempIndex = gun_index;
  3858. }
  3859. for (int index = 0; index < AC_QUANTITY; index++)
  3860. {
  3861. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3862. {
  3863. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3864. }
  3865. } // END for AC_QUANTITY
  3866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3867. }
  3868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3873. //============================ Voltage L1 ====================================
  3874. //idx_sample=4;
  3875. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3876. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3877. {
  3878. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3879. {
  3880. tempIndex = ((gun_index==2) ? 1: 0);
  3881. }
  3882. else
  3883. {
  3884. tempIndex = gun_index;
  3885. }
  3886. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3887. {
  3888. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3889. {
  3890. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3891. }
  3892. } // END OF FOR CHAdeMO_QUANTITY
  3893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3894. }
  3895. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3896. {
  3897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3898. {
  3899. tempIndex = ((gun_index==2) ? 1: 0);
  3900. }
  3901. else
  3902. {
  3903. tempIndex = gun_index;
  3904. }
  3905. for (int index = 0; index < CCS_QUANTITY; index++)
  3906. {
  3907. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3908. {
  3909. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3910. }
  3911. } // END OF FOR CCS_QUANTITY
  3912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3913. }
  3914. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3915. {
  3916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3917. {
  3918. tempIndex = ((gun_index==2) ? 1: 0);
  3919. }
  3920. else
  3921. {
  3922. tempIndex = gun_index;
  3923. }
  3924. for (int index = 0; index < GB_QUANTITY; index++)
  3925. {
  3926. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3927. {
  3928. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3929. }
  3930. } // END OF FOR GB_QUANTITY
  3931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3932. }
  3933. else if(gunType[gun_index] == GUN_TYPE_DO)
  3934. {
  3935. tempIndex = gun_index;
  3936. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3937. {
  3938. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3939. {
  3940. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3941. }
  3942. }
  3943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3944. }
  3945. else
  3946. {
  3947. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3948. {
  3949. tempIndex = 2;
  3950. }
  3951. else
  3952. {
  3953. tempIndex = gun_index;
  3954. }
  3955. for (int index = 0; index < AC_QUANTITY; index++)
  3956. {
  3957. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3958. {
  3959. 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
  3960. }
  3961. } // END OF FOR AC_QUANTITY
  3962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3963. }
  3964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3969. //====================== End SoC ================================
  3970. //idx_sample=5;
  3971. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3972. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  3973. {
  3974. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  3975. {
  3976. tempIndex = ((gun_index==2) ? 1: 0);
  3977. }
  3978. else
  3979. {
  3980. tempIndex = gun_index;
  3981. }
  3982. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3983. {
  3984. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3985. {
  3986. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3987. {
  3988. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3989. }
  3990. }
  3991. }
  3992. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3993. {
  3994. for (int index = 0; index < CCS_QUANTITY; index++)
  3995. {
  3996. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3997. {
  3998. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3999. }
  4000. }
  4001. }
  4002. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4003. {
  4004. for (int index = 0; index < GB_QUANTITY; index++)
  4005. {
  4006. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4007. {
  4008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4009. }
  4010. }
  4011. }
  4012. else if(gunType[gun_index] == GUN_TYPE_DO)
  4013. {
  4014. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4015. {
  4016. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4017. {
  4018. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4019. }
  4020. }
  4021. }
  4022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4028. } // END FOR DC CASE
  4029. // ================================= Current.Import L2 ===============================================
  4030. //idx_sample=6;
  4031. // AC 3 phse L2 current
  4032. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4033. {
  4034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4035. {
  4036. tempIndex = 2;
  4037. }
  4038. else
  4039. {
  4040. tempIndex = gun_index;
  4041. }
  4042. for (int index = 0; index < AC_QUANTITY; index++)
  4043. {
  4044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4045. {
  4046. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4047. }
  4048. }// End of for AC_QUANTITY
  4049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4050. }
  4051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4056. // ================================= Current.Import L3 ===============================================
  4057. //idx_sample=7;
  4058. // AC 3 phse L3 current
  4059. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4060. {
  4061. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4062. {
  4063. tempIndex = 2;
  4064. }
  4065. else
  4066. {
  4067. tempIndex = gun_index;
  4068. }
  4069. for (int index = 0; index < AC_QUANTITY; index++)
  4070. {
  4071. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4072. {
  4073. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4074. }
  4075. }// End of for AC_QUANTITY
  4076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4077. }
  4078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4083. //============================ Voltage L2 ====================================
  4084. //idx_sample=8;
  4085. // AC 3 phse L2 voltage
  4086. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4087. {
  4088. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4089. {
  4090. tempIndex = 2;
  4091. }
  4092. else
  4093. {
  4094. tempIndex = gun_index;
  4095. }
  4096. for (int index = 0; index < AC_QUANTITY; index++)
  4097. {
  4098. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4099. {
  4100. 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
  4101. }
  4102. } // END OF FOR AC_QUANTITY
  4103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4104. }
  4105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4110. //============================ Voltage L3 ====================================
  4111. //idx_sample=8;
  4112. // AC 3 phse L3 voltage
  4113. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4114. {
  4115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4116. {
  4117. tempIndex = 2;
  4118. }
  4119. else
  4120. {
  4121. tempIndex = gun_index;
  4122. }
  4123. for (int index = 0; index < AC_QUANTITY; index++)
  4124. {
  4125. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4126. {
  4127. 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
  4128. }
  4129. } // END OF FOR AC_QUANTITY
  4130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4131. }
  4132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4137. //====================== Start SoC ================================
  4138. //idx_sample=10;
  4139. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4140. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  4141. {
  4142. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4143. {
  4144. tempIndex = ((gun_index==2) ? 1: 0);
  4145. }
  4146. else
  4147. {
  4148. tempIndex = gun_index;
  4149. }
  4150. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4151. {
  4152. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4153. {
  4154. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4155. {
  4156. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4157. }
  4158. }
  4159. }
  4160. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4161. {
  4162. for (int index = 0; index < CCS_QUANTITY; index++)
  4163. {
  4164. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4165. {
  4166. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4167. }
  4168. }
  4169. }
  4170. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4171. {
  4172. for (int index = 0; index < GB_QUANTITY; index++)
  4173. {
  4174. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4175. {
  4176. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4177. }
  4178. }
  4179. }
  4180. else if(gunType[gun_index] == GUN_TYPE_DO)
  4181. {
  4182. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4183. {
  4184. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4185. {
  4186. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4187. }
  4188. }
  4189. }
  4190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4196. } // END FOR DC CASE
  4197. //================================================ Message create ====================================================
  4198. json_object *StopTransaction = json_object_new_object();
  4199. json_object *transactionDatas = json_object_new_array();
  4200. json_object *sampledValues = json_object_new_array();
  4201. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4202. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4203. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4204. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4205. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4206. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4207. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4208. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4209. {
  4210. json_object *transactionData = json_object_new_object();
  4211. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4212. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4213. {
  4214. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4215. {
  4216. json_object *sampledValue = json_object_new_object();
  4217. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4218. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4219. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4220. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4221. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4222. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4223. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4224. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4225. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4226. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4227. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4228. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4229. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4230. json_object_array_add(sampledValues, sampledValue);
  4231. }
  4232. }
  4233. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4234. json_object_array_add(transactionDatas, transactionData);
  4235. }
  4236. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4237. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4238. ,MESSAGE_TYPE_CALL
  4239. ,guid
  4240. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4241. json_object_put(StopTransaction);
  4242. #if 1 // for TempStopTransaction
  4243. //Delete TempStopTransaction
  4244. if((access(TempStopTransaction,F_OK))!=-1)
  4245. {
  4246. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4247. }
  4248. #endif
  4249. #if 1
  4250. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4251. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4252. {
  4253. result = PASS;
  4254. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4255. }
  4256. #endif
  4257. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4258. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4259. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4260. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4261. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4262. {
  4263. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4264. }
  4265. //for test
  4266. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4267. return result;
  4268. }
  4269. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4270. {
  4271. mtrace();
  4272. int result = FAIL;
  4273. char guid[37]={0};
  4274. char tempdata[65]={0};
  4275. int tempIndex = 0;
  4276. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4277. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4278. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4279. //set value
  4280. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4281. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  4282. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4283. -1);
  4284. random_uuid(guid);
  4285. //UTC Date time
  4286. struct timeval tmnow;
  4287. struct tm *tm;
  4288. char buf[28];//, usec_buf[6];
  4289. gettimeofday(&tmnow, NULL);
  4290. time_t t;
  4291. t = time(NULL);
  4292. /*UTC time and date*/
  4293. tm = gmtime(&t);
  4294. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4295. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4296. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4297. //idx_sample=0;
  4298. //********************************(1)Current.Import L1************************************************/
  4299. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4300. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4301. {
  4302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4303. {
  4304. tempIndex = ((gun_index==2) ? 1: 0);
  4305. }
  4306. else
  4307. {
  4308. tempIndex = gun_index;
  4309. }
  4310. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4311. {
  4312. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4313. {
  4314. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4315. }
  4316. }
  4317. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4318. }
  4319. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4320. {
  4321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4322. {
  4323. tempIndex = ((gun_index==2) ? 1: 0);
  4324. }
  4325. else
  4326. {
  4327. tempIndex = gun_index;
  4328. }
  4329. for (int index = 0; index < CCS_QUANTITY; index++)
  4330. {
  4331. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4332. {
  4333. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4334. }
  4335. }
  4336. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4337. }
  4338. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4339. {
  4340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4341. {
  4342. tempIndex = ((gun_index==2) ? 1: 0);
  4343. }
  4344. else
  4345. {
  4346. tempIndex = gun_index;
  4347. }
  4348. for (int index = 0; index < GB_QUANTITY; index++)
  4349. {
  4350. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4351. {
  4352. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4353. }
  4354. }
  4355. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4356. }
  4357. else if(gunType[gun_index] == GUN_TYPE_DO)
  4358. {
  4359. tempIndex = gun_index;
  4360. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4361. {
  4362. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4363. {
  4364. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4365. }
  4366. }
  4367. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4368. }
  4369. else
  4370. {
  4371. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4372. {
  4373. tempIndex = 2;
  4374. }
  4375. else
  4376. {
  4377. tempIndex = gun_index;
  4378. }
  4379. for (int index = 0; index < AC_QUANTITY; index++)
  4380. {
  4381. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4382. {
  4383. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4384. }
  4385. }
  4386. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4387. }
  4388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4389. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4390. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4391. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4393. //idx_sample=1;
  4394. //********************************(2)Energy.Active.Import.Register ************************************************/
  4395. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4396. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4397. {
  4398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4399. {
  4400. tempIndex = ((gun_index==2) ? 1: 0);
  4401. }
  4402. else
  4403. {
  4404. tempIndex = gun_index;
  4405. }
  4406. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4407. {
  4408. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4409. {
  4410. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4411. }
  4412. }
  4413. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4414. }
  4415. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4416. {
  4417. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4418. {
  4419. tempIndex = ((gun_index==2) ? 1: 0);
  4420. }
  4421. else
  4422. {
  4423. tempIndex = gun_index;
  4424. }
  4425. for (int index = 0; index < CCS_QUANTITY; index++)
  4426. {
  4427. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4428. {
  4429. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4430. }
  4431. }
  4432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4433. }
  4434. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4435. {
  4436. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4437. {
  4438. tempIndex = ((gun_index==2) ? 1: 0);
  4439. }
  4440. else
  4441. {
  4442. tempIndex = gun_index;
  4443. }
  4444. for (int index = 0; index < GB_QUANTITY; index++)
  4445. {
  4446. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4447. {
  4448. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4449. }
  4450. }
  4451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4452. }
  4453. else if(gunType[gun_index] == GUN_TYPE_DO)
  4454. {
  4455. tempIndex = gun_index;
  4456. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4457. {
  4458. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4459. {
  4460. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4461. }
  4462. }
  4463. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4464. }
  4465. else
  4466. {
  4467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4468. {
  4469. tempIndex = 2;
  4470. }
  4471. else
  4472. {
  4473. tempIndex = gun_index;
  4474. }
  4475. for (int index = 0; index < AC_QUANTITY; index++)
  4476. {
  4477. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4478. {
  4479. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4480. }
  4481. }
  4482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4483. }
  4484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4489. //idx_sample=2;
  4490. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4491. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4492. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4493. {
  4494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4495. {
  4496. tempIndex = ((gun_index==2) ? 1: 0);
  4497. }
  4498. else
  4499. {
  4500. tempIndex = gun_index;
  4501. }
  4502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4503. {
  4504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4505. {
  4506. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4507. }
  4508. } // END OF FOR CHAdeMO_QUANTITY
  4509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4510. }
  4511. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4512. {
  4513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4514. {
  4515. tempIndex = ((gun_index==2) ? 1: 0);
  4516. }
  4517. else
  4518. {
  4519. tempIndex = gun_index;
  4520. }
  4521. for (int index = 0; index < CCS_QUANTITY; index++)
  4522. {
  4523. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4524. {
  4525. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4526. }
  4527. } // END OF CCS_QUANTITY
  4528. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4529. }
  4530. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4531. {
  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. for (int index = 0; index < GB_QUANTITY; index++)
  4541. {
  4542. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4543. {
  4544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4545. }
  4546. } // END OF GB_QUANTITY
  4547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4548. }
  4549. else if(gunType[gun_index] == GUN_TYPE_DO)
  4550. {
  4551. tempIndex = gun_index;
  4552. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4553. {
  4554. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4555. {
  4556. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4557. }
  4558. }
  4559. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4560. }
  4561. else
  4562. {
  4563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4564. {
  4565. tempIndex = 2;
  4566. }
  4567. else
  4568. {
  4569. tempIndex = gun_index;
  4570. }
  4571. for (int index = 0; index < AC_QUANTITY; index++)
  4572. {
  4573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4574. {
  4575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4576. }
  4577. }
  4578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4579. }
  4580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4585. //idx_sample=3;
  4586. //********************************(4)Power.Active.Import************************************************/
  4587. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4588. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4589. {
  4590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4591. {
  4592. tempIndex = ((gun_index==2) ? 1: 0);
  4593. }
  4594. else
  4595. {
  4596. tempIndex = gun_index;
  4597. }
  4598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4599. {
  4600. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4601. {
  4602. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4603. }
  4604. } // END OF FOR
  4605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4606. }
  4607. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4608. {
  4609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4610. {
  4611. tempIndex = ((gun_index==2) ? 1: 0);
  4612. }
  4613. else
  4614. {
  4615. tempIndex = gun_index;
  4616. }
  4617. for (int index = 0; index < CCS_QUANTITY; index++)
  4618. {
  4619. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4620. {
  4621. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4622. }
  4623. }
  4624. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4625. }
  4626. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4627. {
  4628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4629. {
  4630. tempIndex = ((gun_index==2) ? 1: 0);
  4631. }
  4632. else
  4633. {
  4634. tempIndex = gun_index;
  4635. }
  4636. for (int index = 0; index < GB_QUANTITY; index++)
  4637. {
  4638. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4639. {
  4640. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4641. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4642. }
  4643. }
  4644. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4645. }
  4646. else if(gunType[gun_index] == GUN_TYPE_DO)
  4647. {
  4648. tempIndex = gun_index;
  4649. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4650. {
  4651. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4652. {
  4653. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4654. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4655. }
  4656. }
  4657. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4658. }
  4659. else
  4660. {
  4661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4662. {
  4663. tempIndex = 2;
  4664. }
  4665. else
  4666. {
  4667. tempIndex = gun_index;
  4668. }
  4669. for (int index = 0; index < AC_QUANTITY; index++)
  4670. {
  4671. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4672. {
  4673. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4674. }
  4675. }
  4676. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4677. }
  4678. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4679. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4683. //idx_sample=4;
  4684. //***********************************************(5)VOLTAGE L1******************************************************/
  4685. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4686. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4687. {
  4688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4689. {
  4690. tempIndex = ((gun_index==2) ? 1: 0);
  4691. }
  4692. else
  4693. {
  4694. tempIndex = gun_index;
  4695. }
  4696. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4697. {
  4698. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4699. {
  4700. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4701. }
  4702. }
  4703. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4704. }
  4705. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4706. {
  4707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4708. {
  4709. tempIndex = ((gun_index==2) ? 1: 0);
  4710. }
  4711. else
  4712. {
  4713. tempIndex = gun_index;
  4714. }
  4715. for (int index = 0; index < CCS_QUANTITY; index++)
  4716. {
  4717. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4718. {
  4719. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4720. }
  4721. }
  4722. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4723. }
  4724. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4725. {
  4726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4727. {
  4728. tempIndex = ((gun_index==2) ? 1: 0);
  4729. }
  4730. else
  4731. {
  4732. tempIndex = gun_index;
  4733. }
  4734. for (int index = 0; index < GB_QUANTITY; index++)
  4735. {
  4736. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4737. {
  4738. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4739. }
  4740. }
  4741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4742. }
  4743. else if(gunType[gun_index] == GUN_TYPE_DO)
  4744. {
  4745. tempIndex = gun_index;
  4746. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4747. {
  4748. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4749. {
  4750. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4751. }
  4752. }
  4753. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4754. }
  4755. else
  4756. {
  4757. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4758. {
  4759. tempIndex = 2;
  4760. }
  4761. else
  4762. {
  4763. tempIndex = gun_index;
  4764. }
  4765. for (int index = 0; index < AC_QUANTITY; index++)
  4766. {
  4767. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4768. {
  4769. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4770. }
  4771. }
  4772. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4773. }
  4774. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4775. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4776. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4777. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4778. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4779. //***********************************************(6)SOC******************************************************/
  4780. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  4781. {
  4782. //idx_sample=5;
  4783. //sampledValue = NULL;
  4784. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4785. {
  4786. tempIndex = ((gun_index==2) ? 1: 0);
  4787. }
  4788. else
  4789. {
  4790. tempIndex = gun_index;
  4791. }
  4792. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4793. {
  4794. //tempIndex = ((gun_index==2) ? 1: 0);
  4795. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4796. {
  4797. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4798. {
  4799. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4800. }
  4801. }
  4802. }
  4803. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4804. {
  4805. //tempIndex = ((gun_index==2) ? 1: 0);
  4806. for (int index = 0; index < CCS_QUANTITY; index++)
  4807. {
  4808. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4809. {
  4810. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4811. }
  4812. }
  4813. }
  4814. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4815. {
  4816. //tempIndex = ((gun_index==2) ? 1: 0);
  4817. for (int index = 0; index < GB_QUANTITY; index++)
  4818. {
  4819. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4820. {
  4821. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4822. }
  4823. }
  4824. }
  4825. else if(gunType[gun_index] == GUN_TYPE_DO)
  4826. {
  4827. //tempIndex = ((gun_index==2) ? 1: 0);
  4828. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4829. {
  4830. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4831. {
  4832. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4833. }
  4834. }
  4835. }
  4836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  4837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4840. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  4841. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4842. }
  4843. //********************************(7)Current.Import L2************************************************/
  4844. // Only for AC 3 phase
  4845. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4846. {
  4847. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4848. {
  4849. tempIndex = 2;
  4850. }
  4851. else
  4852. {
  4853. tempIndex = gun_index;
  4854. }
  4855. for (int index = 0; index < AC_QUANTITY; index++)
  4856. {
  4857. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4858. {
  4859. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4860. }
  4861. }
  4862. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4863. }
  4864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4865. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4866. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4867. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4868. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4869. //********************************(8)Current.Import L3************************************************/
  4870. // Only for AC 3 phase
  4871. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4872. {
  4873. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4874. {
  4875. tempIndex = 2;
  4876. }
  4877. else
  4878. {
  4879. tempIndex = gun_index;
  4880. }
  4881. for (int index = 0; index < AC_QUANTITY; index++)
  4882. {
  4883. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4884. {
  4885. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4886. }
  4887. }
  4888. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4889. }
  4890. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4891. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4892. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4893. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4894. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4895. //***********************************************(9)VOLTAGE L2******************************************************/
  4896. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4897. {
  4898. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4899. {
  4900. tempIndex = 2;
  4901. }
  4902. else
  4903. {
  4904. tempIndex = gun_index;
  4905. }
  4906. for (int index = 0; index < AC_QUANTITY; index++)
  4907. {
  4908. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4909. {
  4910. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4911. }
  4912. }
  4913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4914. }
  4915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4920. //***********************************************(10)VOLTAGE L3******************************************************/
  4921. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4922. {
  4923. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4924. {
  4925. tempIndex = 2;
  4926. }
  4927. else
  4928. {
  4929. tempIndex = gun_index;
  4930. }
  4931. for (int index = 0; index < AC_QUANTITY; index++)
  4932. {
  4933. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4934. {
  4935. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4936. }
  4937. }
  4938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4939. }
  4940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4941. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4942. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4943. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4944. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4945. // Message create ====================================================================================================
  4946. if(TRUE)
  4947. {
  4948. json_object *MeterValueReq = json_object_new_object();
  4949. json_object *MeterValues = json_object_new_array();
  4950. json_object *sampledValues = json_object_new_array();
  4951. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  4952. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  4953. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  4954. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  4955. {
  4956. json_object *MeterValue = json_object_new_object();
  4957. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  4958. {
  4959. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  4960. {
  4961. json_object *sampledValue = json_object_new_object();
  4962. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  4963. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  4964. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  4965. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  4966. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  4967. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  4968. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  4969. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  4970. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  4971. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  4972. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  4973. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  4974. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  4975. json_object_array_add(sampledValues, sampledValue);
  4976. }
  4977. }
  4978. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  4979. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  4980. json_object_array_add(MeterValues, MeterValue);
  4981. }
  4982. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  4983. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  4984. ,gun_index + 1
  4985. ,MESSAGE_TYPE_CALL
  4986. ,guid
  4987. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  4988. json_object_put(MeterValueReq);
  4989. }
  4990. // Put request guid to hash map
  4991. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4992. 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*/)
  4993. {
  4994. result = PASS;
  4995. //DEBUG_INFO("MeterValues mapitem pass\n");
  4996. }
  4997. if((dataType != ReadingContext_Trigger) &&
  4998. (dataType != ReadingContext_Sample_Clock) &&
  4999. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5000. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5001. else
  5002. {
  5003. if(FirstHeartBeat)
  5004. LWS_Send(queuedata +2);
  5005. }
  5006. return result;
  5007. }
  5008. //==========================================
  5009. // send confirm routine
  5010. //==========================================
  5011. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5012. {
  5013. mtrace();
  5014. int result = FAIL;
  5015. char message[100]={0};
  5016. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5017. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5018. LWS_Send(message);
  5019. result = TRUE;
  5020. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5021. return result;
  5022. }
  5023. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5024. {
  5025. mtrace();
  5026. int result = FAIL;
  5027. char message[100]={0};
  5028. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5029. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5030. LWS_Send(message);
  5031. result = TRUE;
  5032. return result;
  5033. }
  5034. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5035. {
  5036. mtrace();
  5037. int result = FAIL;
  5038. char message[100]={0};
  5039. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5040. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5041. LWS_Send(message);
  5042. result = TRUE;
  5043. return result;
  5044. }
  5045. int sendClearCacheConfirmation(char *uuid,char *payload)
  5046. {
  5047. mtrace();
  5048. int result = FAIL;
  5049. char message[500]={0};
  5050. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5051. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5052. LWS_Send(message);
  5053. return result;
  5054. }
  5055. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5056. {
  5057. mtrace();
  5058. int result = FAIL;
  5059. char message[500]={0};
  5060. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5061. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5062. LWS_Send(message);
  5063. return result;
  5064. }
  5065. int sendDataTransferConfirmation(char *uuid,char *payload)
  5066. {
  5067. mtrace();
  5068. char statusStr[20]={0};
  5069. char dataStr[10]={0};
  5070. char sstr[20]={0};
  5071. int c = 0;
  5072. char *loc;
  5073. int result = FAIL;
  5074. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5075. /**********************status**************************/
  5076. loc = strstr(payload, "status");
  5077. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5078. c = 0;
  5079. while (loc[3+strlen("status")+c] != '\"')
  5080. {
  5081. sstr[c] = loc[3+strlen("status")+c];
  5082. c++;
  5083. }
  5084. sstr[c] = '\0';
  5085. strcpy(statusStr, sstr);
  5086. /**********************data**************************/
  5087. loc = strstr(payload, "data");
  5088. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5089. c = 0;
  5090. while (loc[3+strlen("data")+c] != '\"')
  5091. {
  5092. sstr[c] = loc[3+strlen("data")+c];
  5093. c++;
  5094. }
  5095. sstr[c] = '\0';
  5096. strcpy(dataStr, sstr);
  5097. return result;
  5098. }
  5099. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5100. {
  5101. mtrace();
  5102. int result = FAIL;
  5103. char message[1000]={0};
  5104. int CompositeScheduleIndex = 0;
  5105. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5106. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5107. if(nPeriod == 0)
  5108. {
  5109. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5110. {
  5111. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5112. ,MESSAGE_TYPE_CALLRESULT
  5113. ,uuid
  5114. ,payload
  5115. ,connectorIdInt);
  5116. }
  5117. else
  5118. {
  5119. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5120. ,MESSAGE_TYPE_CALLRESULT
  5121. ,uuid
  5122. ,payload
  5123. ,connectorIdInt
  5124. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5125. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5126. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5127. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5128. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5129. }
  5130. }
  5131. else
  5132. {
  5133. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5134. ,MESSAGE_TYPE_CALLRESULT
  5135. ,uuid
  5136. ,payload
  5137. ,connectorIdInt
  5138. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5139. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5140. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5141. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5142. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5143. {
  5144. if (idx_sample == 0)
  5145. {
  5146. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5147. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5148. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5149. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5150. }
  5151. else
  5152. {
  5153. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5154. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5155. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5156. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5157. }
  5158. }
  5159. sprintf(message + strlen(message), "]}}]");
  5160. }
  5161. LWS_Send(message);
  5162. result = TRUE;
  5163. return result;
  5164. }
  5165. int sendGetConfigurationConfirmation(char *uuid)
  5166. {
  5167. mtrace();
  5168. int result = FAIL;
  5169. int MaxKeySupported = 0;
  5170. int sentConfigurationNumber= 0;
  5171. int sentunConfigurationNumber= 0;
  5172. char message[4000]={0};
  5173. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5174. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5175. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5176. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5177. ,MESSAGE_TYPE_CALLRESULT
  5178. ,uuid );
  5179. //configuration key
  5180. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5181. {
  5182. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5183. {
  5184. if (sentConfigurationNumber == 0)
  5185. {
  5186. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5187. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5188. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5189. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5190. }
  5191. else
  5192. {
  5193. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5194. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5195. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5196. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5197. }
  5198. sentConfigurationNumber = sentConfigurationNumber + 1;
  5199. }
  5200. }
  5201. sprintf(message + strlen(message), "]");
  5202. if(UnknownKeynum != 0)
  5203. {
  5204. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5205. //unkown key
  5206. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5207. {
  5208. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5209. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5210. if(sentunConfigurationNumber == 0)
  5211. {
  5212. sprintf(message + strlen(message), "\"%s\""
  5213. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5214. }
  5215. else
  5216. {
  5217. sprintf(message + strlen(message), ",\"%s\""
  5218. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5219. }
  5220. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5221. }
  5222. sprintf(message + strlen(message), "]");
  5223. }
  5224. sprintf(message + strlen(message), "}]");
  5225. LWS_Send(message);
  5226. return result;
  5227. }
  5228. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5229. {
  5230. mtrace();
  5231. int result = FAIL;
  5232. char message[400]={0};
  5233. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5234. if(strcmp(payload,"")==0)
  5235. {
  5236. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5237. }
  5238. else
  5239. {
  5240. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5241. }
  5242. LWS_Send(message);
  5243. result = TRUE;
  5244. return result;
  5245. }
  5246. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5247. {
  5248. mtrace();
  5249. int result = FAIL;
  5250. char message[80]={0};
  5251. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5252. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5253. LWS_Send(message);
  5254. result = TRUE;
  5255. return result;
  5256. }
  5257. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5258. {
  5259. mtrace();
  5260. int result = FAIL;
  5261. char message[80]={0};
  5262. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5263. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5264. LWS_Send(message);
  5265. result = TRUE;
  5266. return result;
  5267. }
  5268. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5269. {
  5270. mtrace();
  5271. int result = FAIL;
  5272. char message[80]={0};
  5273. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5274. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5275. LWS_Send(message);
  5276. result = TRUE;
  5277. return result;
  5278. }
  5279. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5280. {
  5281. mtrace();
  5282. int result = FAIL;
  5283. char message[80]={0};
  5284. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5285. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5286. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5287. LWS_Send(message);
  5288. result = TRUE;
  5289. return result;
  5290. }
  5291. int sendResetConfirmation(char *uuid,char *payload)
  5292. {
  5293. mtrace();
  5294. int result = FAIL;
  5295. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5296. char message[80]={0};
  5297. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5298. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5299. LWS_Send(message);
  5300. result = TRUE;
  5301. return result;
  5302. }
  5303. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5304. {
  5305. mtrace();
  5306. int result = FAIL;
  5307. char message[500]={0};
  5308. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5309. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5310. LWS_Send(message);
  5311. result = TRUE;
  5312. return result;
  5313. }
  5314. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5315. {
  5316. mtrace();
  5317. int result = FAIL;
  5318. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5319. char message[80]={0};
  5320. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5321. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5322. LWS_Send(message);
  5323. result = TRUE;
  5324. return result;
  5325. }
  5326. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5327. {
  5328. mtrace();
  5329. int result = FAIL;
  5330. char message[80]={0};
  5331. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5332. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5333. LWS_Send(message);
  5334. result = TRUE;
  5335. return result;
  5336. }
  5337. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5338. {
  5339. mtrace();
  5340. int result = FAIL;
  5341. char message[80]={0};
  5342. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5343. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5344. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5345. LWS_Send(message);
  5346. result = TRUE;
  5347. return result;
  5348. }
  5349. int sendUpdateFirmwareConfirmation(char *uuid)
  5350. {
  5351. mtrace();
  5352. int result = FAIL;
  5353. char message[60]={0};
  5354. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5355. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5356. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5357. LWS_Send(message);
  5358. result = TRUE;
  5359. return result;
  5360. }
  5361. //==========================================
  5362. // send CallError routine
  5363. //==========================================
  5364. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5365. {
  5366. mtrace();
  5367. char message[220]={0};
  5368. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5369. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5370. LWS_Send(message);
  5371. }
  5372. //==========================================
  5373. // Handle server request routine Start
  5374. //==========================================
  5375. int handleCancelReservationRequest(char *uuid, char *payload)
  5376. {
  5377. mtrace();
  5378. int result = FAIL;
  5379. int gunNO = 0;
  5380. int reservationIdInt = -1;
  5381. char comfirmstr[20];
  5382. DEBUG_INFO("handleCancelReservationRequest...\n");
  5383. json_object *CancelReservation;
  5384. CancelReservation = json_tokener_parse(payload);
  5385. if(!is_error(CancelReservation))
  5386. {
  5387. // Required data
  5388. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5389. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5390. }
  5391. json_object_put(CancelReservation);
  5392. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5393. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5394. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5395. if(reservationIdInt != -1)
  5396. {
  5397. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5398. //check Transaction active
  5399. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5401. {
  5402. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5403. {
  5404. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5405. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5406. if(gunType[2] == GUN_TYPE_CHAdeMO)
  5407. {
  5408. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5409. }
  5410. else
  5411. {
  5412. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5413. }
  5414. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5415. goto end;
  5416. }
  5417. }
  5418. for (int index = 0; index < CCS_QUANTITY; index++)
  5419. {
  5420. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5421. {
  5422. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5423. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5424. if(gunType[2] == GUN_TYPE_CCS)
  5425. {
  5426. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5427. }
  5428. else
  5429. {
  5430. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5431. }
  5432. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5433. goto end;
  5434. }
  5435. }
  5436. for (int index = 0; index < GB_QUANTITY; index++)
  5437. {
  5438. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5439. {
  5440. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5441. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5442. if(gunType[2] == GUN_TYPE_GBT)
  5443. {
  5444. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5445. }
  5446. else
  5447. {
  5448. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5449. }
  5450. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5451. goto end;
  5452. }
  5453. }
  5454. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5455. {
  5456. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5457. {
  5458. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5459. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5460. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5461. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5462. goto end;
  5463. }
  5464. }
  5465. for (int index = 0; index < AC_QUANTITY; index++)
  5466. {
  5467. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5468. {
  5469. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5470. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5471. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5472. {
  5473. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5474. }
  5475. else
  5476. {
  5477. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5478. }
  5479. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5480. goto end;
  5481. }
  5482. }
  5483. }
  5484. //The reservationId does NOT match the reservationId
  5485. sendCancelReservationConfirmation(uuid, comfirmstr);
  5486. end:
  5487. // Fill in ocpp packet uuid
  5488. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5489. return result;
  5490. }
  5491. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5492. {
  5493. mtrace();
  5494. int result = FAIL;
  5495. int gunIndex = 0;
  5496. char typeStr[16]={0};
  5497. char comfirmstr[20];
  5498. int specificId = FALSE;
  5499. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5500. json_object *ChangeAvailability;
  5501. ChangeAvailability = json_tokener_parse(payload);
  5502. if(!is_error(ChangeAvailability))
  5503. {
  5504. // Required data
  5505. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5506. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5507. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5508. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5509. }
  5510. json_object_put(ChangeAvailability);
  5511. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5512. {
  5513. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5514. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5515. }
  5516. else if(gunIndex == 0)
  5517. {
  5518. for(int i=0; i < gunTotalNumber; i++)
  5519. {
  5520. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5521. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5522. }
  5523. }
  5524. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5525. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5526. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5527. {
  5528. specificId = TRUE;
  5529. }
  5530. if(specificId == FALSE)
  5531. goto end;
  5532. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5533. {
  5534. //----------------------gunIndex is 0 ------------------------------------------------//
  5535. if(gunIndex == 0)
  5536. {
  5537. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5538. {
  5539. for(int i=0; i < gunTotalNumber; i++)
  5540. {
  5541. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5542. {
  5543. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5544. {
  5545. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5546. {
  5547. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5548. goto end;
  5549. }
  5550. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5551. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5552. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5553. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5554. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5555. {
  5556. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5557. goto end;
  5558. }
  5559. }
  5560. }//END FOR CHAdeMO_QUANTITY
  5561. for (int index = 0; index < CCS_QUANTITY; index++)
  5562. {
  5563. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5564. {
  5565. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5566. {
  5567. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5568. goto end;
  5569. }
  5570. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5571. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5572. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5573. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5574. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5575. {
  5576. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5577. goto end;
  5578. }
  5579. }
  5580. }//END FOR CCS_QUANTITY
  5581. for (int index = 0; index < GB_QUANTITY; index++)
  5582. {
  5583. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5584. {
  5585. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5586. {
  5587. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5588. goto end;
  5589. }
  5590. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5591. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5592. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5593. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5594. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5595. {
  5596. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5597. goto end;
  5598. }
  5599. }
  5600. }// END FOR GB_QUANTITY
  5601. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5602. {
  5603. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5604. {
  5605. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5606. {
  5607. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5608. goto end;
  5609. }
  5610. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5611. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5612. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5613. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5614. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5615. {
  5616. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5617. goto end;
  5618. }
  5619. }
  5620. }// END FOR GENERAL_GUN_QUANTITY
  5621. for (int index = 0; index < AC_QUANTITY; index++)
  5622. {
  5623. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5624. {
  5625. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5626. {
  5627. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5628. goto end;
  5629. }
  5630. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5631. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5632. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5633. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5634. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5635. {
  5636. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5637. goto end;
  5638. }
  5639. }
  5640. }//END FOR AC_QUANTITY
  5641. }// END FOR gunTotalNumber
  5642. }
  5643. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5644. {
  5645. for(int i=0; i < gunTotalNumber; i++)
  5646. {
  5647. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5648. {
  5649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5650. goto end;
  5651. }
  5652. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5653. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5654. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5655. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5656. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5657. {
  5658. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5659. goto end;
  5660. }
  5661. }
  5662. }
  5663. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5664. goto end;
  5665. }
  5666. //----------------------gunIndex is not 0 ------------------------------------------------//
  5667. //check Transaction active
  5668. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5669. {
  5670. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  5671. {
  5672. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5673. {
  5674. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5675. goto end;
  5676. }
  5677. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5678. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5679. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5680. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5681. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5682. {
  5683. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5684. goto end;
  5685. }
  5686. else
  5687. {
  5688. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5689. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5690. goto end;
  5691. }
  5692. }
  5693. }//END FOR CHAdeMO_QUANTITY
  5694. for (int index = 0; index < CCS_QUANTITY; index++)
  5695. {
  5696. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  5697. {
  5698. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5699. {
  5700. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5701. goto end;
  5702. }
  5703. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5704. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5705. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5706. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5707. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5708. {
  5709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5710. goto end;
  5711. }
  5712. else
  5713. {
  5714. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5715. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5716. goto end;
  5717. }
  5718. }
  5719. }//END FOR CCS_QUANTITY
  5720. for (int index = 0; index < GB_QUANTITY; index++)
  5721. {
  5722. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  5723. {
  5724. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5725. {
  5726. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5727. goto end;
  5728. }
  5729. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5730. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5731. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5732. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5733. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5734. {
  5735. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5736. goto end;
  5737. }
  5738. else
  5739. {
  5740. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5741. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5742. goto end;
  5743. }
  5744. }
  5745. }// END FOR GB_QUANTITY
  5746. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5747. {
  5748. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  5749. {
  5750. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5751. {
  5752. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5753. goto end;
  5754. }
  5755. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5756. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5757. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5758. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5759. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5760. {
  5761. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5762. goto end;
  5763. }
  5764. else
  5765. {
  5766. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5767. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5768. goto end;
  5769. }
  5770. }
  5771. }// END FOR GENERAL_GUN_QUANTITY
  5772. for (int index = 0; index < AC_QUANTITY; index++)
  5773. {
  5774. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  5775. {
  5776. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5777. {
  5778. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5779. goto end;
  5780. }
  5781. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5782. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5783. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5784. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5785. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5786. {
  5787. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5788. goto end;
  5789. }
  5790. else
  5791. {
  5792. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5793. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5794. goto end;
  5795. }
  5796. }
  5797. }//END FOR AC_QUANTITY
  5798. }//END FOR AvailabilityTypeStr[Inoperative]
  5799. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5800. {
  5801. //----------------------gunIndex is 0 ------------------------------------------------//
  5802. if(gunIndex == 0)
  5803. {
  5804. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5805. {
  5806. for(int i=0; i < gunTotalNumber; i++)
  5807. {
  5808. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5809. {
  5810. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5811. {
  5812. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5813. goto end;
  5814. }
  5815. }//END FOR CHAdeMO_QUANTITY
  5816. for (int index = 0; index < CCS_QUANTITY; index++)
  5817. {
  5818. if ((gunType[i] == GUN_TYPE_CCS)&&(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
  5819. {
  5820. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5821. goto end;
  5822. }
  5823. }//END FOR CCS_QUANTITY
  5824. for (int index = 0; index < GB_QUANTITY; index++)
  5825. {
  5826. if ((gunType[i] == GUN_TYPE_GBT)&&(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
  5827. {
  5828. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5829. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5830. goto end;
  5831. }
  5832. }// END FOR GB_QUANTITY
  5833. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5834. {
  5835. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5836. {
  5837. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5838. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5839. goto end;
  5840. }
  5841. }// END FOR GENERAL_GUN_QUANTITY
  5842. for (int index = 0; index < AC_QUANTITY; index++)
  5843. {
  5844. if ((gunType[i] == GUN_TYPE_AC) &&(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
  5845. {
  5846. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5847. goto end;
  5848. }
  5849. }//END FOR CHAdeMO_QUANTITY
  5850. }// END FOR gunTotalNumber
  5851. }
  5852. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5853. {
  5854. for(int i=0; i < gunTotalNumber; i++)
  5855. {
  5856. for (int index = 0; index < AC_QUANTITY; index++)
  5857. {
  5858. if ((gunType[i] == GUN_TYPE_AC) &&(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
  5859. {
  5860. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5861. goto end;
  5862. }
  5863. }//END FOR CHAdeMO_QUANTITY
  5864. } // END FOR gunTotalNumber
  5865. }
  5866. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5867. goto end;
  5868. }
  5869. //----------------------gunIndex is not 0 ------------------------------------------------//
  5870. //check Transaction active
  5871. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5872. {
  5873. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5874. {
  5875. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5876. goto end;
  5877. }
  5878. }//END FOR CHAdeMO_QUANTITY
  5879. for (int index = 0; index < CCS_QUANTITY; index++)
  5880. {
  5881. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5882. {
  5883. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5884. goto end;
  5885. }
  5886. }//END FOR CCS_QUANTITY
  5887. for (int index = 0; index < GB_QUANTITY; index++)
  5888. {
  5889. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5890. {
  5891. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5892. goto end;
  5893. }
  5894. }// END FOR GB_QUANTITY
  5895. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5896. {
  5897. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5898. {
  5899. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5900. goto end;
  5901. }
  5902. }// END FOR GENERAL_GUN_QUANTITY
  5903. for (int index = 0; index < AC_QUANTITY; index++)
  5904. {
  5905. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5906. {
  5907. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5908. goto end;
  5909. }
  5910. }//END FOR AC_QUANTITY
  5911. }//END FOR AvailabilityTypeStr[Operative]
  5912. end:
  5913. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5914. {
  5915. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5916. }
  5917. else
  5918. {
  5919. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5920. }
  5921. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5922. {
  5923. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5924. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5925. }
  5926. else if(gunIndex == 0)
  5927. {
  5928. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5929. {
  5930. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5931. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5932. }
  5933. }
  5934. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5935. return result;
  5936. }
  5937. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5938. {
  5939. mtrace();
  5940. int result = FAIL;
  5941. char keystr[40]={0};
  5942. char valuestr[100]={0};
  5943. char comfirmstr[20]={0};
  5944. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5945. json_object *ChangeConfiguration;
  5946. ChangeConfiguration = json_tokener_parse(payload);
  5947. if(!is_error(ChangeConfiguration))
  5948. {
  5949. // Required data
  5950. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  5951. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5952. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  5953. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5954. }
  5955. json_object_put(ChangeConfiguration);
  5956. if((uuid==NULL) || (payload ==NULL) )
  5957. {
  5958. DEBUG_ERROR("Payload is null\n");
  5959. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5960. }
  5961. else
  5962. {
  5963. int status = setKeyValue(keystr, valuestr);
  5964. switch(status)
  5965. {
  5966. case ConfigurationStatus_Accepted:
  5967. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5968. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5969. StoreConfigurationTable();
  5970. break;
  5971. case RebootRequired:
  5972. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5973. StoreConfigurationTable();
  5974. break;
  5975. case NotSupported:
  5976. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5977. break;
  5978. case ConfigurationStatus_Rejected:
  5979. default:
  5980. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5981. break;
  5982. }
  5983. }
  5984. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5985. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5986. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5987. {
  5988. ChageWebSocketPingInterval(atoi(valuestr));
  5989. }
  5990. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5991. {
  5992. SetOcppConnStatus(FALSE);
  5993. }
  5994. return result;
  5995. }
  5996. int handleClearCacheRequest(char *uuid, char *payload)
  5997. {
  5998. mtrace();
  5999. int result = FAIL;
  6000. char comfirmstr[20];
  6001. char rmFileCmd[100]={0};
  6002. struct stat stats;
  6003. DEBUG_INFO("handleClearCacheRequest...\n");
  6004. stat("/Storage/OCPP", &stats);
  6005. // Check for directory existence
  6006. if (S_ISDIR(stats.st_mode) == 1)
  6007. {}
  6008. else
  6009. {
  6010. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6011. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6012. system(rmFileCmd);
  6013. }
  6014. if(OCPP_cleanLocalCache())
  6015. {
  6016. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6017. }
  6018. else
  6019. {
  6020. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6021. }
  6022. sendClearCacheConfirmation(uuid, comfirmstr);
  6023. return result;
  6024. }
  6025. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6026. {
  6027. mtrace();
  6028. int result = FAIL;
  6029. int resultRename;
  6030. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6031. char chargingProfilePurposeStr[26]={0};
  6032. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6033. char tempchargingProfilePurposeStr[26]={0};
  6034. char str[100]={0};
  6035. char fname[200]={0};
  6036. char comfirmstr[20]={0};
  6037. char word[1600]={0};
  6038. int clearflag = FALSE;
  6039. int chargingProfileIdIsNULL = FALSE;
  6040. int connectorIsNULL = FALSE;
  6041. int chargingProfilePurposeIsNULL = FALSE;
  6042. int stackLevelIsNULL = FALSE;
  6043. //int GotoEnd = FALSE;
  6044. FILE *fptr1, *fptr2;
  6045. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6046. int n_chargingProfile=0;
  6047. int isEmptyFile = FALSE;
  6048. char sLineWord[1600]={0};
  6049. char chargingProfiles[10][100]={0};
  6050. int ChargeProfileCount = 0;
  6051. int ch;
  6052. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6053. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6054. json_object *ClearChargingProfile;
  6055. ClearChargingProfile = json_tokener_parse(payload);
  6056. if(!is_error(ClearChargingProfile))
  6057. {
  6058. // Optional data
  6059. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6060. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6061. else
  6062. chargingProfileIdIsNULL = TRUE;
  6063. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6064. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6065. else
  6066. connectorIsNULL = TRUE;
  6067. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6068. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6069. else
  6070. chargingProfilePurposeIsNULL = TRUE;
  6071. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6072. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6073. else
  6074. stackLevelIsNULL = TRUE;
  6075. }
  6076. json_object_put(ClearChargingProfile);
  6077. if(connectorIsNULL == FALSE)
  6078. {
  6079. switch(connectorIdInt)
  6080. {
  6081. case 0:
  6082. if(chargingProfilePurposeIsNULL == TRUE)
  6083. {
  6084. int l = 0;
  6085. strcpy(fname, ChargePointMaxProfile_JSON);
  6086. if((access(fname,F_OK))!=-1)
  6087. {
  6088. strcpy(chargingProfiles[l], fname);
  6089. l = l + 1;
  6090. }
  6091. strcpy(fname, TxDefaultProfile_0_JSON);
  6092. if((access(fname,F_OK))!=-1)
  6093. {
  6094. strcpy(chargingProfiles[l], fname);
  6095. l = l + 1;
  6096. }
  6097. ChargeProfileCount = l;
  6098. }
  6099. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6100. {
  6101. strcpy(fname, ChargePointMaxProfile_JSON);
  6102. if((access(fname,F_OK))!=-1)
  6103. {
  6104. strcpy(chargingProfiles[0], fname);
  6105. ChargeProfileCount = 1;
  6106. }
  6107. }
  6108. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6109. {
  6110. strcpy(fname, TxDefaultProfile_0_JSON);
  6111. if((access(fname,F_OK))!=-1)
  6112. {
  6113. strcpy(chargingProfiles[0], fname);
  6114. ChargeProfileCount = 1;
  6115. }
  6116. }
  6117. break;
  6118. default:
  6119. if(chargingProfilePurposeIsNULL == TRUE)
  6120. {
  6121. int m = 0;
  6122. memset(fname, 0, ARRAY_SIZE(fname));
  6123. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6124. if((access(fname,F_OK))!=-1)
  6125. {
  6126. strcpy(chargingProfiles[m], fname);
  6127. m = m + 1;
  6128. }
  6129. memset(fname, 0, ARRAY_SIZE(fname));
  6130. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6131. if((access(fname,F_OK))!=-1)
  6132. {
  6133. strcpy(chargingProfiles[m], fname);
  6134. m = m + 1;
  6135. }
  6136. ChargeProfileCount = m;
  6137. }
  6138. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6139. {
  6140. //strcpy(fname, TxDefaultProfile_1_JSON);
  6141. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6142. if((access(fname,F_OK))!=-1)
  6143. {
  6144. strcpy(chargingProfiles[0], fname);
  6145. ChargeProfileCount = 1;
  6146. }
  6147. }
  6148. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6149. {
  6150. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6151. if((access(fname,F_OK))!=-1)
  6152. {
  6153. strcpy(chargingProfiles[0], fname);
  6154. ChargeProfileCount = 1;
  6155. }
  6156. //strcpy(fname, TxProfile_1_JSON);
  6157. }
  6158. //strcpy(fname, ChargePointMaxProfile_JSON );
  6159. break;
  6160. }
  6161. }
  6162. else // Check all Charging Profiles
  6163. {
  6164. int i = 0;
  6165. char fnametemp[200]={0};
  6166. ChargeProfileCount = 0;
  6167. //Check ChargePointMaxProfile.json exit
  6168. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6169. {
  6170. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6171. i = i + 1;
  6172. }
  6173. //Check TxDefaultProfile_0.json exit
  6174. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6175. {
  6176. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6177. i = i + 1;
  6178. }
  6179. //Check TxDefaultProfile_%d.json
  6180. for(int j=1; j <= gunTotalNumber; j++)
  6181. {
  6182. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6183. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6184. if((access(fnametemp,F_OK))!=-1)
  6185. {
  6186. strcpy(chargingProfiles[i], fnametemp);
  6187. i = i + 1;
  6188. }
  6189. }
  6190. //Check TxProfile_%d.json
  6191. for(int j=1; j <= gunTotalNumber; j++)
  6192. {
  6193. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6194. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6195. if((access(fnametemp,F_OK))!=-1)
  6196. {
  6197. strcpy(chargingProfiles[i], fnametemp);
  6198. i = i + 1;
  6199. }
  6200. }
  6201. ChargeProfileCount = i;
  6202. }// End connectorIsNULL is TRUE
  6203. if(ChargeProfileCount == 0)
  6204. {
  6205. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6206. goto end;
  6207. }
  6208. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6209. {
  6210. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6211. goto end;
  6212. }
  6213. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6214. {
  6215. memset(str, 0, ARRAY_SIZE(str));
  6216. // clear temp file
  6217. sprintf(str,"rm -f %s",temp);
  6218. system(str);
  6219. for(int k=0; k < ChargeProfileCount; k++)
  6220. {
  6221. memset(str, 0, ARRAY_SIZE(str));
  6222. //clear file in C
  6223. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6224. system(str);
  6225. }
  6226. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6227. goto end;
  6228. }
  6229. else if(connectorIsNULL == TRUE)
  6230. {
  6231. for(int k=0; k < ChargeProfileCount; k++)
  6232. {
  6233. fptr1 = fopen(chargingProfiles[k], "r");
  6234. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6235. //Check Charging Profile Count
  6236. while(fscanf(fptr1, "%s", word) != EOF)
  6237. {
  6238. //DEBUG_INFO("word=%s\n",word);
  6239. if(strstr(word, "chargingProfileId")!= NULL)
  6240. {
  6241. //DEBUG_INFO("test chargingProfileId \n");
  6242. n_chargingProfile = n_chargingProfile + 1;
  6243. //DEBUG_INFO("chargingProfileId Found\n");
  6244. }
  6245. }
  6246. rewind(fptr1);
  6247. //search Charging Profile Element
  6248. //int i= 0;
  6249. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6250. {
  6251. json_object *tmpProfilee;
  6252. tmpProfilee = json_tokener_parse(sLineWord);
  6253. if(!is_error(tmpProfilee))
  6254. {
  6255. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6256. {
  6257. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6258. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6259. }
  6260. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6261. {
  6262. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6263. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6264. }
  6265. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6266. {
  6267. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6268. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6269. }
  6270. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6271. {
  6272. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6273. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6274. }
  6275. }
  6276. json_object_put(tmpProfilee);
  6277. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6278. {
  6279. //------- not write to fptr2-------//
  6280. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6281. //clearflag = TRUE;
  6282. }
  6283. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6284. {
  6285. //------- not write to fptr2-------//
  6286. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6287. }
  6288. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6289. {
  6290. //------- not write to fptr2-------//
  6291. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6292. }
  6293. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6294. {
  6295. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6296. }
  6297. else
  6298. {
  6299. fprintf(fptr2, sLineWord);//writing data into file
  6300. }
  6301. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6302. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  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. memset(str, 0, ARRAY_SIZE(str));
  6318. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6319. system(str);
  6320. resultRename = rename(temp, chargingProfiles[k]);
  6321. if(resultRename == 0)
  6322. {
  6323. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6324. }
  6325. else
  6326. {
  6327. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6328. }
  6329. if(comfirmstr[0]== 0)
  6330. {
  6331. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6332. }
  6333. //Check chargingProfile is empty file
  6334. /*------ Read the file ----------------*/
  6335. fptr1=fopen(chargingProfiles[k],"r");
  6336. ch=fgetc(fptr1);
  6337. rewind(fptr1);
  6338. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6339. if(ch!=EOF)
  6340. {
  6341. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6342. {
  6343. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6344. if(sLineWord[0]=='\0')
  6345. {
  6346. isEmptyFile = TRUE;
  6347. break;
  6348. }
  6349. else
  6350. {
  6351. isEmptyFile = FALSE;
  6352. break;
  6353. }
  6354. }
  6355. }
  6356. else
  6357. isEmptyFile = TRUE;
  6358. fclose(fptr1);
  6359. if(isEmptyFile == TRUE)
  6360. {
  6361. memset(str, 0, ARRAY_SIZE(str));
  6362. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6363. system(str);
  6364. }
  6365. }
  6366. }// End of while(int k=0; k < ChargePointCount; k++)
  6367. }
  6368. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6369. {
  6370. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6371. for(int k=0; k < ChargeProfileCount; k++)
  6372. {
  6373. fptr1 = fopen(chargingProfiles[k], "r");
  6374. fptr2 = fopen(temp, "w+");
  6375. //Check Charging Profile Count
  6376. while(fscanf(fptr1, "%s", word) != EOF)
  6377. {
  6378. //DEBUG_INFO("word=%s\n",word);
  6379. if(strstr(word, "chargingProfileId")!= NULL)
  6380. {
  6381. n_chargingProfile = n_chargingProfile + 1;
  6382. }
  6383. }
  6384. rewind(fptr1);
  6385. //search Charging Profile Element
  6386. //int i= 0;
  6387. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6388. {
  6389. json_object *tmpProfilee;
  6390. tmpProfilee = json_tokener_parse(sLineWord);
  6391. if(!is_error(tmpProfilee))
  6392. {
  6393. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6394. {
  6395. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6396. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6397. }
  6398. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6399. {
  6400. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6401. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6402. }
  6403. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6404. {
  6405. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6406. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6407. }
  6408. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6409. {
  6410. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6411. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6412. }
  6413. }
  6414. json_object_put(tmpProfilee);
  6415. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6416. {
  6417. //------- not write to fptr2-------//
  6418. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6419. //clearflag = TRUE;
  6420. }
  6421. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6422. {
  6423. //------- not write to fptr2-------//
  6424. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6425. }
  6426. else if(stackLevelIsNULL == TRUE)
  6427. {
  6428. //Clear Whole File
  6429. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6430. clearflag = TRUE;
  6431. break;
  6432. }
  6433. else
  6434. {
  6435. fprintf(fptr2, sLineWord);//writing data into file
  6436. }
  6437. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6438. }
  6439. if(clearflag == TRUE)
  6440. {
  6441. fclose(fptr1);
  6442. fclose(fptr2);
  6443. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6444. system(str);
  6445. // clear temp file
  6446. sprintf(str,"rm -f %s",temp);
  6447. system(str);
  6448. }
  6449. else
  6450. {
  6451. fclose(fptr1);
  6452. fclose(fptr2);
  6453. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6454. system(str);
  6455. resultRename = rename(temp, chargingProfiles[k]);
  6456. if(resultRename == 0)
  6457. {
  6458. DEBUG_INFO("File ChargingProfile renamed successfully");
  6459. }
  6460. else
  6461. {
  6462. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6463. }
  6464. if(comfirmstr[0]== 0)
  6465. {
  6466. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6467. }
  6468. //Check chargingProfile is empty file
  6469. /*------ Read the file ----------------*/
  6470. fptr1=fopen(chargingProfiles[k],"r");
  6471. ch=fgetc(fptr1);
  6472. rewind(fptr1);
  6473. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6474. if(ch!=EOF)
  6475. {
  6476. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6477. {
  6478. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6479. if(sLineWord[0]=='\0')
  6480. {
  6481. isEmptyFile = TRUE;
  6482. break;
  6483. }
  6484. else
  6485. {
  6486. isEmptyFile = FALSE;
  6487. break;
  6488. }
  6489. }
  6490. }
  6491. else
  6492. isEmptyFile = TRUE;
  6493. fclose(fptr1);
  6494. if(isEmptyFile == TRUE)
  6495. {
  6496. memset(str, 0, ARRAY_SIZE(str));
  6497. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6498. system(str);
  6499. }
  6500. /*------- End of reading ---------------*/
  6501. }
  6502. } // while(int k=0; k < ChargeProfileCount; k++)
  6503. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6504. end:
  6505. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6506. {
  6507. if(connectorIdInt == 0)
  6508. {
  6509. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6510. {
  6511. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  6512. }
  6513. }
  6514. else
  6515. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  6516. }
  6517. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6518. return result;
  6519. }
  6520. void createFirmwareVersionByDataTransfer(void)
  6521. {
  6522. json_object *FirmwareDataTransfer = json_object_new_object();
  6523. // AC & DC model
  6524. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6525. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6526. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6527. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6528. // DC model
  6529. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  6530. {
  6531. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6532. {
  6533. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6534. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6535. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6536. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6537. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6538. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6539. }
  6540. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6541. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  6542. {
  6543. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6544. }
  6545. }
  6546. else
  6547. {
  6548. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6549. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6550. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6551. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6552. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  6553. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  6554. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  6555. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  6556. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  6557. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  6558. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  6559. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  6560. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  6561. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  6562. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  6563. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  6564. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  6565. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  6566. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  6567. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  6568. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  6569. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  6570. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  6571. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  6572. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  6573. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  6574. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  6575. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  6576. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  6577. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  6578. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  6579. }
  6580. // 4G model
  6581. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6582. {
  6583. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6584. }
  6585. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6586. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6587. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6588. json_object_put(FirmwareDataTransfer);
  6589. }
  6590. int handleDataTransferRequest(char *uuid, char *payload)
  6591. {
  6592. mtrace();
  6593. json_object *response = json_object_new_object();
  6594. int result = FAIL;
  6595. char tempvendorId[255]={0};
  6596. char tempmessageId[50]={0};
  6597. char tempdata[512]={0};
  6598. char message[2048]={0};
  6599. DEBUG_INFO("handleDataTransferRequest...\n");
  6600. if((uuid != NULL) && (payload != NULL))
  6601. {
  6602. json_object *DataTransfer;
  6603. DataTransfer = json_tokener_parse(payload);
  6604. if(!is_error(DataTransfer))
  6605. {
  6606. // Required data
  6607. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6608. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6609. // Optional data
  6610. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6611. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6612. if(json_object_object_get(DataTransfer, "data") != NULL)
  6613. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6614. result = PASS;
  6615. }
  6616. json_object_put(DataTransfer);
  6617. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6618. {
  6619. // Send all moudle firmware version on EVSE
  6620. createFirmwareVersionByDataTransfer();
  6621. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6622. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6623. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6624. json_object_put(response);
  6625. }
  6626. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  6627. {
  6628. system("/usr/bin/run_tmate_restart.sh &");
  6629. }
  6630. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6631. {
  6632. json_object *data;
  6633. data = json_tokener_parse(tempdata);
  6634. if(!is_error(data))
  6635. {
  6636. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6637. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6638. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6639. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6640. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6641. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6642. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6643. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6644. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6645. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6646. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6647. }
  6648. else
  6649. {
  6650. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6651. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6652. }
  6653. json_object_put(data);
  6654. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6655. json_object_put(response);
  6656. }
  6657. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6658. {
  6659. json_object *data;
  6660. data = json_tokener_parse(tempdata);
  6661. if(!is_error(data))
  6662. {
  6663. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  6664. if(json_object_object_get(data, "idToken") != NULL)
  6665. {
  6666. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  6667. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6668. }
  6669. if(json_object_object_get(data, "price") != NULL)
  6670. {
  6671. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  6672. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6673. }
  6674. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6675. }
  6676. else
  6677. {
  6678. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6679. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6680. }
  6681. json_object_put(data);
  6682. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6683. json_object_put(response);
  6684. }
  6685. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6686. {
  6687. json_object *data;
  6688. data = json_tokener_parse(tempdata);
  6689. if(!is_error(data))
  6690. {
  6691. if(json_object_object_get(data, "txId") != NULL)
  6692. {
  6693. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6694. for(int idx = 0;idx<gunTotalNumber;idx++)
  6695. {
  6696. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6697. {
  6698. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6699. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6700. if(json_object_object_get(data, "description") != NULL)
  6701. {
  6702. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6703. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6704. }
  6705. }
  6706. }
  6707. }
  6708. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6709. }
  6710. else
  6711. {
  6712. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6713. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6714. }
  6715. json_object_put(data);
  6716. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6717. json_object_put(response);
  6718. }
  6719. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6720. {
  6721. json_object *data;
  6722. data = json_tokener_parse(tempdata);
  6723. if(!is_error(data))
  6724. {
  6725. if(json_object_object_get(data, "txId") != NULL)
  6726. {
  6727. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6728. for(int idx = 0;idx<gunTotalNumber;idx++)
  6729. {
  6730. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6731. {
  6732. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6733. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6734. if(json_object_object_get(data, "description") != NULL)
  6735. {
  6736. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6737. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6738. }
  6739. }
  6740. }
  6741. }
  6742. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6743. }
  6744. else
  6745. {
  6746. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6747. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6748. }
  6749. json_object_put(data);
  6750. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6751. json_object_put(response);
  6752. }
  6753. else
  6754. {
  6755. // Can not find valid message id
  6756. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6757. }
  6758. }
  6759. else
  6760. {
  6761. // Payload is null
  6762. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6763. }
  6764. LWS_Send(message);
  6765. return result;
  6766. }
  6767. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6768. {
  6769. mtrace();
  6770. int result = FAIL;
  6771. int connectorIdInt, durationInt;
  6772. char chargingRateUnitStr[4]={0};
  6773. char comfirmstr[20];
  6774. int confirmPeriods = 0;
  6775. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6776. json_object *GetCompositeSchedule;
  6777. GetCompositeSchedule = json_tokener_parse(payload);
  6778. if(!is_error(GetCompositeSchedule))
  6779. {
  6780. // Required data
  6781. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6782. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6783. else
  6784. connectorIdInt = -1;
  6785. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6786. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6787. else
  6788. durationInt = 86400;
  6789. // Optional data
  6790. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6791. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6792. }
  6793. json_object_put(GetCompositeSchedule);
  6794. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6795. if((connectorIdInt == 0) ||
  6796. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6797. {
  6798. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6799. struct StructChargingProfile tmpProfile[1];
  6800. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6801. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6802. {
  6803. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6804. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6805. }
  6806. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6807. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6808. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6809. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6810. {
  6811. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6812. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6813. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6814. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6815. {
  6816. confirmPeriods = idx;
  6817. break;
  6818. }
  6819. }
  6820. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6821. }
  6822. else
  6823. {
  6824. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6825. }
  6826. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6827. return result;
  6828. }
  6829. int handleGetConfigurationRequest(char *uuid, char *payload)
  6830. {
  6831. mtrace();
  6832. int result = FAIL;
  6833. int MaxKeySupported = 0;
  6834. int n_keys = 0;
  6835. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6836. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6837. json_object *GetConfiguration;
  6838. GetConfiguration = json_tokener_parse(payload);
  6839. if(!is_error(GetConfiguration))
  6840. {
  6841. // Optional data
  6842. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6843. {
  6844. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6845. {
  6846. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6847. n_keys = idx + 1;
  6848. }
  6849. }
  6850. }
  6851. json_object_put(GetConfiguration);
  6852. UnknownKeynum = 0;
  6853. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6854. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6855. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6856. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6857. if(n_keys != 0)
  6858. {
  6859. for(int i=0;i<n_keys;i++)
  6860. {
  6861. getKeyValue(requestKey[i]);
  6862. }
  6863. }
  6864. else
  6865. {
  6866. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6867. getKeyValue("");
  6868. }
  6869. processUnkownKey();
  6870. sendGetConfigurationConfirmation(uuid);
  6871. return result;
  6872. }
  6873. static char fnamePlusPath[100]={0};
  6874. static char fnamePWithNoPath[60]={0};
  6875. void checkUploadLog(void)
  6876. {
  6877. FILE *fp;
  6878. /* Open the command for reading. */
  6879. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6880. if (fp == NULL) {
  6881. printf("Failed to run command\n" );
  6882. exit(1);
  6883. }
  6884. int ftppathlen = 0;
  6885. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6886. int i = 0;
  6887. /* Read the output a line at a time - output it. */
  6888. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6889. if(i==0)
  6890. {
  6891. ftppathlen = strlen(fnamePlusPath);
  6892. printf("%s\n", fnamePlusPath);
  6893. fnamePlusPath[ftppathlen]='\0';
  6894. break;
  6895. }
  6896. i= i+1;
  6897. }
  6898. /* close */
  6899. pclose(fp);
  6900. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6901. {
  6902. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  6903. {
  6904. fnamePlusPath[k]='\0';
  6905. }
  6906. }
  6907. i=1;
  6908. //char fname[60]={0};
  6909. while(i < ftppathlen)
  6910. {
  6911. int len=ftppathlen-i;
  6912. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6913. {
  6914. printf("compare '/' all right\n");
  6915. break;
  6916. }
  6917. i=i+1;
  6918. }
  6919. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6920. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6921. fnamePWithNoPath[i+1] = '\0';
  6922. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6923. {
  6924. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6925. {
  6926. fnamePWithNoPath[j]='\0';
  6927. }
  6928. }
  6929. FILE* fp1 = fopen(fnamePlusPath, "r");
  6930. if (fp1)
  6931. {
  6932. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6933. // file exists
  6934. fclose(fp1);
  6935. }
  6936. else
  6937. {
  6938. // file doesn't exist
  6939. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6940. }
  6941. }
  6942. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6943. {
  6944. mtrace();
  6945. int result = FAIL;
  6946. time_t CurrentTime;
  6947. struct tm *tm;
  6948. pthread_t th_Status;
  6949. CurrentTime = time(NULL);
  6950. tm = localtime(&CurrentTime);
  6951. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  6952. sprintf((char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName, "%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  6953. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6954. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6955. return result;
  6956. }
  6957. void* GetDiagnosticsProcess(void* data)
  6958. {
  6959. pthread_detach(pthread_self());
  6960. mtrace();
  6961. int retriesInt=0, retryIntervalInt=0;
  6962. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6963. 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};
  6964. int port=0;
  6965. int isSuccess = FALSE;
  6966. char ftpbuf[200]={0};
  6967. char cmdBuf[512];
  6968. json_object *GetDiagnostics;
  6969. DEBUG_INFO("GetDiagnosticsProcess...\n");
  6970. GetDiagnostics = json_tokener_parse(data);
  6971. if(!is_error(GetDiagnostics))
  6972. {
  6973. // Required data
  6974. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  6975. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  6976. // Optional data
  6977. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  6978. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  6979. else
  6980. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6981. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  6982. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  6983. else
  6984. retryIntervalInt = 30;
  6985. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  6986. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  6987. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  6988. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  6989. }
  6990. json_object_put(GetDiagnostics);
  6991. // Pack log to compress file
  6992. system("exec /root/logPackTools 'log' 6");
  6993. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6994. system(cmdBuf);
  6995. checkUploadLog();
  6996. //****************location*******************/
  6997. if(strcmp(locationstr,"")==0)
  6998. {
  6999. DEBUG_INFO("location is <Empty>!\n");
  7000. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7001. goto end;
  7002. }
  7003. memset(protocol, 0, ARRAY_SIZE(protocol));
  7004. memset(user, 0, ARRAY_SIZE(user) );
  7005. memset(password, 0, ARRAY_SIZE(password));
  7006. memset(host, 0, ARRAY_SIZE(host));
  7007. memset(path, 0, ARRAY_SIZE(path));
  7008. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7009. memset(host1, 0, ARRAY_SIZE(host1));
  7010. memset(path1, 0, ARRAY_SIZE(path1));
  7011. /*location: ftp://user:password@host:port/path*/
  7012. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7013. if((access(fnamePlusPath,F_OK))!=-1)
  7014. {
  7015. DEBUG_INFO("fnamePlusPath exist.\n");
  7016. }
  7017. else
  7018. {
  7019. DEBUG_INFO("fnamePlusPath not exist!\n");
  7020. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7021. goto end;
  7022. }
  7023. if(strchr(locationstr,'@')==NULL)
  7024. {
  7025. sscanf(locationstr,
  7026. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7027. protocol, host, &port, path);
  7028. strcpy(user,"anonymous");
  7029. strcpy(password,"");
  7030. }
  7031. else
  7032. {
  7033. //DEBUG_INFO("pch=%s\n", pch);
  7034. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7035. protocol, user, password, host, &port, path);
  7036. }
  7037. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7038. {
  7039. DEBUG_INFO("protocol is not ftp/http ! \n");
  7040. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7041. goto end;
  7042. }
  7043. if(strncmp(locationstr,"http", 4) == 0)
  7044. {
  7045. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7046. sprintf(ftppath,"/%s", path);
  7047. do
  7048. {
  7049. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7050. sleep(3);
  7051. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7052. if(!isSuccess)
  7053. {
  7054. DEBUG_INFO("Diagnostics fail.\n");
  7055. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7056. sleep(retryIntervalInt);
  7057. }
  7058. else
  7059. {
  7060. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7061. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7062. }
  7063. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  7064. }
  7065. else
  7066. {
  7067. sscanf(host,"%[^/]%s",host1, path1);
  7068. sprintf(ftppath,"%s", path1);
  7069. int ftppathlen=strlen(ftppath);
  7070. int i=1;
  7071. char filenametemp[50];
  7072. while(i < ftppathlen)
  7073. {
  7074. int len=ftppathlen-i;
  7075. if(ftppath[len]== 47) // '/' ascll code: 47
  7076. {
  7077. DEBUG_INFO("find '/' all right\n");
  7078. break;
  7079. }
  7080. i=i+1;
  7081. }
  7082. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7083. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7084. filenametemp[i+1] = 0;
  7085. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7086. if(port == 0)
  7087. port = 21;
  7088. do
  7089. {
  7090. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7091. sleep(3);
  7092. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7093. if(!isSuccess)
  7094. {
  7095. DEBUG_INFO("Diagnostics fail.\n");
  7096. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7097. sleep(retryIntervalInt);
  7098. }
  7099. else
  7100. {
  7101. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7102. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7103. }
  7104. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  7105. }
  7106. end:
  7107. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7108. pthread_exit(NULL);
  7109. }
  7110. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7111. {
  7112. mtrace();
  7113. int result = FAIL;
  7114. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7115. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7116. {
  7117. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7118. localversion = -1;
  7119. }
  7120. else
  7121. {
  7122. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7123. OCPP_getListVerion();
  7124. }
  7125. //from db.OCPP_getListVerion
  7126. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7127. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7128. sendGetLocalListVersionConfirmation(uuid,"");
  7129. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7130. return result;
  7131. }
  7132. int handleRemoteStartRequest(char *uuid, char *payload)
  7133. {
  7134. mtrace();
  7135. int result = FAIL;
  7136. int connectorIdInt=0;
  7137. int tempIndex = 0;
  7138. int connectorIdIsNULL, chargingProfileIsNULL;
  7139. char comfirmstr[20]={0};
  7140. char cmdBuf[512];
  7141. json_object *RemoteStartTransaction;
  7142. FILE *fp;
  7143. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7144. if(server_pending == TRUE)
  7145. {
  7146. return 0;
  7147. }
  7148. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7149. RemoteStartTransaction = json_tokener_parse(payload);
  7150. if(!is_error(RemoteStartTransaction))
  7151. {
  7152. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7153. {
  7154. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7155. if(connectorIdInt <= gunTotalNumber)
  7156. {
  7157. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7158. // Required data
  7159. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7160. // Optional data
  7161. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7162. {
  7163. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7164. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7165. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7166. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7167. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7168. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7169. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7170. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7171. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7172. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7173. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7174. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7175. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7176. {
  7177. 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")));
  7178. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7179. 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"));
  7180. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7181. 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"));
  7182. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7183. 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")));
  7184. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7185. {
  7186. 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++)
  7187. {
  7188. 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"));
  7189. 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"));
  7190. 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)
  7191. 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"));
  7192. }
  7193. }
  7194. }
  7195. }
  7196. else
  7197. chargingProfileIsNULL = TRUE;
  7198. }
  7199. }
  7200. else
  7201. connectorIdIsNULL = TRUE;
  7202. }
  7203. else
  7204. connectorIdIsNULL = TRUE;
  7205. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7206. {
  7207. DEBUG_WARN("Connector id is NULL\n.");
  7208. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7209. goto end;
  7210. }
  7211. /*
  7212. enum _SYSTEM_STATUS
  7213. {
  7214. S_BOOTING = 0,
  7215. S_IDLE, = 1
  7216. S_AUTHORIZING, = 2
  7217. S_REASSIGN_CHECK, = 3
  7218. S_REASSIGN, = 4
  7219. S_PRECHARGE, = 5
  7220. S_PREPARING_FOR_EV, = 6
  7221. S_PREPARING_FOR_EVSE, = 7
  7222. S_CHARGING, = 8
  7223. S_TERMINATING, = 9
  7224. S_COMPLETE, = 10
  7225. S_ALARM, = 11
  7226. S_FAULT = 12
  7227. }
  7228. */
  7229. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7230. {
  7231. //check Transaction active
  7232. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7233. {
  7234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7235. {
  7236. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7237. }
  7238. else
  7239. {
  7240. tempIndex = connectorIdInt -1;
  7241. }
  7242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7243. {
  7244. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7245. {
  7246. 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))
  7247. {
  7248. //Reserved
  7249. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7250. }
  7251. 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))
  7252. {
  7253. //Reserved
  7254. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7255. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7256. goto end;
  7257. }
  7258. else
  7259. {
  7260. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7261. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7262. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7263. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7264. {
  7265. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7266. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7267. goto end;
  7268. }
  7269. }//END FOR ELSE
  7270. }
  7271. }// END FOR CHAdeMO_QUANTITY
  7272. }
  7273. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  7274. {
  7275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7276. {
  7277. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7278. }
  7279. else
  7280. {
  7281. tempIndex = connectorIdInt -1;
  7282. }
  7283. for (int index = 0; index < CCS_QUANTITY; index++)
  7284. {
  7285. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7286. {
  7287. 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))
  7288. {
  7289. //Reserved
  7290. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7291. }
  7292. 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))
  7293. {
  7294. //Reserved
  7295. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7296. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7297. goto end;
  7298. }
  7299. else
  7300. {
  7301. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7302. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7303. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7304. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7305. {
  7306. DEBUG_WARN("CCS connector not allow start\n.");
  7307. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7308. goto end;
  7309. }
  7310. }// END FOR ELSE
  7311. }
  7312. }// END FOR CCS_QUANTITY
  7313. }
  7314. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  7315. {
  7316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7317. {
  7318. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7319. }
  7320. else
  7321. {
  7322. tempIndex = connectorIdInt -1;
  7323. }
  7324. for (int index = 0; index < GB_QUANTITY; index++)
  7325. {
  7326. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7327. {
  7328. 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))
  7329. {
  7330. //Reserved
  7331. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7332. }
  7333. 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))
  7334. {
  7335. //Reserved
  7336. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7337. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7338. goto end;
  7339. }
  7340. else
  7341. {
  7342. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7343. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7344. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7345. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7346. {
  7347. DEBUG_WARN("GB connector not allow start\n.");
  7348. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7349. goto end;
  7350. }
  7351. }// END FOR ELSE
  7352. }
  7353. } // END FOR GB_QUANTITY
  7354. }
  7355. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  7356. {
  7357. tempIndex = connectorIdInt -1;
  7358. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7359. {
  7360. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7361. {
  7362. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7363. {
  7364. //Reserved
  7365. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7366. }
  7367. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7368. {
  7369. //Reserved
  7370. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7371. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7372. goto end;
  7373. }
  7374. else
  7375. {
  7376. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7377. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7378. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7379. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7380. {
  7381. DEBUG_WARN("GB connector not allow start\n.");
  7382. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7383. goto end;
  7384. }
  7385. }// END FOR ELSE
  7386. }
  7387. } // END FOR GB_QUANTITY
  7388. }
  7389. else
  7390. {
  7391. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7392. {
  7393. tempIndex = 2;
  7394. }
  7395. else
  7396. {
  7397. tempIndex = connectorIdInt -1;
  7398. }
  7399. for (int index = 0; index < AC_QUANTITY; index++)
  7400. {
  7401. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7402. {
  7403. 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))
  7404. {
  7405. //Reserved
  7406. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7407. }
  7408. 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))
  7409. {
  7410. //Reserved
  7411. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7412. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7413. goto end;
  7414. }
  7415. else
  7416. {
  7417. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7418. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7419. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7420. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7421. {
  7422. DEBUG_WARN("AC connector not allow start\n.");
  7423. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7424. goto end;
  7425. }
  7426. }//END FOR ELSE
  7427. }
  7428. }// END FOR AC_QUANTITY
  7429. }
  7430. if(chargingProfileIsNULL == FALSE)
  7431. {
  7432. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7433. {
  7434. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7435. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7436. //memset idTag
  7437. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7438. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7439. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7440. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7441. // Save profile to file
  7442. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7443. system(cmdBuf);
  7444. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7445. fp = fopen(cmdBuf, "w");
  7446. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  7447. fclose(fp);
  7448. }
  7449. else
  7450. {
  7451. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7452. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7453. }
  7454. }
  7455. else
  7456. {
  7457. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7458. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7459. //memset idTag
  7460. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7461. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7462. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7463. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7464. }
  7465. }
  7466. else
  7467. {
  7468. DEBUG_WARN("Connector id over\n.");
  7469. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7470. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7471. }
  7472. end:
  7473. json_object_put(RemoteStartTransaction);
  7474. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7475. {
  7476. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7477. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7478. }
  7479. //OCPP send RemoteStartConfirmation by first.
  7480. sendRemoteStartConfirmation(uuid, comfirmstr);
  7481. return result;
  7482. }
  7483. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7484. {
  7485. mtrace();
  7486. int result = FAIL;
  7487. int match = FALSE;
  7488. int GunNO = 0;
  7489. int tempIndex = 0;
  7490. int transactionIdInt=0;
  7491. int transactionIdIsNULL= TRUE;
  7492. char comfirmstr[20];
  7493. json_object *RemoteStopTransaction;
  7494. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7495. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7496. if(server_pending == TRUE)
  7497. {
  7498. return 0;
  7499. }
  7500. RemoteStopTransaction = json_tokener_parse(payload);
  7501. if(!is_error(RemoteStopTransaction))
  7502. {
  7503. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7504. {
  7505. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7506. transactionIdIsNULL = FALSE;
  7507. }
  7508. }
  7509. json_object_put(RemoteStopTransaction);
  7510. if(transactionIdIsNULL == FALSE)
  7511. {
  7512. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7513. {
  7514. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7515. {
  7516. //check Transaction active
  7517. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7518. {
  7519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7520. {
  7521. tempIndex = ((gun_index==2) ? 1: 0);
  7522. }
  7523. else
  7524. {
  7525. tempIndex = gun_index;
  7526. }
  7527. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7528. {
  7529. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7530. {
  7531. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7532. {
  7533. match = TRUE;
  7534. GunNO = gun_index;
  7535. }
  7536. }
  7537. }// END FOR CHAdeMO_QUANTITY
  7538. }
  7539. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7540. {
  7541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7542. {
  7543. tempIndex = ((gun_index==2) ? 1: 0);
  7544. }
  7545. else
  7546. {
  7547. tempIndex = gun_index;
  7548. }
  7549. for (int index = 0; index < CCS_QUANTITY; index++)
  7550. {
  7551. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7552. {
  7553. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7554. {
  7555. match = TRUE;
  7556. GunNO = gun_index;
  7557. }
  7558. }
  7559. }// END FOR CCS_QUANTITY
  7560. }
  7561. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7562. {
  7563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7564. {
  7565. tempIndex = ((gun_index==2) ? 1: 0);
  7566. }
  7567. else
  7568. {
  7569. tempIndex = gun_index;
  7570. }
  7571. for (int index = 0; index < GB_QUANTITY; index++)
  7572. {
  7573. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7574. {
  7575. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7576. {
  7577. match = TRUE;
  7578. GunNO = gun_index;
  7579. }
  7580. }
  7581. }// END FOR GB_QUANTITY
  7582. }
  7583. else if(gunType[gun_index] == GUN_TYPE_DO)
  7584. {
  7585. tempIndex = gun_index;
  7586. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7587. {
  7588. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7589. {
  7590. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7591. {
  7592. match = TRUE;
  7593. GunNO = gun_index;
  7594. }
  7595. }
  7596. }// END FOR GB_QUANTITY
  7597. }
  7598. else
  7599. {
  7600. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7601. {
  7602. tempIndex = 2;
  7603. }
  7604. else
  7605. {
  7606. tempIndex = gun_index;
  7607. }
  7608. for (int index = 0; index < AC_QUANTITY; index++)
  7609. {
  7610. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7611. {
  7612. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7613. {
  7614. match = TRUE;
  7615. GunNO = gun_index;
  7616. }
  7617. }
  7618. }// END FOR CHAdeMO_QUANTITY
  7619. } // END FOR AC ELSE
  7620. }// CHECK IF ResponseTransactionId == transactionIdInt
  7621. }//END FOR
  7622. if( match == TRUE)
  7623. {
  7624. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7625. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7626. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7627. }
  7628. else
  7629. {
  7630. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7631. }
  7632. }
  7633. else
  7634. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7635. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7636. return result;
  7637. }
  7638. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7639. {
  7640. mtrace();
  7641. int result = FAIL;
  7642. int connectorIdInt=0, reservationIdInt=0;
  7643. int tempIndex = 0;
  7644. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7645. char comfirmstr[20]={0};
  7646. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7647. int c = 0;
  7648. char *loc;
  7649. //char *ptr;
  7650. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7651. strcpy(sstrtemp, stringtrimspace(payload));
  7652. //***(1)connectorId ****/
  7653. c=0;
  7654. loc = strstr(sstrtemp, "connectorId");
  7655. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7656. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7657. {
  7658. sstr[c] = loc[strlen("connectorId")+2+c];
  7659. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7660. c++;
  7661. }
  7662. sstr[c] = '\0';
  7663. connectorIdInt = atoi(sstr);
  7664. //***(2)expiryDate ****/
  7665. loc = strstr(sstrtemp, "expiryDate");
  7666. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7667. c = 0;
  7668. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7669. {
  7670. sstr[c] = loc[3+strlen("expiryDate")+c];
  7671. c++;
  7672. }
  7673. sstr[c] = '\0';
  7674. strcpy(expiryDatestr, sstr);
  7675. //***(3)idTag ****/
  7676. loc = strstr(sstrtemp, "idTag");
  7677. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7678. c = 0;
  7679. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7680. {
  7681. sstr[c] = loc[3+strlen("idTag")+c];
  7682. c++;
  7683. }
  7684. sstr[c] = '\0';
  7685. strcpy(idTagstr, sstr);
  7686. //***(4)parentIdTag ****/
  7687. loc = strstr(sstrtemp, "parentIdTag");
  7688. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7689. c = 0;
  7690. if(loc == NULL)
  7691. {
  7692. strcpy(parentIdTagstr, "");
  7693. }
  7694. else
  7695. {
  7696. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7697. {
  7698. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7699. c++;
  7700. }
  7701. sstr[c] = '\0';
  7702. strcpy(parentIdTagstr, sstr);
  7703. }
  7704. //***(5)reservationId ****/
  7705. c=0;
  7706. loc = strstr(sstrtemp, "reservationId");
  7707. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7708. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7709. {
  7710. sstr[c] = loc[strlen("reservationId")+2+c];
  7711. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7712. c++;
  7713. }
  7714. sstr[c] = '\0';
  7715. reservationIdInt = atoi(sstr);
  7716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7717. /*
  7718. enum SYSTEM_STATUS
  7719. {
  7720. SYS_MODE_BOOTING = 0,
  7721. SYS_MODE_IDLE = 1,
  7722. SYS_MODE_AUTHORIZING = 2,
  7723. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7724. SYS_MODE_REASSIGN = 4,
  7725. SYS_MODE_PREPARING = 5,
  7726. SYS_MODE_PREPARE_FOR_EV = 6,
  7727. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7728. SYS_MODE_CHARGING = 8,
  7729. SYS_MODE_TERMINATING = 9,
  7730. SYS_MODE_COMPLETE = 10,
  7731. SYS_MODE_ALARM = 11,
  7732. SYS_MODE_FAULT = 12,
  7733. SYS_MODE_RESERVATION = 13,
  7734. SYS_MODE_BOOKING = 14,
  7735. SYS_MODE_MAINTAIN = 15,
  7736. SYS_MODE_DEBUG = 16,
  7737. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7738. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7739. SYS_MODE_UPDATE = 19
  7740. };
  7741. */
  7742. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7743. {
  7744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7745. goto end;
  7746. }
  7747. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7748. {
  7749. //check Transaction active
  7750. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7751. {
  7752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7753. {
  7754. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7755. }
  7756. else
  7757. {
  7758. tempIndex = connectorIdInt -1;
  7759. }
  7760. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7761. {
  7762. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7763. {
  7764. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7765. {
  7766. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7767. {
  7768. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7769. {
  7770. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7771. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7772. }
  7773. 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'))
  7774. {
  7775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7776. }
  7777. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7778. {
  7779. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7780. }
  7781. else
  7782. {
  7783. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7784. }
  7785. }
  7786. 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
  7787. {
  7788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7789. }
  7790. }
  7791. else
  7792. {
  7793. //replace reservation
  7794. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7795. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7796. }
  7797. }
  7798. } // END FOR CHAdeMO_QUANTITY
  7799. }
  7800. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  7801. {
  7802. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7803. {
  7804. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7805. }
  7806. else
  7807. {
  7808. tempIndex = connectorIdInt -1;
  7809. }
  7810. for (int index = 0; index < CCS_QUANTITY; index++)
  7811. {
  7812. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7813. {
  7814. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7815. {
  7816. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7817. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7818. {
  7819. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7820. {
  7821. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7823. }
  7824. 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'))
  7825. {
  7826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7827. }
  7828. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7829. {
  7830. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7831. }
  7832. else
  7833. {
  7834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7835. }
  7836. }
  7837. 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
  7838. {
  7839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7840. }
  7841. }
  7842. else
  7843. {
  7844. //replace reservation
  7845. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7846. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7847. }
  7848. }
  7849. } // END FOR CCS_QUANTITY
  7850. }
  7851. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  7852. {
  7853. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7854. {
  7855. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7856. }
  7857. else
  7858. {
  7859. tempIndex = connectorIdInt -1;
  7860. }
  7861. for (int index = 0; index < GB_QUANTITY; index++)
  7862. {
  7863. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7864. {
  7865. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7866. {
  7867. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7868. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7869. {
  7870. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7871. {
  7872. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7874. }
  7875. 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'))
  7876. {
  7877. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7878. }
  7879. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7880. {
  7881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7882. }
  7883. else
  7884. {
  7885. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7886. }
  7887. }
  7888. 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
  7889. {
  7890. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7891. }
  7892. }
  7893. else
  7894. {
  7895. //replace reservation
  7896. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7898. }
  7899. }
  7900. }// END FOR GB_QUANTITY
  7901. }
  7902. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  7903. {
  7904. tempIndex = connectorIdInt -1;
  7905. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7906. {
  7907. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7908. {
  7909. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  7910. {
  7911. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7912. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7913. {
  7914. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7915. {
  7916. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7918. }
  7919. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  7920. {
  7921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7922. }
  7923. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7924. {
  7925. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7926. }
  7927. else
  7928. {
  7929. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7930. }
  7931. }
  7932. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  7933. {
  7934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7935. }
  7936. }
  7937. else
  7938. {
  7939. //replace reservation
  7940. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7941. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7942. }
  7943. }
  7944. }// END FOR GB_QUANTITY
  7945. }
  7946. else
  7947. {
  7948. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7949. {
  7950. tempIndex = 2;
  7951. }
  7952. else
  7953. {
  7954. tempIndex = (connectorIdInt -1);
  7955. }
  7956. for (int index = 0; index < AC_QUANTITY; index++)
  7957. {
  7958. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7959. {
  7960. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7961. {
  7962. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7963. {
  7964. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7965. {
  7966. 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))
  7967. {
  7968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7969. }
  7970. else
  7971. {
  7972. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7973. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7974. }
  7975. }
  7976. 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'))
  7977. {
  7978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7979. }
  7980. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7981. {
  7982. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7983. }
  7984. else
  7985. {
  7986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7987. }
  7988. }
  7989. 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
  7990. {
  7991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7992. }
  7993. }
  7994. else
  7995. {
  7996. //replace reservation
  7997. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7998. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7999. }
  8000. }
  8001. } // END FOR AC_QUANTITY
  8002. }
  8003. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8004. }
  8005. else if(connectorIdInt == 0)
  8006. {
  8007. //check Transaction active
  8008. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8009. {
  8010. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8011. {
  8012. 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'))
  8013. {
  8014. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8015. goto end;
  8016. }
  8017. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8018. {
  8019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8020. goto end;
  8021. }
  8022. 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
  8023. {
  8024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8025. goto end;
  8026. }
  8027. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8028. {
  8029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8030. goto end;
  8031. }
  8032. }
  8033. }// END FOR CHAdeMO_QUANTITY
  8034. for (int index = 0; index < CCS_QUANTITY; index++)
  8035. {
  8036. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8037. {
  8038. 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'))
  8039. {
  8040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8041. goto end;
  8042. }
  8043. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8044. {
  8045. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8046. goto end;
  8047. }
  8048. 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
  8049. {
  8050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8051. goto end;
  8052. }
  8053. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8054. {
  8055. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8056. goto end;
  8057. }
  8058. }
  8059. } // END FOR CCS_QUANTITY
  8060. for (int index = 0; index < GB_QUANTITY; index++)
  8061. {
  8062. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8063. {
  8064. 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'))
  8065. {
  8066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8067. goto end;
  8068. }
  8069. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8070. {
  8071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8072. goto end;
  8073. }
  8074. 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
  8075. {
  8076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8077. goto end;
  8078. }
  8079. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8080. {
  8081. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8082. goto end;
  8083. }
  8084. }
  8085. } // END FOR GB_QUANTITY
  8086. for (int index = 0; index < AC_QUANTITY; index++)
  8087. {
  8088. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8089. {
  8090. 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'))
  8091. {
  8092. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8093. goto end;
  8094. }
  8095. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8096. {
  8097. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8098. goto end;
  8099. }
  8100. 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
  8101. {
  8102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8103. goto end;
  8104. }
  8105. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8106. {
  8107. 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))
  8108. {
  8109. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8110. goto end;
  8111. }
  8112. }
  8113. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8114. {
  8115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8116. goto end;
  8117. }
  8118. }
  8119. }// END FOR AC_QUANTITY
  8120. //The connectorId is 0
  8121. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8122. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8123. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8124. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8125. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8126. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8127. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8128. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8129. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8130. result = TRUE;
  8131. return result;
  8132. }
  8133. else
  8134. {
  8135. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8136. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8137. }
  8138. if(strcmp(comfirmstr,"Accepted") == 0)
  8139. {
  8140. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8141. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8142. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8143. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8144. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8145. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8146. result = TRUE;
  8147. return result;
  8148. }
  8149. end:
  8150. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8151. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8152. return result;
  8153. }
  8154. int handleResetRequest(char *uuid, char *payload)
  8155. {
  8156. mtrace();
  8157. int result = FAIL;
  8158. char sstr[10]={0},sstrtemp[30]={ 0 };
  8159. char typestr[10]={0};
  8160. char comfirmstr[20]={0};
  8161. int c = 0;
  8162. char *loc;
  8163. DEBUG_INFO("handleResetRequest...\n");
  8164. strcpy(sstrtemp, stringtrimspace(payload));
  8165. loc = strstr(sstrtemp, "type");
  8166. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8167. c = 0;
  8168. while (loc[3+strlen("type")+c] != '\"')
  8169. {
  8170. sstr[c] = loc[3+strlen("type")+c];
  8171. c++;
  8172. }
  8173. sstr[c] = '\0';
  8174. strcpy(typestr,sstr);
  8175. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8176. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8177. {
  8178. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8179. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8180. result = TRUE;
  8181. return result;
  8182. }
  8183. else
  8184. {
  8185. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8186. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8187. goto errorend;
  8188. }
  8189. errorend:
  8190. sendResetConfirmation(uuid, comfirmstr);
  8191. return result;
  8192. }
  8193. int handleSendLocalListRequest(char *uuid, char *payload)
  8194. {
  8195. mtrace();
  8196. int result = FAIL;
  8197. int listVersionInt;
  8198. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8199. char listsearch[]="listVersion";
  8200. char updateTypesearch[]="updateType";
  8201. char localAuthorizationListsearch[]="localAuthorizationList";
  8202. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8203. char CardList[500][160]={0};
  8204. char updateTypestr[15]={0};
  8205. char idTagstr[20]={0};
  8206. char parentIdTag[20]={0};
  8207. char expiryDate[30]={0};
  8208. char idTagstatus[16]={0};
  8209. int c = 0;
  8210. int i = 0;
  8211. char *delim1 = "}";
  8212. char * pch;
  8213. char *loc;
  8214. //char *ptr;
  8215. char comfirmstr[20];
  8216. //int n_localAuthorizations = 0;
  8217. int checkState_Faulted = FALSE;
  8218. DEBUG_INFO("handleSendLocalListRequest...\n");
  8219. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8220. {
  8221. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8222. goto end;
  8223. }
  8224. //check Charge Point state
  8225. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8226. {
  8227. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8228. {
  8229. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8230. }
  8231. }
  8232. for (int index = 0; index < CCS_QUANTITY; index++)
  8233. {
  8234. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8235. {
  8236. checkState_Faulted = TRUE; //OCPP Status
  8237. }
  8238. }
  8239. for (int index = 0; index < GB_QUANTITY; index++)
  8240. {
  8241. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8242. {
  8243. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8244. }
  8245. }
  8246. //check Charge Point state
  8247. for (int index = 0; index < AC_QUANTITY; index++)
  8248. {
  8249. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8250. {
  8251. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8252. }
  8253. }
  8254. if(checkState_Faulted == TRUE)
  8255. {
  8256. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8257. goto end;
  8258. }
  8259. //Filter payload space
  8260. strcpy(sstrtemp, stringtrimspace(payload));
  8261. //listVersion
  8262. c = 0;
  8263. loc = strstr(sstrtemp, listsearch);
  8264. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8265. {
  8266. sstr[c] = loc[strlen("listVersion")+2+c];
  8267. c++;
  8268. }
  8269. sstr[c] = '\0';
  8270. listVersionInt = atoi(sstr);
  8271. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8272. //updateType
  8273. loc = strstr(sstrtemp, updateTypesearch);
  8274. c = 0;
  8275. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8276. {
  8277. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8278. c++;
  8279. }
  8280. sstr[c] = '\0';
  8281. strcpy(updateTypestr, sstr);
  8282. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8283. //localAuthorizationList
  8284. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8285. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8286. if(loc != NULL) // localAuthorizationList is not NULL
  8287. {
  8288. //Check UpdateType
  8289. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8290. {
  8291. //Local list full update
  8292. printf("Local list full update.\n");
  8293. OCPP_getListVerion();
  8294. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8295. {
  8296. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8297. goto end;
  8298. }
  8299. OCPP_cleanLocalList();
  8300. }
  8301. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8302. {
  8303. //Local list different update
  8304. printf("Local list different update.\n");
  8305. OCPP_getListVerion();
  8306. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8307. {
  8308. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8309. goto end;
  8310. }
  8311. }
  8312. else
  8313. {
  8314. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8315. goto end;
  8316. }
  8317. c = 0;
  8318. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8319. {
  8320. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8321. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8322. c++;
  8323. }
  8324. sstr[c] = '\0';
  8325. //DEBUG_INFO("sstr=%s\n", sstr);
  8326. //parsing strings to words
  8327. i = 0;
  8328. pch = strtok(sstr,delim1);
  8329. while (pch != NULL)
  8330. {
  8331. strcpy(CardList[i], pch);
  8332. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8333. pch = strtok (NULL, delim1);
  8334. i = i + 1;
  8335. }
  8336. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8337. //local Authorizations List Numbers
  8338. //n_localAuthorizations = i;
  8339. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8340. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8341. c= 0;
  8342. while(c < i) // i is CardList Number
  8343. {
  8344. //Search "IdToken"
  8345. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8346. loc = strstr(CardList[c], "idTag");
  8347. int j = 0;
  8348. while (loc[3+strlen("idTag")+j] != '\"')
  8349. {
  8350. sstr[j] = loc[3+strlen("idTag")+j];
  8351. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8352. j++;
  8353. }
  8354. sstr[j] = '\0';
  8355. strcpy(idTagstr, sstr);
  8356. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8357. //Search "expiryDate"
  8358. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8359. loc = strstr(CardList[c], "expiryDate");
  8360. j = 0;
  8361. if(loc != NULL)
  8362. {
  8363. while (loc[3+strlen("expiryDate")+j] != '\"')
  8364. {
  8365. sstr[j] = loc[3+strlen("expiryDate")+j];
  8366. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8367. j++;
  8368. }
  8369. sstr[j] = '\0';
  8370. strcpy(expiryDate, sstr);
  8371. }
  8372. else
  8373. {
  8374. strcpy(expiryDate, "");
  8375. }
  8376. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8377. //Search "parentIdTag"
  8378. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8379. loc = strstr(CardList[c], "parentIdTag");
  8380. j = 0;
  8381. if(loc != NULL)
  8382. {
  8383. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8384. {
  8385. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8386. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8387. j++;
  8388. }
  8389. sstr[j] = '\0';
  8390. strcpy(parentIdTag, sstr);
  8391. }
  8392. else
  8393. {
  8394. strcpy(parentIdTag, "");
  8395. }
  8396. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8397. //Search "status"
  8398. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8399. loc = strstr(CardList[c], "status");
  8400. j = 0;
  8401. while (loc[3+strlen("status")+j] != '\"')
  8402. {
  8403. sstr[j] = loc[3+strlen("status")+j];
  8404. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8405. j++;
  8406. }
  8407. sstr[j] = '\0';
  8408. strcpy(idTagstatus, sstr);
  8409. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8410. OCPP_getIdTagFromLocalList(idTagstr);
  8411. //OCPP_getIdTagFromLocalList("test"); For Test
  8412. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8413. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8414. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8415. {
  8416. //Local list full update
  8417. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8418. // update list
  8419. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8420. //DEBUG_INFO("Local list full update. 1\n");
  8421. //OCPP_get_TableAuthlocalAllData();
  8422. //DEBUG_INFO("Local list full update. 2\n");
  8423. }
  8424. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8425. {
  8426. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8427. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8428. }
  8429. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8430. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8431. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8432. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8433. c++;
  8434. }
  8435. }
  8436. else
  8437. {
  8438. //Check UpdateType
  8439. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8440. {
  8441. //Local list full update
  8442. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8443. OCPP_cleanLocalList();
  8444. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8445. goto end;
  8446. }
  8447. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8448. {
  8449. //Local list different update
  8450. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8451. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8452. goto end;
  8453. }
  8454. }
  8455. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8456. end:
  8457. sendSendLocalListConfirmation(uuid, comfirmstr);
  8458. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8459. return result;
  8460. }
  8461. #define MAX 200
  8462. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8463. {
  8464. mtrace();
  8465. int result = FAIL;
  8466. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8467. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8468. char chargingProfilePurposeStr[30]={0};
  8469. char chargingProfileKindStr[16]={0};
  8470. char recurrencyKindStr[10]={0};
  8471. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8472. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8473. int chargingSchedulePeriodCount = 0;
  8474. char comfirmstr[20]={0};
  8475. int meet= FALSE;
  8476. FILE *fptr1;
  8477. char filename[MAX]={0};
  8478. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8479. char rmFileCmd[50]={0};
  8480. char tempchargingProfilePurposeStr[30]={0};
  8481. char word[1600]={0};
  8482. int n_chargingProfile = 0;
  8483. json_object *SetChargingProfile;
  8484. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8485. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8486. SetChargingProfile = json_tokener_parse(payload);
  8487. if(!is_error(SetChargingProfile))
  8488. {
  8489. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8490. {
  8491. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8492. if(connectorIdInt == 0)
  8493. {
  8494. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8495. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8496. }
  8497. else
  8498. {
  8499. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8500. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8501. }
  8502. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8503. }
  8504. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8505. {
  8506. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8507. {
  8508. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8509. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8510. {
  8511. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8512. }
  8513. else
  8514. {
  8515. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8516. }
  8517. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8518. }
  8519. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8520. {
  8521. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8522. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8523. {
  8524. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8525. }
  8526. else
  8527. {
  8528. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8529. }
  8530. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8531. }
  8532. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8533. {
  8534. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8535. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8536. {
  8537. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8538. }
  8539. else
  8540. {
  8541. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8542. }
  8543. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8544. }
  8545. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8546. {
  8547. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8548. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8549. {
  8550. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8551. }
  8552. else
  8553. {
  8554. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8555. }
  8556. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8557. }
  8558. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8559. {
  8560. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8561. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8562. {
  8563. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8564. }
  8565. else
  8566. {
  8567. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8568. }
  8569. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8570. }
  8571. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8572. {
  8573. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8574. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8575. {
  8576. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8577. }
  8578. else
  8579. {
  8580. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8581. }
  8582. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8583. }
  8584. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8585. {
  8586. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8587. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8588. {
  8589. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8590. }
  8591. else
  8592. {
  8593. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8594. }
  8595. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8596. }
  8597. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8598. {
  8599. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8600. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8601. {
  8602. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8603. }
  8604. else
  8605. {
  8606. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8607. }
  8608. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8609. }
  8610. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8611. {
  8612. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8613. {
  8614. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8615. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8616. {
  8617. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8618. }
  8619. else
  8620. {
  8621. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8622. }
  8623. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8624. }
  8625. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8626. {
  8627. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8628. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8629. {
  8630. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8631. }
  8632. else
  8633. {
  8634. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8635. }
  8636. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8637. }
  8638. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8639. {
  8640. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8641. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8642. {
  8643. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8644. }
  8645. else
  8646. {
  8647. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8648. }
  8649. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8650. }
  8651. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8652. {
  8653. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8654. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8655. {
  8656. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8657. }
  8658. else
  8659. {
  8660. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8661. }
  8662. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8663. }
  8664. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8665. {
  8666. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8667. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8668. if(chargingSchedulePeriodCount <= 10)
  8669. {
  8670. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  8671. {
  8672. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  8673. {
  8674. startPeriodInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  8675. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8676. {
  8677. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8678. }
  8679. else
  8680. {
  8681. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8682. }
  8683. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8684. }
  8685. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  8686. {
  8687. limitflaot[idxPeriod] = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  8688. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8689. {
  8690. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8691. }
  8692. else
  8693. {
  8694. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8695. }
  8696. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8697. }
  8698. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  8699. {
  8700. numberPhasesInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  8701. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8702. {
  8703. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8704. }
  8705. else
  8706. {
  8707. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8708. }
  8709. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8710. }
  8711. }
  8712. }
  8713. }
  8714. }
  8715. }
  8716. }
  8717. json_object_put(SetChargingProfile);
  8718. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8719. {
  8720. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8721. goto end;
  8722. }
  8723. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8724. {
  8725. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8726. if(connectorIdInt != 0)
  8727. {
  8728. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8729. goto end;
  8730. }
  8731. strcpy(filename, ChargePointMaxProfile_JSON );
  8732. fptr1 = fopen(filename, "r");
  8733. if (!fptr1)
  8734. {
  8735. //file not exist
  8736. DEBUG_INFO("Unable to open the input file!!\n");
  8737. fptr1 = fopen(filename, "w+");
  8738. }
  8739. else
  8740. {
  8741. //Check Charging Profile Count
  8742. while(fscanf(fptr1, "%s", word) != EOF)
  8743. {
  8744. //DEBUG_INFO("word=%s\n",word);
  8745. if(strstr(word, "chargingProfileId")!= NULL)
  8746. {
  8747. //DEBUG_INFO("test chargingProfileId \n");
  8748. n_chargingProfile = n_chargingProfile + 1;
  8749. //DEBUG_INFO("chargingProfileId Found\n");
  8750. }
  8751. }
  8752. }
  8753. fclose(fptr1);
  8754. }
  8755. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8756. {
  8757. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8758. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8759. {
  8760. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8761. goto end;
  8762. }
  8763. memset(filename, 0, ARRAY_SIZE(filename));
  8764. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8765. fptr1 = fopen(filename, "r");
  8766. if (!fptr1)
  8767. {
  8768. //file not exist
  8769. //DEBUG_INFO("Unable to open the input file!!\n");
  8770. fptr1 = fopen(filename, "w+");
  8771. }
  8772. else
  8773. {
  8774. //Check Charging Profile Count
  8775. while(fscanf(fptr1, "%s", word) != EOF)
  8776. {
  8777. //DEBUG_INFO("word=%s\n",word);
  8778. if(strstr(word, "chargingProfileId")!= NULL)
  8779. {
  8780. //DEBUG_INFO("test chargingProfileId \n");
  8781. n_chargingProfile = n_chargingProfile + 1;
  8782. //DEBUG_INFO("chargingProfileId Found\n");
  8783. }
  8784. }
  8785. }
  8786. fclose(fptr1);
  8787. }
  8788. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8789. {
  8790. //printf("set chargingProfile 1-4\n");
  8791. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8792. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8793. if(connectorIdInt == 0)
  8794. {
  8795. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8796. goto end;
  8797. }
  8798. int tempIndex = 0;
  8799. //check Transaction active
  8800. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8801. {
  8802. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8803. {
  8804. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8805. }
  8806. else
  8807. {
  8808. tempIndex = connectorIdInt -1;
  8809. }
  8810. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8811. {
  8812. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8813. {
  8814. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8815. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8816. {
  8817. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8818. {
  8819. meet = TRUE;
  8820. break;
  8821. }
  8822. }
  8823. }
  8824. }
  8825. }
  8826. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8827. {
  8828. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8829. {
  8830. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8831. }
  8832. else
  8833. {
  8834. tempIndex = connectorIdInt -1;
  8835. }
  8836. for (int index = 0; index < CCS_QUANTITY; index++)
  8837. {
  8838. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8839. {
  8840. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8841. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8842. {
  8843. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8844. {
  8845. meet = TRUE;
  8846. break;
  8847. }
  8848. }
  8849. }
  8850. }
  8851. }
  8852. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8853. {
  8854. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8855. {
  8856. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8857. }
  8858. else
  8859. {
  8860. tempIndex = connectorIdInt -1;
  8861. }
  8862. for (int index = 0; index < GB_QUANTITY; index++)
  8863. {
  8864. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8865. {
  8866. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8867. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8868. {
  8869. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8870. {
  8871. meet = TRUE;
  8872. break;
  8873. }
  8874. }
  8875. }
  8876. }
  8877. }
  8878. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8879. {
  8880. tempIndex = connectorIdInt -1;
  8881. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8882. {
  8883. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8884. {
  8885. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8886. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8887. {
  8888. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8889. {
  8890. meet = TRUE;
  8891. break;
  8892. }
  8893. }
  8894. }
  8895. }
  8896. }
  8897. else
  8898. {
  8899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8900. {
  8901. tempIndex = 2;
  8902. }
  8903. else
  8904. {
  8905. tempIndex = (connectorIdInt -1);
  8906. }
  8907. for (int index = 0; index < AC_QUANTITY; index++)
  8908. {
  8909. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8910. {
  8911. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8912. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8913. {
  8914. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8915. {
  8916. meet = TRUE;
  8917. break;
  8918. }
  8919. }
  8920. }
  8921. }
  8922. }
  8923. //check Transaction active
  8924. if(meet == FALSE)
  8925. {
  8926. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8927. goto end;
  8928. }
  8929. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8930. {
  8931. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8932. goto end;
  8933. }
  8934. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8935. fptr1 = fopen(filename, "r");
  8936. if (!fptr1)
  8937. {
  8938. //file not exist
  8939. DEBUG_INFO("Unable to open the input file!!\n");
  8940. fptr1 = fopen(filename, "w+");
  8941. }
  8942. else
  8943. {
  8944. //Check Charging Profile Count
  8945. while(fscanf(fptr1, "%s", word) != EOF)
  8946. {
  8947. //DEBUG_INFO("word=%s\n",word);
  8948. if(strstr(word, "chargingProfileId")!= NULL)
  8949. {
  8950. //DEBUG_INFO("test chargingProfileId \n");
  8951. n_chargingProfile = n_chargingProfile + 1;
  8952. //DEBUG_INFO("chargingProfileId Found\n");
  8953. }
  8954. }
  8955. }
  8956. fclose(fptr1);
  8957. }
  8958. // Check ChargeProfileMaxStackLevel
  8959. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8960. {
  8961. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8962. goto end;
  8963. }
  8964. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8965. {
  8966. int i = 0;
  8967. char fnametemp[200]={0};
  8968. n_chargingProfile = 0;
  8969. //Check ChargePointMaxProfile.json exit
  8970. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8971. {
  8972. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8973. //Check Charging Profile Count
  8974. while(fscanf(fptr1, "%s", word) != EOF)
  8975. {
  8976. //DEBUG_INFO("word=%s\n",word);
  8977. if(strstr(word, "chargingProfileId")!= NULL)
  8978. {
  8979. //DEBUG_INFO("test chargingProfileId \n");
  8980. n_chargingProfile = n_chargingProfile + 1;
  8981. i = i + 1;
  8982. //DEBUG_INFO("chargingProfileId Found\n");
  8983. }
  8984. memset(word, 0, ARRAY_SIZE(word));
  8985. }
  8986. fclose(fptr1);
  8987. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8988. }
  8989. //Check TxDefaultProfile_0.json exit
  8990. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8991. {
  8992. i = 0;
  8993. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8994. //Check Charging Profile Count
  8995. while(fscanf(fptr1, "%s", word) != EOF)
  8996. {
  8997. //DEBUG_INFO("word=%s\n",word);
  8998. if(strstr(word, "chargingProfileId")!= NULL)
  8999. {
  9000. //DEBUG_INFO("test chargingProfileId \n");
  9001. n_chargingProfile = n_chargingProfile + 1;
  9002. i = i + 1;
  9003. //DEBUG_INFO("chargingProfileId Found\n");
  9004. }
  9005. memset(word, 0, ARRAY_SIZE(word));
  9006. }
  9007. fclose(fptr1);
  9008. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9009. }
  9010. //Check TxDefaultProfile_%d.json
  9011. for(int j=1; j <= gunTotalNumber; j++)
  9012. {
  9013. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9014. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9015. if((access(fnametemp,F_OK))!=-1)
  9016. {
  9017. i = 0;
  9018. fptr1 = fopen(fnametemp, "r");
  9019. //Check Charging Profile Count
  9020. while(fscanf(fptr1, "%s", word) != EOF)
  9021. {
  9022. //DEBUG_INFO("word=%s\n",word);
  9023. if(strstr(word, "chargingProfileId")!= NULL)
  9024. {
  9025. //DEBUG_INFO("test chargingProfileId \n");
  9026. n_chargingProfile = n_chargingProfile + 1;
  9027. i = i + 1;
  9028. //DEBUG_INFO("chargingProfileId Found\n");
  9029. }
  9030. memset(word, 0, ARRAY_SIZE(word));
  9031. }
  9032. fclose(fptr1);
  9033. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9034. }
  9035. }
  9036. //Check TxProfile_%d.json
  9037. for(int j=1; j <= gunTotalNumber; j++)
  9038. {
  9039. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9040. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9041. if((access(fnametemp,F_OK))!=-1)
  9042. {
  9043. i = 0;
  9044. fptr1 = fopen(fnametemp, "r");
  9045. //Check Charging Profile Count
  9046. while(fscanf(fptr1, "%s", word) != EOF)
  9047. {
  9048. //DEBUG_INFO("word=%s\n",word);
  9049. if(strstr(word, "chargingProfileId")!= NULL)
  9050. {
  9051. //DEBUG_INFO("test chargingProfileId \n");
  9052. n_chargingProfile = n_chargingProfile + 1;
  9053. i = i + 1;
  9054. //DEBUG_INFO("chargingProfileId Found\n");
  9055. }
  9056. memset(word, 0, ARRAY_SIZE(word));
  9057. }
  9058. fclose(fptr1);
  9059. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9060. }
  9061. }
  9062. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9063. {
  9064. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9065. goto end;
  9066. }
  9067. }
  9068. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9069. //**********************************Write to File********************************************************/
  9070. FILE *infile;
  9071. FILE *outfile;
  9072. infile = fopen (filename, "r");
  9073. outfile = fopen (tempfile, "w");
  9074. int d =0;
  9075. d = fgetc(infile);
  9076. rewind(infile);
  9077. if(d == EOF)
  9078. {
  9079. // Profile is empty
  9080. fprintf(outfile,"%s\n",payload);
  9081. fclose(infile);
  9082. fclose(outfile);
  9083. sprintf(rmFileCmd,"rm -f %s",filename);
  9084. system(rmFileCmd);
  9085. rename(tempfile, filename);
  9086. }
  9087. else
  9088. {
  9089. // Profile is not empty
  9090. char buf[2048]={0};
  9091. int ChargingProfileAdded = FALSE;
  9092. while (fgets(buf, sizeof(buf), infile) != NULL)
  9093. {
  9094. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9095. json_object *tmpChargingProfile;
  9096. tmpChargingProfile = json_tokener_parse(buf);
  9097. if(!is_error(SetChargingProfile))
  9098. {
  9099. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9100. {
  9101. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9102. }
  9103. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9104. {
  9105. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9106. {
  9107. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9108. }
  9109. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9110. {
  9111. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9112. }
  9113. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9114. {
  9115. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9116. }
  9117. }
  9118. }
  9119. json_object_put(tmpChargingProfile);
  9120. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9121. {
  9122. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9123. {
  9124. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9125. if(ChargingProfileAdded == FALSE)
  9126. {
  9127. fprintf(outfile,"%s\n",payload);
  9128. ChargingProfileAdded = TRUE;
  9129. }
  9130. }
  9131. else
  9132. {
  9133. if(tempstackLevelInt < stackLevelInt)
  9134. {
  9135. if(ChargingProfileAdded == FALSE)
  9136. {
  9137. fprintf(outfile,"%s\n",buf);
  9138. fprintf(outfile,"%s\n",payload);
  9139. ChargingProfileAdded = TRUE;
  9140. }
  9141. else
  9142. {
  9143. fprintf(outfile,"%s\n",buf);
  9144. }
  9145. }
  9146. else
  9147. {
  9148. if(ChargingProfileAdded == FALSE)
  9149. {
  9150. fprintf(outfile,"%s\n",buf);
  9151. fprintf(outfile,"%s\n",payload);
  9152. ChargingProfileAdded = TRUE;
  9153. }
  9154. else
  9155. {
  9156. fprintf(outfile,"%s\n",buf);
  9157. }
  9158. }
  9159. }
  9160. }
  9161. else
  9162. {
  9163. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9164. {
  9165. if(ChargingProfileAdded == FALSE)
  9166. {
  9167. fprintf(outfile,"%s\n",buf);
  9168. fprintf(outfile,"%s\n",payload);
  9169. ChargingProfileAdded = TRUE;
  9170. }
  9171. else
  9172. {
  9173. fprintf(outfile,"%s\n",buf);
  9174. }
  9175. }
  9176. else if(tempstackLevelInt < stackLevelInt)
  9177. {
  9178. if(ChargingProfileAdded == FALSE)
  9179. {
  9180. fprintf(outfile,"%s\n",buf);
  9181. fprintf(outfile,"%s\n",payload);
  9182. ChargingProfileAdded = TRUE;
  9183. }
  9184. else
  9185. {
  9186. fprintf(outfile,"%s\n",buf);
  9187. }
  9188. }
  9189. else
  9190. {
  9191. if(ChargingProfileAdded == FALSE)
  9192. {
  9193. fprintf(outfile,"%s\n",buf);
  9194. fprintf(outfile,"%s\n",payload);
  9195. ChargingProfileAdded = TRUE;
  9196. }
  9197. else
  9198. {
  9199. fprintf(outfile,"%s\n",buf);
  9200. }
  9201. }
  9202. }
  9203. } // end of while loop
  9204. fclose(infile);
  9205. fclose(outfile);
  9206. sprintf(rmFileCmd,"rm -f %s",filename);
  9207. system(rmFileCmd);
  9208. rename(tempfile, filename);
  9209. }
  9210. sleep(1);
  9211. result = TRUE;
  9212. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9213. end:
  9214. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9215. {
  9216. if(connectorIdInt == 0)
  9217. {
  9218. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9219. {
  9220. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  9221. }
  9222. }
  9223. else
  9224. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  9225. }
  9226. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9227. return result;
  9228. }
  9229. int handleTriggerMessageRequest(char *uuid, char *payload)
  9230. {
  9231. mtrace();
  9232. int result = FAIL;
  9233. int connectorIdIsNULL = FALSE;
  9234. int connectorIdInt =0;
  9235. char sstr[40]={0},sstrtemp[100]={ 0 };
  9236. char requestedMessagestr[40]={0};
  9237. char comfirmstr[20]={0};
  9238. int c = 0;
  9239. char *loc;
  9240. DEBUG_INFO("handleTriggerMessageRequest\n");
  9241. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9242. strcpy(sstrtemp, stringtrimspace(payload));
  9243. c = 0;
  9244. loc = strstr(sstrtemp, "requestedMessage");
  9245. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9246. {
  9247. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9248. c++;
  9249. }
  9250. sstr[c] = '\0';
  9251. strcpy(requestedMessagestr, sstr);
  9252. c = 0;
  9253. loc = strstr(sstrtemp, "connectorId");
  9254. if(loc == NULL)
  9255. {
  9256. connectorIdIsNULL = TRUE;
  9257. }
  9258. else
  9259. {
  9260. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9261. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9262. {
  9263. sstr[c] = loc[strlen("connectorId")+2+c];
  9264. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9265. c++;
  9266. }
  9267. sstr[c] = '\0';
  9268. connectorIdInt = atoi(sstr);
  9269. }
  9270. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9271. {
  9272. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9273. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9274. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9275. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9276. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9277. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9278. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9279. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9280. {
  9281. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9282. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9283. return TRUE;
  9284. }
  9285. else
  9286. {
  9287. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9288. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9289. }
  9290. }
  9291. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9292. {
  9293. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9294. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9295. return TRUE;
  9296. }
  9297. //==========================
  9298. // Trigger message
  9299. //==========================
  9300. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9301. {
  9302. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9303. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9304. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9305. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9306. {
  9307. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9308. }
  9309. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9310. }
  9311. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9312. {
  9313. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9314. }
  9315. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9316. {
  9317. //sendBootNotificationRequest();
  9318. server_sign = FALSE;
  9319. }
  9320. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9321. {
  9322. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9323. }
  9324. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9325. {
  9326. if(connectorIdIsNULL == FALSE)
  9327. {
  9328. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9329. {
  9330. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9331. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9332. }
  9333. }
  9334. else
  9335. {
  9336. for(int idx=0;idx< gunTotalNumber;idx++)
  9337. {
  9338. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9339. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9340. }
  9341. }
  9342. }
  9343. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9344. {
  9345. if(connectorIdIsNULL == FALSE)
  9346. {
  9347. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9348. {
  9349. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9350. }
  9351. }
  9352. else
  9353. {
  9354. for(int idx=0;idx< gunTotalNumber;idx++)
  9355. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9356. }
  9357. }
  9358. return result;
  9359. }
  9360. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9361. {
  9362. mtrace();
  9363. int result = FAIL;
  9364. int connectorIdInt =0;
  9365. char comfirmstr[20]={0};
  9366. int tempIndex = 0;
  9367. json_object *UnlockConnector;
  9368. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9369. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9370. UnlockConnector = json_tokener_parse(payload);
  9371. if(!is_error(UnlockConnector))
  9372. {
  9373. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9374. {
  9375. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9376. }
  9377. }
  9378. json_object_put(UnlockConnector);
  9379. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9380. if(gunTotalNumber == 0)
  9381. {
  9382. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9383. goto end;
  9384. }
  9385. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9386. {
  9387. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9388. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9389. goto end;
  9390. }
  9391. else
  9392. {
  9393. //check Transaction active
  9394. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  9395. {
  9396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9397. {
  9398. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9399. }
  9400. else
  9401. {
  9402. tempIndex = connectorIdInt -1;
  9403. }
  9404. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9405. {
  9406. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9407. {
  9408. //stop Transaction
  9409. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9410. }
  9411. }
  9412. }
  9413. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  9414. {
  9415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9416. {
  9417. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9418. }
  9419. else
  9420. {
  9421. tempIndex = connectorIdInt -1;
  9422. }
  9423. for (int index = 0; index < CCS_QUANTITY; index++)
  9424. {
  9425. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9426. {
  9427. //stop Transaction
  9428. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9429. }
  9430. }
  9431. }
  9432. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  9433. {
  9434. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9435. {
  9436. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9437. }
  9438. else
  9439. {
  9440. tempIndex = connectorIdInt -1;
  9441. }
  9442. for (int index = 0; index < GB_QUANTITY; index++)
  9443. {
  9444. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9445. {
  9446. //stop Transaction
  9447. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9448. }
  9449. }
  9450. }
  9451. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  9452. {
  9453. tempIndex = connectorIdInt -1;
  9454. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9455. {
  9456. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  9457. {
  9458. //stop Transaction
  9459. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9460. }
  9461. }
  9462. }
  9463. else
  9464. {
  9465. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9466. {
  9467. tempIndex = 2;
  9468. }
  9469. else
  9470. {
  9471. tempIndex = connectorIdInt-1;
  9472. }
  9473. for (int index = 0; index < AC_QUANTITY; index++)
  9474. {
  9475. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9476. {
  9477. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9478. }
  9479. }
  9480. }
  9481. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9482. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9483. result = TRUE;
  9484. return result;
  9485. }
  9486. end:
  9487. //json_object_put(obj); --- remove temporally
  9488. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9489. return result;
  9490. }
  9491. static char UpdateFirmwarepayloadData[300]={0};
  9492. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9493. {
  9494. mtrace();
  9495. int result = FAIL;
  9496. pthread_t t;
  9497. sendUpdateFirmwareConfirmation(uuid);
  9498. memset(UpdateFirmwarepayloadData, 0, 300);
  9499. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9500. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9501. ////pthread_join(t, NULL); //
  9502. //pthread_detach(t);
  9503. //sendUpdateFirmwareConfirmation(uuid);
  9504. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9505. return result;
  9506. }
  9507. void *UpdateFirmwareProcess(void *data)
  9508. {
  9509. pthread_detach(pthread_self());
  9510. mtrace();
  9511. int retriesInt =0, retryIntervalInt=0;
  9512. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9513. int port=0;
  9514. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9515. int isSuccess = 0;
  9516. char ftpbuf[200];
  9517. char temp[100];
  9518. char * pch;
  9519. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9520. json_object *UpdateFirmware;
  9521. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9522. if(!is_error(UpdateFirmware))
  9523. {
  9524. // Required data
  9525. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9526. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9527. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9528. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9529. // Optional data
  9530. if(json_object_object_get(UpdateFirmware, "retries"))
  9531. {
  9532. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9533. }
  9534. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9535. {
  9536. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9537. }
  9538. }
  9539. json_object_put(UpdateFirmware);
  9540. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9541. memset(path, 0, ARRAY_SIZE(path));
  9542. system("rm -f /mnt/*");
  9543. if(strncmp(locationstr,"http", 4) == 0)
  9544. {
  9545. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9546. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9547. // protocol, user, password, host, path);
  9548. sprintf(ftppath,"/%s", path);
  9549. DEBUG_INFO("locationstr: %s\n", locationstr);
  9550. DEBUG_INFO("protocol: %s\n",protocol);
  9551. DEBUG_INFO("host: %s\n",host);
  9552. DEBUG_INFO("path: %s\n",path);
  9553. DEBUG_INFO("ftppath: %s\n",ftppath);
  9554. int ftppathlen=strlen(ftppath);
  9555. int i=1;
  9556. char filenametemp[50];
  9557. while(i < ftppathlen)
  9558. {
  9559. int len=ftppathlen-i;
  9560. if(ftppath[len]== 47) // '/' ascll code: 47
  9561. {
  9562. DEBUG_INFO("compare '/' all right\n");
  9563. break;
  9564. }
  9565. i=i+1;
  9566. }
  9567. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9568. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9569. filenametemp[i+1] = 0;
  9570. do
  9571. {
  9572. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9573. sleep(3);
  9574. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9575. if(!isSuccess)
  9576. {
  9577. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9578. sleep(retryIntervalInt);
  9579. }
  9580. else
  9581. {
  9582. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9583. }
  9584. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9585. }
  9586. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9587. {
  9588. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9589. memset(temp, 0, ARRAY_SIZE(temp));
  9590. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9591. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9592. int ftppathlen=strlen(ftpbuf);
  9593. int i=1;
  9594. char filenametemp[50];
  9595. while(i < ftppathlen)
  9596. {
  9597. int len=ftppathlen-i;
  9598. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9599. {
  9600. DEBUG_INFO(" compare '/' all right\n");
  9601. break;
  9602. }
  9603. i=i+1;
  9604. }
  9605. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9606. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9607. filenametemp[i+1] = 0;
  9608. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9609. pch=strchr(temp,'@');
  9610. if(pch==NULL)
  9611. {
  9612. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9613. protocol, host, &port, path);
  9614. strcpy(user,"anonymous");
  9615. strcpy(password,"");
  9616. }
  9617. else
  9618. {
  9619. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9620. protocol, user, password, host, &port, path);
  9621. }
  9622. sscanf(host,"%[^/]%s",host1, path1);
  9623. sprintf(ftppath,"%s", path1);
  9624. //DEBUG_INFO("protocol =%s\n",protocol);
  9625. //DEBUG_INFO("user =%s\n",user);
  9626. //DEBUG_INFO("password =%s\n",password);
  9627. //DEBUG_INFO("host1 =%s\n",host1);
  9628. //DEBUG_INFO("port =%d\n",port);
  9629. //DEBUG_INFO("path1 =%s\n",path1);
  9630. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9631. //ftpFile(host, user, password, port, ftppath, fname);
  9632. //download firmware pthred
  9633. if(port == 0)
  9634. {
  9635. port = 21;
  9636. }
  9637. do
  9638. {
  9639. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9640. sleep(3);
  9641. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9642. if(!isSuccess)
  9643. {
  9644. //BulldogUtil.sleepMs(interval*1000);
  9645. DEBUG_INFO("Update firmware request and download file fail.\n");
  9646. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9647. sleep(retryIntervalInt);
  9648. }
  9649. else
  9650. {
  9651. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9652. }
  9653. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9654. }
  9655. else
  9656. {
  9657. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9658. }
  9659. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9660. pthread_exit(NULL);
  9661. }
  9662. //==========================================
  9663. // Handle server response routine
  9664. //==========================================
  9665. void handleAuthorizeResponse(char *payload, int gun_index)
  9666. {
  9667. mtrace();
  9668. char expiryDatestr[30]={0};
  9669. char parentIdTagstr[20]={0};
  9670. char statusstr[20]={0};
  9671. int expiryDateISNULL=FALSE;
  9672. int parentIdTagISNULL=FALSE;
  9673. DEBUG_INFO("handleAuthorizeResponse...\n");
  9674. json_object *Authorize;
  9675. Authorize = json_tokener_parse(payload);
  9676. if(!is_error(Authorize))
  9677. {
  9678. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9679. {
  9680. // Required data
  9681. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9682. // Optional data
  9683. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9684. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9685. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9686. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9687. }
  9688. }
  9689. json_object_put(Authorize);
  9690. if(expiryDateISNULL == FALSE)
  9691. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9692. if(parentIdTagISNULL == FALSE)
  9693. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9694. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9695. //Update idTag information to authorization cache if supproted
  9696. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9697. {
  9698. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  9699. }
  9700. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9701. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9702. authorizeRetryTimes = 0;
  9703. }
  9704. void handleBootNotificationResponse(char *payload, int gun_index)
  9705. {
  9706. mtrace();
  9707. char statusStr[12]={0};
  9708. char currentTimeStr[30]={0};
  9709. int intervalInt = 0;
  9710. struct tm tp;
  9711. char buf[28]={0};
  9712. char timebuf[50]={0};
  9713. DEBUG_INFO("handleBootNotificationResponse...\n");
  9714. json_object *BootNotification;
  9715. BootNotification = json_tokener_parse(payload);
  9716. if(!is_error(BootNotification))
  9717. {
  9718. // Required data
  9719. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9720. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9721. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9722. }
  9723. json_object_put(BootNotification);
  9724. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9725. BootNotificationInterval = intervalInt;
  9726. HeartBeatWaitTime = intervalInt;
  9727. //write back to ShmOCPP16Data->BootNotification
  9728. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9729. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9730. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9731. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9732. {
  9733. server_sign = TRUE;
  9734. server_pending =FALSE;
  9735. }
  9736. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9737. {
  9738. server_pending = TRUE;
  9739. }
  9740. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9741. tp.tm_isdst = -1;
  9742. //time_t utc = mktime(&tp);
  9743. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9744. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9745. sprintf(timebuf,"date -s '%s'",buf);
  9746. system(timebuf);
  9747. srand(time(NULL));
  9748. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9749. //==============================================
  9750. // RTC sync
  9751. //==============================================
  9752. system("/sbin/hwclock -w --systohc");
  9753. SetOcppConnStatus(TRUE);
  9754. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9755. }
  9756. void handleDataTransferResponse(char *payload, int gun_index)
  9757. {
  9758. char sstr[160]={0};//sstr[200]={ 0 };
  9759. int c = 0;
  9760. char *loc;
  9761. DEBUG_INFO("handleDataTransferResponse ...\n");
  9762. loc = strstr(payload, "status");
  9763. printf("loc=%s\n",loc);
  9764. c = 0;
  9765. while (loc[3+strlen("status")+c] != '\"')
  9766. {
  9767. sstr[c] = loc[3+strlen("status")+c];
  9768. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9769. c++;
  9770. }
  9771. sstr[c] = '\0';
  9772. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9773. }
  9774. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9775. {
  9776. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9777. //struct json_object *obj;
  9778. // obj = json_tokener_parse(payload);
  9779. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9780. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9781. //No fields are defined.
  9782. }
  9783. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9784. {
  9785. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9786. //struct json_object *obj;
  9787. // obj = json_tokener_parse(payload);
  9788. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9789. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9790. //No fields are defined.
  9791. }
  9792. void handleHeartbeatResponse(char *payload, int gun_index)
  9793. {
  9794. mtrace();
  9795. struct tm tp;
  9796. char buf[28]={0};
  9797. char timebuf[50]={0};
  9798. DEBUG_INFO("handleHeartbeatResponse...\n");
  9799. json_object *Heartbeat;
  9800. Heartbeat = json_tokener_parse(payload);
  9801. if(!is_error(Heartbeat))
  9802. {
  9803. // Required data
  9804. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9805. }
  9806. json_object_put(Heartbeat);
  9807. if(FirstHeartBeat == 0)
  9808. {
  9809. FirstHeartBeat = 1;
  9810. DEBUG_INFO("FirstHeartBeat \n");
  9811. }
  9812. HeartBeatWithNOResponse = 0;
  9813. clientTime.Heartbeat=time((time_t*)NULL);
  9814. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9815. tp.tm_isdst = -1;
  9816. //time_t utc = mktime(&tp);
  9817. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9818. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9819. sprintf(timebuf,"date -s '%s'",buf);
  9820. system(timebuf);
  9821. //==============================================
  9822. // RTC sync
  9823. //==============================================
  9824. system("/sbin/hwclock -w --systohc");
  9825. }
  9826. void handleMeterValuesResponse(char *payload, int gun_index)
  9827. {
  9828. mtrace();
  9829. DEBUG_INFO("handleMeterValuesResponse...\n");
  9830. }
  9831. void handleStartTransactionResponse(char *payload, int gun_index)
  9832. {
  9833. mtrace();
  9834. //int transactionIdInt = 0;
  9835. FILE *outfile;
  9836. char data[100]={0};
  9837. DEBUG_INFO("handleStartTransactionResponse...\n");
  9838. json_object *StartTransaction;
  9839. StartTransaction = json_tokener_parse(payload);
  9840. if(!is_error(StartTransaction))
  9841. {
  9842. // Required data
  9843. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9844. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9845. // Optional data
  9846. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9847. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9848. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9849. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9850. }
  9851. json_object_put(StartTransaction);
  9852. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9853. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9854. //-----------Start : write to the Queue TransactionId file -----------------//
  9855. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9856. {}
  9857. else
  9858. {
  9859. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9860. if(log == NULL)
  9861. {
  9862. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9863. return ;
  9864. }
  9865. else
  9866. {
  9867. fclose(log);
  9868. }
  9869. }
  9870. // open file for writing
  9871. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9872. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9873. {
  9874. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9875. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9876. fputs(data, outfile);
  9877. fclose (outfile);
  9878. }
  9879. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9880. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9881. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9882. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9883. }
  9884. void handleStatusNotificationResponse(char *payload, int gun_index)
  9885. {
  9886. mtrace();
  9887. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9888. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9889. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9890. }
  9891. void handleStopTransactionnResponse(char *payload, int gun_index)
  9892. {
  9893. mtrace();
  9894. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9895. json_object *StopTransaction;
  9896. StopTransaction = json_tokener_parse(payload);
  9897. if(!is_error(StopTransaction))
  9898. {
  9899. // Optional data
  9900. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9901. {
  9902. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9903. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9904. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9905. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9906. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9907. }
  9908. }
  9909. json_object_put(StopTransaction);
  9910. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9911. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9912. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9913. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9914. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9915. }
  9916. //==========================================
  9917. // Handle Error routine
  9918. //==========================================
  9919. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9920. {
  9921. mtrace();
  9922. #ifdef SystemLogMessage
  9923. DEBUG_INFO("errorCode: %s\n", errorCode);
  9924. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9925. DEBUG_INFO("errorDetails: %s\n", payload);
  9926. #endif
  9927. }
  9928. //===============================================
  9929. // Common routine
  9930. //===============================================
  9931. int initialConfigurationTable(void)
  9932. {
  9933. //clock_t start_t, end_t, total_t;
  9934. FILE *fp;
  9935. FILE *outfile;
  9936. char str[512]={0};
  9937. char sstr[256]={0};
  9938. int c = 0;
  9939. char *loc;
  9940. DEBUG_INFO("initialConfigurationTable...\n");
  9941. //start_t = clock();
  9942. //printf("Starting of the program, start_t = %ld\n", start_t);
  9943. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9944. // Check configuration file size is correct
  9945. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  9946. {
  9947. struct stat st;
  9948. stat("/Storage/OCPP/OCPPConfiguration", &st);
  9949. if(st.st_size < 3100)
  9950. {
  9951. system("rm -f /Storage/OCPP/OCPPConfiguration");
  9952. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  9953. }
  9954. }
  9955. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9956. {
  9957. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9958. if(outfile == NULL)
  9959. {
  9960. DEBUG_INFO("Error opening file\n");
  9961. return FALSE;
  9962. }
  9963. /*Core Profile*/
  9964. //AllowOfflineTxForUnknownId
  9965. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9969. //AuthorizationCacheEnabled
  9970. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9974. //AuthorizeRemoteTxRequests
  9975. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9979. //BlinkRepeat
  9980. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9984. //ClockAlignedDataInterval
  9985. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9989. //ConnectionTimeOut
  9990. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9994. //GetConfigurationMaxKeys
  9995. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  9998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9999. // HeartbeatInterval
  10000. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10004. // LightIntensity
  10005. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10009. // LocalAuthorizeOffline
  10010. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10014. // LocalPreAuthorize
  10015. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10019. // MaxEnergyOnInvalidId
  10020. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10023. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10025. // MeterValuesAlignedData
  10026. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10028. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10030. else
  10031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10033. // MeterValuesAlignedDataMaxLength
  10034. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10038. else
  10039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10041. // MeterValuesSampledData
  10042. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10044. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10046. else
  10047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10049. // MeterValuesSampledDataMaxLength
  10050. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10052. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10054. else
  10055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10057. // MeterValueSampleInterval
  10058. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10062. // MinimumStatusDuration
  10063. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10066. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10068. // NumberOfConnectors
  10069. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10072. {
  10073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10074. }
  10075. else
  10076. {
  10077. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10078. }
  10079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10080. // ResetRetries
  10081. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10085. // ConnectorPhaseRotation
  10086. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10090. // ConnectorPhaseRotationMaxLength
  10091. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10095. // StopTransactionOnEVSideDisconnect
  10096. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10100. // StopTransactionOnInvalidId
  10101. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10105. // StopTxnAlignedData
  10106. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10110. // StopTxnAlignedDataMaxLength
  10111. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10115. // StopTxnSampledData
  10116. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10118. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10120. else
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10123. // StopTxnSampledDataMaxLength
  10124. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10126. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10127. {
  10128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10129. }
  10130. else
  10131. {
  10132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10133. }
  10134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10135. // SupportedFeatureProfiles
  10136. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10140. // SupportedFeatureProfilesMaxLength
  10141. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10145. // TransactionMessageAttempts
  10146. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10149. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10151. // TransactionMessageRetryInterval
  10152. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10155. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10157. // UnlockConnectorOnEVSideDisconnect
  10158. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10162. // WebSocketPingInterval
  10163. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10167. // QueueOffLineStartTransactionMessage
  10168. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10172. // AuthorizationKey
  10173. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10177. // SecurityProfile
  10178. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10182. // DefaultPrice
  10183. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10187. // CustomDisplayCostAndPrice
  10188. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10192. // CustomIdleFeeAfterStop
  10193. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10197. //* Local Auth List Management Profile*/
  10198. #if 0
  10199. //For OCTT Test Case
  10200. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10203. #endif
  10204. #if 1
  10205. //LocalAuthListEnabled
  10206. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10210. #endif
  10211. //LocalAuthListMaxLength
  10212. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10216. //SendLocalListMaxLength
  10217. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10221. //ReserveConnectorZeroSupported
  10222. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10226. //* Smart Charging Profile */
  10227. //ChargeProfileMaxStackLevel
  10228. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10232. // ChargingScheduleAllowedChargingRateUnit
  10233. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10237. // ChargingScheduleMaxPeriods
  10238. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10242. // ConnectorSwitch3to1PhaseSupported
  10243. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10247. // MaxChargingProfilesInstalled
  10248. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10252. fclose(outfile);
  10253. }
  10254. else
  10255. {
  10256. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10257. char keystr[60]={0};
  10258. char readonlystr[10]={0};
  10259. char valuestr[256]={0};
  10260. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10261. if(fp == NULL) {
  10262. DEBUG_INFO("Error opening file");
  10263. return FALSE;
  10264. }
  10265. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10266. {
  10267. //DEBUG_INFO("Get Configuration \n");
  10268. if(strlen(str) > 0)
  10269. {
  10270. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10271. //*************************key*********************************/
  10272. if(strstr(str, "key") != NULL)
  10273. {
  10274. loc = strstr(str, "key");
  10275. c = 0;
  10276. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10277. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10278. {
  10279. sstr[c] = loc[strlen("key")+3+c];
  10280. c++;
  10281. }
  10282. sstr[c] = '\0';
  10283. strcpy(keystr,sstr);
  10284. }
  10285. //*************************readonly*********************************/
  10286. if(strstr(str, "readonly") != NULL)
  10287. {
  10288. loc = strstr(str, "readonly");
  10289. c = 0;
  10290. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10291. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  10292. {
  10293. sstr[c] = loc[strlen("readonly")+2+c];
  10294. c++;
  10295. }
  10296. sstr[c] = '\0';
  10297. strcpy(readonlystr,sstr);
  10298. }
  10299. //*************************value*********************************/
  10300. if(strstr(str, "value") != NULL)
  10301. {
  10302. loc = strstr(str, "value");
  10303. c = 0;
  10304. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10305. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10306. {
  10307. sstr[c] = loc[strlen("value")+3+c];
  10308. c++;
  10309. }
  10310. sstr[c] = '\0';
  10311. strcpy(valuestr,sstr);
  10312. }
  10313. // DEBUG_INFO("keystr=%s\n",keystr);
  10314. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10315. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10316. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10317. {
  10318. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10319. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10320. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10321. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10322. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10323. }
  10324. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10325. {
  10326. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10327. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10329. }
  10330. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10331. {
  10332. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10334. }
  10335. if(strcmp(keystr, "BlinkRepeat") == 0)
  10336. {
  10337. //Charger.BlinkRepeat = Integer.parseInt(value);
  10338. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10340. }
  10341. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10342. {
  10343. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10345. }
  10346. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10347. {
  10348. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10349. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10350. }
  10351. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10352. {
  10353. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10355. }
  10356. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10357. {
  10358. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10360. HeartBeatWaitTime = atoi(valuestr);
  10361. }
  10362. if(strcmp(keystr, "LightIntensity") == 0)
  10363. {
  10364. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10366. }
  10367. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10368. {
  10369. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10371. }
  10372. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10373. {
  10374. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10376. }
  10377. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10378. {
  10379. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10380. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10381. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10382. }
  10383. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10384. {
  10385. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10387. }
  10388. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10389. {
  10390. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10392. }
  10393. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10394. {
  10395. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10397. }
  10398. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10399. {
  10400. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10402. }
  10403. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10404. {
  10405. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10407. }
  10408. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10409. {
  10410. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10412. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10413. }
  10414. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10415. {
  10416. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10418. }
  10419. if(strcmp(keystr, "ResetRetries") == 0)
  10420. {
  10421. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10423. }
  10424. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10425. {
  10426. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10428. }
  10429. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10430. {
  10431. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10433. }
  10434. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10435. {
  10436. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10438. }
  10439. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10440. {
  10441. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10443. }
  10444. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10445. {
  10446. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10448. }
  10449. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10450. {
  10451. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10453. }
  10454. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10455. {
  10456. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10458. }
  10459. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10460. {
  10461. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10463. }
  10464. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10465. {
  10466. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10468. }
  10469. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10470. {
  10471. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10473. }
  10474. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10475. {
  10476. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10478. TransactionMessageAttemptsValue = atoi(valuestr);
  10479. }
  10480. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10481. {
  10482. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10484. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10485. }
  10486. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10487. {
  10488. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10490. }
  10491. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10492. {
  10493. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10495. }
  10496. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10497. {
  10498. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10500. }
  10501. if(strcmp(keystr, "AuthorizationKey") == 0)
  10502. {
  10503. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10505. }
  10506. if(strcmp(keystr, "SecurityProfile") == 0)
  10507. {
  10508. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10510. }
  10511. if(strcmp(keystr, "DefaultPrice") == 0)
  10512. {
  10513. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10515. }
  10516. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10517. {
  10518. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10520. }
  10521. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10522. {
  10523. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10525. }
  10526. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10527. {
  10528. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10530. }
  10531. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10532. {
  10533. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10535. }
  10536. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10537. {
  10538. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10540. }
  10541. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10542. {
  10543. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10545. }
  10546. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10547. {
  10548. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10550. }
  10551. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10552. {
  10553. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10555. }
  10556. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10557. {
  10558. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10560. }
  10561. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10562. {
  10563. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10565. }
  10566. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10567. {
  10568. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10570. }
  10571. }
  10572. }
  10573. fclose(fp);
  10574. }
  10575. return 0;
  10576. }
  10577. void StoreConfigurationTable(void)
  10578. {
  10579. FILE *outfile;
  10580. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10581. if(outfile == NULL)
  10582. {
  10583. DEBUG_INFO("Error opening file");
  10584. return ;
  10585. }
  10586. /*Core Profile*/
  10587. //AllowOfflineTxForUnknownId
  10588. /*
  10589. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10590. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10593. */
  10594. //DEBUG_INFO("data=%s\n",data);
  10595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10596. //AuthorizationCacheEnabled
  10597. /*
  10598. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10601. */
  10602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10603. //AuthorizeRemoteTxRequests
  10604. /*
  10605. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10608. */
  10609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10610. //BlinkRepeat
  10611. /*
  10612. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10615. */
  10616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10617. //ClockAlignedDataInterval
  10618. /*
  10619. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10622. */
  10623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10624. //ConnectionTimeOut
  10625. /*
  10626. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10629. */
  10630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10631. //GetConfigurationMaxKeys
  10632. /*
  10633. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10636. */
  10637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10638. // HeartbeatInterval
  10639. /*
  10640. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10643. */
  10644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10645. // LightIntensity
  10646. /*
  10647. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10650. */
  10651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10652. // LocalAuthorizeOffline
  10653. /*
  10654. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10657. */
  10658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10659. // LocalPreAuthorize
  10660. /*
  10661. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10664. */
  10665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10666. // MaxEnergyOnInvalidId
  10667. /*
  10668. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10671. */
  10672. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10674. // MeterValuesAlignedData
  10675. /*
  10676. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10679. */
  10680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10681. // MeterValuesAlignedDataMaxLength
  10682. /*
  10683. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10686. */
  10687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10688. // MeterValuesSampledData
  10689. /*
  10690. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10693. */
  10694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10695. // MeterValuesSampledDataMaxLength
  10696. /*
  10697. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10700. */
  10701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10702. // MeterValueSampleInterval
  10703. /*
  10704. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10707. */
  10708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10709. // MinimumStatusDuration
  10710. /*
  10711. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10714. */
  10715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10716. // NumberOfConnectors
  10717. /*
  10718. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10720. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10721. {
  10722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10723. }
  10724. else
  10725. {
  10726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10727. }
  10728. */
  10729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10730. // ResetRetries
  10731. /*
  10732. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10735. */
  10736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10737. // ConnectorPhaseRotation
  10738. /*
  10739. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10742. */
  10743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10744. // ConnectorPhaseRotationMaxLength
  10745. /*
  10746. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10749. */
  10750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10751. // StopTransactionOnEVSideDisconnect
  10752. /*
  10753. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10756. */
  10757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10758. // StopTransactionOnInvalidId
  10759. /*
  10760. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10763. */
  10764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10765. // StopTxnAlignedData
  10766. /*
  10767. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10770. */
  10771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10772. // StopTxnAlignedDataMaxLength
  10773. /*
  10774. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10777. */
  10778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10779. // StopTxnSampledData
  10780. /*
  10781. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10784. */
  10785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10786. // StopTxnSampledDataMaxLength
  10787. /*
  10788. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10791. */
  10792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10793. // SupportedFeatureProfiles
  10794. /*
  10795. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10798. */
  10799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10800. // SupportedFeatureProfilesMaxLength
  10801. /*
  10802. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10805. */
  10806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10807. // TransactionMessageAttempts
  10808. /*
  10809. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10812. */
  10813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10814. // TransactionMessageRetryInterval
  10815. /*
  10816. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10819. */
  10820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10821. // UnlockConnectorOnEVSideDisconnect
  10822. /*
  10823. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10826. */
  10827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10828. // WebSocketPingInterval
  10829. /*
  10830. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10833. */
  10834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10835. // QueueOffLineStartTransactionMessage
  10836. /*
  10837. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10840. */
  10841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10842. // AuthorizationKey
  10843. /*
  10844. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10847. */
  10848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10849. // SecurityProfile
  10850. /*
  10851. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10854. */
  10855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10856. // DefaultPrice
  10857. /*
  10858. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10861. */
  10862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10863. // CustomDisplayCostAndPrice
  10864. /*
  10865. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10868. */
  10869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10870. // CustomIdleFeeAfterStop
  10871. /*
  10872. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10875. */
  10876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10877. //* Local Auth List Management Profile*/
  10878. //LocalAuthListEnabled
  10879. /*
  10880. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10883. */
  10884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10885. //LocalAuthListMaxLength
  10886. /*
  10887. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10890. */
  10891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10892. //SendLocalListMaxLength
  10893. /*
  10894. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10897. */
  10898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10899. //ReserveConnectorZeroSupported
  10900. /*
  10901. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10904. */
  10905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10906. //* Smart Charging Profile */
  10907. //ChargeProfileMaxStackLevel
  10908. /*
  10909. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10912. */
  10913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10914. // ChargingScheduleAllowedChargingRateUnit
  10915. /*
  10916. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10919. */
  10920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10921. // ChargingScheduleMaxPeriods
  10922. /*
  10923. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10926. */
  10927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10928. // ConnectorSwitch3to1PhaseSupported
  10929. /*
  10930. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10933. */
  10934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10935. // MaxChargingProfilesInstalled
  10936. /*
  10937. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10940. */
  10941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10942. fclose(outfile);
  10943. }
  10944. void getKeyValue(char *keyReq)
  10945. {
  10946. int isEmpty = FALSE;
  10947. int isKnowKey = FALSE;
  10948. DEBUG_INFO("keyReq = %s\n", keyReq);
  10949. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10950. isEmpty = TRUE;
  10951. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10952. {
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10955. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10956. {
  10957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10958. }
  10959. else
  10960. {
  10961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10962. }
  10963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10964. isKnowKey = TRUE;
  10965. }
  10966. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10967. {
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10971. {
  10972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10973. }
  10974. else
  10975. {
  10976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10977. }
  10978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10979. isKnowKey = TRUE;
  10980. }
  10981. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10982. {
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10986. {
  10987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10988. }
  10989. else
  10990. {
  10991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10992. }
  10993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10994. isKnowKey = TRUE;
  10995. }
  10996. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10997. {
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11001. {
  11002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11003. }
  11004. else
  11005. {
  11006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11007. }
  11008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11009. isKnowKey = TRUE;
  11010. }
  11011. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11012. {
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11016. {
  11017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11018. }
  11019. else
  11020. {
  11021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11022. }
  11023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11024. isKnowKey = TRUE;
  11025. }
  11026. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11027. {
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11030. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11031. {
  11032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11033. }
  11034. else
  11035. {
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11037. }
  11038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11039. isKnowKey = TRUE;
  11040. }
  11041. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11042. {
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11046. {
  11047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11048. }
  11049. else
  11050. {
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11052. }
  11053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11054. isKnowKey = TRUE;
  11055. }
  11056. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11057. {
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11061. {
  11062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11063. }
  11064. else
  11065. {
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11067. }
  11068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11069. isKnowKey = TRUE;
  11070. }
  11071. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11072. {
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11076. {
  11077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11078. }
  11079. else
  11080. {
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11082. }
  11083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11084. isKnowKey = TRUE;
  11085. }
  11086. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11087. {
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11091. {
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11093. }
  11094. else
  11095. {
  11096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11097. }
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11099. isKnowKey = TRUE;
  11100. }
  11101. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11102. {
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11106. {
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11108. }
  11109. else
  11110. {
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11112. }
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11114. isKnowKey = TRUE;
  11115. }
  11116. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11117. {
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11121. {
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11123. }
  11124. else
  11125. {
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11127. }
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11129. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11130. isKnowKey = TRUE;
  11131. }
  11132. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11133. {
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11136. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11137. {
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11139. }
  11140. else
  11141. {
  11142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11143. }
  11144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11145. isKnowKey = TRUE;
  11146. }
  11147. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11148. {
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11152. {
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11154. }
  11155. else
  11156. {
  11157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11158. }
  11159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11160. isKnowKey = TRUE;
  11161. }
  11162. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11163. {
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11166. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11167. {
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11169. }
  11170. else
  11171. {
  11172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11173. }
  11174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11175. isKnowKey = TRUE;
  11176. }
  11177. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11178. {
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11182. {
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11184. }
  11185. else
  11186. {
  11187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11188. }
  11189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11190. isKnowKey = TRUE;
  11191. }
  11192. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11193. {
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11197. {
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11199. }
  11200. else
  11201. {
  11202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11203. }
  11204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11205. isKnowKey = TRUE;
  11206. }
  11207. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11208. {
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11211. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11212. {
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11214. }
  11215. else
  11216. {
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11218. }
  11219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11220. isKnowKey = TRUE;
  11221. }
  11222. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11223. {
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11227. {
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11229. }
  11230. else
  11231. {
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11233. }
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11235. isKnowKey = TRUE;
  11236. }
  11237. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11238. {
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11244. }
  11245. else
  11246. {
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11248. }
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11250. isKnowKey = TRUE;
  11251. }
  11252. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11253. {
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11259. }
  11260. else
  11261. {
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11263. }
  11264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11265. isKnowKey = TRUE;
  11266. }
  11267. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11268. {
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11272. {
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11274. }
  11275. else
  11276. {
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11278. }
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11280. isKnowKey = TRUE;
  11281. }
  11282. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11283. {
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11287. {
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11289. }
  11290. else
  11291. {
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11293. }
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11295. isKnowKey = TRUE;
  11296. }
  11297. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11298. {
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11302. {
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11304. }
  11305. else
  11306. {
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11308. }
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11310. isKnowKey = TRUE;
  11311. }
  11312. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11313. {
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11317. {
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11319. }
  11320. else
  11321. {
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11323. }
  11324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11325. isKnowKey = TRUE;
  11326. }
  11327. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11328. {
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11332. {
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11334. }
  11335. else
  11336. {
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11338. }
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11340. isKnowKey = TRUE;
  11341. }
  11342. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11343. {
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11347. {
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11349. }
  11350. else
  11351. {
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11353. }
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11355. isKnowKey = TRUE;
  11356. }
  11357. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11358. {
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11362. {
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11364. }
  11365. else
  11366. {
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11368. }
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11370. isKnowKey = TRUE;
  11371. }
  11372. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11373. {
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11377. {
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11379. }
  11380. else
  11381. {
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11383. }
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11385. isKnowKey = TRUE;
  11386. }
  11387. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11388. {
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11392. {
  11393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11394. }
  11395. else
  11396. {
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11398. }
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11400. isKnowKey = TRUE;
  11401. }
  11402. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11403. {
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11407. {
  11408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11409. }
  11410. else
  11411. {
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11413. }
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11415. isKnowKey = TRUE;
  11416. }
  11417. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11418. {
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11422. {
  11423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11424. }
  11425. else
  11426. {
  11427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11428. }
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11430. isKnowKey = TRUE;
  11431. }
  11432. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11433. {
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11437. {
  11438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11439. }
  11440. else
  11441. {
  11442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11443. }
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11445. isKnowKey = TRUE;
  11446. }
  11447. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11448. {
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11452. {
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11454. }
  11455. else
  11456. {
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11458. }
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11460. isKnowKey = TRUE;
  11461. }
  11462. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11463. {
  11464. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11466. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11467. {
  11468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11469. }
  11470. else
  11471. {
  11472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11473. }
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11475. isKnowKey = TRUE;
  11476. }
  11477. /*
  11478. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11479. {
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11482. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11483. {
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11485. }
  11486. else
  11487. {
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11489. }
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11491. isKnowKey = TRUE;
  11492. }*/
  11493. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11494. {
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11497. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11498. {
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11500. }
  11501. else
  11502. {
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11504. }
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11506. isKnowKey = TRUE;
  11507. }
  11508. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11509. {
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11513. {
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11515. }
  11516. else
  11517. {
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11519. }
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11521. isKnowKey = TRUE;
  11522. }
  11523. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11524. {
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11528. {
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11530. }
  11531. else
  11532. {
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11534. }
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11536. isKnowKey = TRUE;
  11537. }
  11538. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11539. {
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11543. {
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11545. }
  11546. else
  11547. {
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11549. }
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11551. isKnowKey = TRUE;
  11552. }
  11553. #if 1
  11554. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11555. {
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11558. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11561. }
  11562. else
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11565. }
  11566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11567. isKnowKey = TRUE;
  11568. }
  11569. #endif
  11570. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11571. {
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11574. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11575. {
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11577. }
  11578. else
  11579. {
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11581. }
  11582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11583. isKnowKey = TRUE;
  11584. }
  11585. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11586. {
  11587. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11589. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11590. {
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11592. }
  11593. else
  11594. {
  11595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11596. }
  11597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11598. isKnowKey = TRUE;
  11599. }
  11600. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11601. {
  11602. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11604. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11605. {
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11607. }
  11608. else
  11609. {
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11611. }
  11612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11613. isKnowKey = TRUE;
  11614. }
  11615. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11616. {
  11617. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11619. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11620. {
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11622. }
  11623. else
  11624. {
  11625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11626. }
  11627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11628. isKnowKey = TRUE;
  11629. }
  11630. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11631. {
  11632. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11634. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11635. {
  11636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11637. }
  11638. else
  11639. {
  11640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11641. }
  11642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11643. isKnowKey = TRUE;
  11644. }
  11645. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11646. {
  11647. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11649. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11650. {
  11651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11652. }
  11653. else
  11654. {
  11655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11656. }
  11657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11658. isKnowKey = TRUE;
  11659. }
  11660. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11661. {
  11662. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11664. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11665. {
  11666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11667. }
  11668. else
  11669. {
  11670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11671. }
  11672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11673. isKnowKey = TRUE;
  11674. }
  11675. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11676. {
  11677. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11679. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11680. {
  11681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11682. }
  11683. else
  11684. {
  11685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11686. }
  11687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11688. isKnowKey = TRUE;
  11689. }
  11690. //=========================================================
  11691. if(!isEmpty && !isKnowKey)
  11692. {
  11693. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11694. strcpy(unknownkey[UnknownKeynum], keyReq);
  11695. UnknownKeynum = UnknownKeynum + 1;
  11696. }
  11697. }
  11698. void processUnkownKey(void)
  11699. {
  11700. DEBUG_INFO("processUnkownKey...\n");
  11701. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11702. for(int index=0; index < UnknownKeynum; index++)
  11703. {
  11704. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11705. {
  11706. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11707. }
  11708. }
  11709. }
  11710. int setKeyValue(char *key, char *value)
  11711. {
  11712. int isSuccess = NotSupported;
  11713. int check_ascii=0;
  11714. char str[10]={0};
  11715. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11716. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11717. {
  11718. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11719. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11720. {
  11721. strcpy(str, (const char*)value);
  11722. for(int i = 0; str[i]; i++){
  11723. str[i] = tolower(str[i]);
  11724. }
  11725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11726. isSuccess = ConfigurationStatus_Accepted;
  11727. }
  11728. else
  11729. {
  11730. isSuccess = ConfigurationStatus_Rejected;
  11731. }
  11732. }
  11733. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11734. {
  11735. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11737. {
  11738. strcpy(str, (const char*)value);
  11739. for(int i = 0; str[i]; i++){
  11740. str[i] = tolower(str[i]);
  11741. }
  11742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11743. isSuccess = ConfigurationStatus_Accepted;
  11744. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11745. }
  11746. else
  11747. {
  11748. isSuccess = ConfigurationStatus_Rejected;
  11749. }
  11750. }
  11751. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11752. {
  11753. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11754. {
  11755. strcpy(str, (const char*)value);
  11756. for(int i = 0; str[i]; i++)
  11757. {
  11758. str[i] = tolower(str[i]);
  11759. }
  11760. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11762. isSuccess = ConfigurationStatus_Accepted;
  11763. }
  11764. else
  11765. {
  11766. isSuccess = ConfigurationStatus_Rejected;
  11767. }
  11768. }
  11769. if(strcmp(key, "BlinkRepeat") == 0)
  11770. {
  11771. //Charger.BlinkRepeat = Integer.parseInt(value);
  11772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11773. {
  11774. check_ascii = value[0];
  11775. if( (check_ascii < 48) || (check_ascii > 57) )
  11776. {
  11777. isSuccess = ConfigurationStatus_Rejected;
  11778. }
  11779. else
  11780. {
  11781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11782. isSuccess = ConfigurationStatus_Accepted;
  11783. }
  11784. }
  11785. else
  11786. {
  11787. isSuccess = ConfigurationStatus_Rejected;
  11788. }
  11789. }
  11790. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11791. {
  11792. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11793. {
  11794. check_ascii = value[0];
  11795. if( (check_ascii < 48) || (check_ascii > 57) )
  11796. {
  11797. isSuccess = ConfigurationStatus_Rejected;
  11798. }
  11799. else
  11800. {
  11801. if((atoi(value) == 0) || (atoi(value) >= 10))
  11802. {
  11803. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11805. isSuccess = ConfigurationStatus_Accepted;
  11806. }
  11807. else
  11808. isSuccess = ConfigurationStatus_Rejected;
  11809. }
  11810. }
  11811. else
  11812. {
  11813. isSuccess = ConfigurationStatus_Rejected;
  11814. }
  11815. }
  11816. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11817. {
  11818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11819. {
  11820. check_ascii = value[0];
  11821. if( (check_ascii < 48) || (check_ascii > 57) )
  11822. {
  11823. isSuccess = ConfigurationStatus_Rejected;
  11824. }
  11825. else
  11826. {
  11827. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11829. isSuccess = ConfigurationStatus_Accepted;
  11830. }
  11831. }
  11832. else
  11833. {
  11834. isSuccess = ConfigurationStatus_Rejected;
  11835. }
  11836. }
  11837. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11838. {
  11839. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11840. {
  11841. check_ascii = value[0];
  11842. if( (check_ascii < 48) || (check_ascii > 57) )
  11843. {
  11844. isSuccess = ConfigurationStatus_Rejected;
  11845. }
  11846. else
  11847. {
  11848. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11850. isSuccess = ConfigurationStatus_Accepted;
  11851. }
  11852. }
  11853. else
  11854. {
  11855. isSuccess = ConfigurationStatus_Rejected;
  11856. }
  11857. }
  11858. if(strcmp(key, "HeartbeatInterval") == 0)
  11859. {
  11860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11861. {
  11862. check_ascii = value[0];
  11863. if( (check_ascii < 48) || (check_ascii > 57) )
  11864. {
  11865. isSuccess = ConfigurationStatus_Rejected;
  11866. }
  11867. else
  11868. {
  11869. if((atoi(value) == 0) || (atoi(value) >= 10))
  11870. {
  11871. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11873. HeartBeatWaitTime = atoi(value);
  11874. isSuccess = ConfigurationStatus_Accepted;
  11875. }
  11876. else
  11877. {
  11878. isSuccess = ConfigurationStatus_Rejected;
  11879. }
  11880. }
  11881. }
  11882. else
  11883. {
  11884. isSuccess = ConfigurationStatus_Rejected;
  11885. }
  11886. }
  11887. if(strcmp(key, "LightIntensity") == 0)
  11888. {
  11889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11890. {
  11891. check_ascii = value[0];
  11892. if( (check_ascii < 48) || (check_ascii > 57) )
  11893. {
  11894. isSuccess = ConfigurationStatus_Rejected;
  11895. }
  11896. else
  11897. {
  11898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11899. isSuccess = ConfigurationStatus_Accepted;
  11900. }
  11901. }
  11902. else
  11903. {
  11904. isSuccess = ConfigurationStatus_Rejected;
  11905. }
  11906. }
  11907. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11908. {
  11909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11910. {
  11911. strcpy(str, (const char*)value);
  11912. for(int i = 0; str[i]; i++)
  11913. {
  11914. str[i] = tolower(str[i]);
  11915. }
  11916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11917. isSuccess = ConfigurationStatus_Accepted;
  11918. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11919. }
  11920. else
  11921. {
  11922. isSuccess = ConfigurationStatus_Rejected;
  11923. }
  11924. }
  11925. if(strcmp(key, "LocalPreAuthorize") == 0)
  11926. {
  11927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11928. {
  11929. strcpy(str, (const char*)value);
  11930. for(int i = 0; str[i]; i++)
  11931. {
  11932. str[i] = tolower(str[i]);
  11933. }
  11934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11935. isSuccess = ConfigurationStatus_Accepted;
  11936. }
  11937. else
  11938. {
  11939. isSuccess = ConfigurationStatus_Rejected;
  11940. }
  11941. }
  11942. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11943. {
  11944. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11945. {
  11946. check_ascii = value[0];
  11947. if( (check_ascii < 48) || (check_ascii > 57) )
  11948. {
  11949. isSuccess = ConfigurationStatus_Rejected;
  11950. }
  11951. else
  11952. {
  11953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11954. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11955. isSuccess = ConfigurationStatus_Accepted;
  11956. }
  11957. }
  11958. else
  11959. {
  11960. isSuccess = ConfigurationStatus_Rejected;
  11961. }
  11962. }
  11963. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11964. {
  11965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11966. {
  11967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11968. isSuccess = ConfigurationStatus_Accepted;
  11969. }
  11970. else
  11971. {
  11972. isSuccess = ConfigurationStatus_Rejected;
  11973. }
  11974. }
  11975. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11976. {
  11977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11978. {
  11979. check_ascii = value[0];
  11980. if( (check_ascii < 48) || (check_ascii > 57) )
  11981. {
  11982. isSuccess = ConfigurationStatus_Rejected;
  11983. }
  11984. else
  11985. {
  11986. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11988. isSuccess = ConfigurationStatus_Accepted;
  11989. }
  11990. }
  11991. else
  11992. {
  11993. isSuccess = ConfigurationStatus_Rejected;
  11994. }
  11995. }
  11996. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11997. {
  11998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11999. {
  12000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12001. isSuccess = ConfigurationStatus_Accepted;
  12002. }
  12003. else
  12004. {
  12005. isSuccess = ConfigurationStatus_Rejected;
  12006. }
  12007. }
  12008. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12009. {
  12010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12011. {
  12012. check_ascii = value[0];
  12013. if( (check_ascii < 48) || (check_ascii > 57) )
  12014. {
  12015. isSuccess = ConfigurationStatus_Rejected;
  12016. }
  12017. else
  12018. {
  12019. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12021. isSuccess = ConfigurationStatus_Accepted;
  12022. }
  12023. }
  12024. else
  12025. {
  12026. isSuccess = ConfigurationStatus_Rejected;
  12027. }
  12028. }
  12029. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12030. {
  12031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12032. {
  12033. check_ascii = value[0];
  12034. if( (check_ascii < 48) || (check_ascii > 57) )
  12035. {
  12036. isSuccess = ConfigurationStatus_Rejected;
  12037. }
  12038. else
  12039. {
  12040. if((atoi(value) == 0) || (atoi(value) >= 10))
  12041. {
  12042. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12044. isSuccess = ConfigurationStatus_Accepted;
  12045. }
  12046. else
  12047. {
  12048. isSuccess = ConfigurationStatus_Rejected;
  12049. }
  12050. }
  12051. }
  12052. else
  12053. {
  12054. isSuccess = ConfigurationStatus_Rejected;
  12055. }
  12056. }
  12057. if(strcmp(key, "MinimumStatusDuration") == 0)
  12058. {
  12059. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12060. {
  12061. check_ascii = value[0];
  12062. if( (check_ascii < 48) || (check_ascii > 57) )
  12063. {
  12064. isSuccess = ConfigurationStatus_Rejected;
  12065. }
  12066. else
  12067. {
  12068. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12069. {
  12070. isSuccess = ConfigurationStatus_Rejected;
  12071. }
  12072. else
  12073. {
  12074. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12076. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12077. isSuccess = ConfigurationStatus_Accepted;
  12078. }
  12079. }
  12080. }
  12081. else
  12082. {
  12083. isSuccess = ConfigurationStatus_Rejected;
  12084. }
  12085. }
  12086. if(strcmp(key, "NumberOfConnectors") == 0)
  12087. {
  12088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12089. {
  12090. check_ascii = value[0];
  12091. if( (check_ascii < 48) || (check_ascii > 57) )
  12092. {
  12093. isSuccess = ConfigurationStatus_Rejected;
  12094. }
  12095. else
  12096. {
  12097. //Charger.ResetRetries = Integer.parseInt(value);
  12098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12099. isSuccess = ConfigurationStatus_Accepted;
  12100. }
  12101. }
  12102. else
  12103. {
  12104. isSuccess = ConfigurationStatus_Rejected;
  12105. }
  12106. }
  12107. if(strcmp(key, "ResetRetries") == 0)
  12108. {
  12109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12110. {
  12111. check_ascii = value[0];
  12112. if( (check_ascii < 48) || (check_ascii > 57) )
  12113. {
  12114. isSuccess = ConfigurationStatus_Rejected;
  12115. }
  12116. else
  12117. {
  12118. //Charger.ResetRetries = Integer.parseInt(value);
  12119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12120. isSuccess = ConfigurationStatus_Accepted;
  12121. }
  12122. }
  12123. else
  12124. {
  12125. isSuccess = ConfigurationStatus_Rejected;
  12126. }
  12127. }
  12128. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12129. {
  12130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12131. {
  12132. strcpy(str, (const char*)value);
  12133. for(int i = 0; str[i]; i++)
  12134. {
  12135. str[i] = tolower(str[i]);
  12136. }
  12137. if(strcmp(str, "notapplicable")== 0)
  12138. {
  12139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12140. isSuccess = ConfigurationStatus_Accepted;
  12141. }
  12142. else if(strcmp(str, "unknown")== 0)
  12143. {
  12144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12145. isSuccess = ConfigurationStatus_Accepted;
  12146. }
  12147. else if(strcmp(str, "rst")== 0)
  12148. {
  12149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12150. isSuccess = ConfigurationStatus_Accepted;
  12151. }
  12152. else if(strcmp(str, "rts")== 0)
  12153. {
  12154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12155. isSuccess = ConfigurationStatus_Accepted;
  12156. }
  12157. else if(strcmp(str, "srt")== 0)
  12158. {
  12159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12160. isSuccess = ConfigurationStatus_Accepted;
  12161. }
  12162. else if(strcmp(str, "str")== 0)
  12163. {
  12164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12165. isSuccess = ConfigurationStatus_Accepted;
  12166. }
  12167. else if(strcmp(str, "trs")== 0)
  12168. {
  12169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12170. isSuccess = ConfigurationStatus_Accepted;
  12171. }
  12172. else if(strcmp(str, "tsr")== 0)
  12173. {
  12174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12175. isSuccess = ConfigurationStatus_Accepted;
  12176. }
  12177. else
  12178. {
  12179. isSuccess = ConfigurationStatus_Rejected;
  12180. }
  12181. }
  12182. else
  12183. {
  12184. isSuccess = ConfigurationStatus_Rejected;
  12185. }
  12186. }
  12187. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12188. {
  12189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12190. {
  12191. check_ascii = value[0];
  12192. if( (check_ascii < 48) || (check_ascii > 57) )
  12193. {
  12194. isSuccess = ConfigurationStatus_Rejected;
  12195. }
  12196. else
  12197. {
  12198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12199. isSuccess = ConfigurationStatus_Accepted;
  12200. }
  12201. }
  12202. else
  12203. {
  12204. isSuccess = ConfigurationStatus_Rejected;
  12205. }
  12206. }
  12207. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12208. {
  12209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12210. {
  12211. strcpy(str, (const char*)value);
  12212. for(int i = 0; str[i]; i++)
  12213. {
  12214. str[i] = tolower(str[i]);
  12215. }
  12216. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12218. isSuccess = ConfigurationStatus_Accepted;
  12219. }
  12220. else
  12221. {
  12222. isSuccess = ConfigurationStatus_Rejected;
  12223. }
  12224. }
  12225. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12226. {
  12227. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12228. {
  12229. strcpy(str, (const char*)value);
  12230. for(int i = 0; str[i]; i++)
  12231. {
  12232. str[i] = tolower(str[i]);
  12233. }
  12234. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12236. isSuccess = ConfigurationStatus_Accepted;
  12237. }
  12238. else
  12239. {
  12240. isSuccess = ConfigurationStatus_Rejected;
  12241. }
  12242. }
  12243. if(strcmp(key, "StopTxnAlignedData") == 0)
  12244. {
  12245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12246. {
  12247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12248. isSuccess = ConfigurationStatus_Accepted;
  12249. }
  12250. else
  12251. {
  12252. isSuccess = ConfigurationStatus_Rejected;
  12253. }
  12254. }
  12255. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12256. {
  12257. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12258. {
  12259. check_ascii = value[0];
  12260. if( (check_ascii < 48) || (check_ascii > 57) )
  12261. {
  12262. isSuccess = ConfigurationStatus_Rejected;
  12263. }
  12264. else
  12265. {
  12266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12267. isSuccess = ConfigurationStatus_Accepted;
  12268. }
  12269. }
  12270. else
  12271. {
  12272. isSuccess = ConfigurationStatus_Rejected;
  12273. }
  12274. }
  12275. if(strcmp(key, "StopTxnSampledData") == 0)
  12276. {
  12277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12278. {
  12279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12280. isSuccess = ConfigurationStatus_Accepted;
  12281. }
  12282. else
  12283. {
  12284. isSuccess = ConfigurationStatus_Rejected;
  12285. }
  12286. }
  12287. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12288. {
  12289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12290. {
  12291. check_ascii = value[0];
  12292. if( (check_ascii < 48) || (check_ascii > 57) )
  12293. {
  12294. isSuccess = ConfigurationStatus_Rejected;
  12295. }
  12296. else
  12297. {
  12298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12299. isSuccess = ConfigurationStatus_Accepted;
  12300. }
  12301. }
  12302. else
  12303. {
  12304. isSuccess = ConfigurationStatus_Rejected;
  12305. }
  12306. }
  12307. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12308. {
  12309. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12310. {
  12311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12312. isSuccess = ConfigurationStatus_Accepted;
  12313. }
  12314. else
  12315. {
  12316. isSuccess = ConfigurationStatus_Rejected;
  12317. }
  12318. }
  12319. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12320. {
  12321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12322. {
  12323. check_ascii = value[0];
  12324. if( (check_ascii < 48) || (check_ascii > 57) )
  12325. {
  12326. isSuccess = ConfigurationStatus_Rejected;
  12327. }
  12328. else
  12329. {
  12330. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12331. isSuccess = ConfigurationStatus_Accepted;
  12332. }
  12333. }
  12334. else
  12335. {
  12336. isSuccess = ConfigurationStatus_Rejected;
  12337. }
  12338. }
  12339. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12340. {
  12341. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12342. {
  12343. check_ascii = value[0];
  12344. if( (check_ascii < 48) || (check_ascii > 57) )
  12345. {
  12346. isSuccess = ConfigurationStatus_Rejected;
  12347. }
  12348. else
  12349. {
  12350. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12352. TransactionMessageAttemptsValue = atoi(value);
  12353. isSuccess = ConfigurationStatus_Accepted;
  12354. }
  12355. }
  12356. else
  12357. {
  12358. isSuccess = ConfigurationStatus_Rejected;
  12359. }
  12360. }
  12361. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12362. {
  12363. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12364. {
  12365. check_ascii = value[0];
  12366. if( (check_ascii < 48) || (check_ascii > 57) )
  12367. {
  12368. isSuccess = ConfigurationStatus_Rejected;
  12369. }
  12370. else
  12371. {
  12372. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12373. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12374. TransactionMessageRetryIntervalValue = atoi(value);
  12375. isSuccess = ConfigurationStatus_Accepted;
  12376. }
  12377. }
  12378. else
  12379. {
  12380. isSuccess = ConfigurationStatus_Rejected;
  12381. }
  12382. }
  12383. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12384. {
  12385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12386. {
  12387. strcpy(str, (const char*)value);
  12388. for(int i = 0; str[i]; i++)
  12389. {
  12390. str[i] = tolower(str[i]);
  12391. }
  12392. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12394. isSuccess = ConfigurationStatus_Accepted;
  12395. }
  12396. else
  12397. {
  12398. isSuccess = ConfigurationStatus_Rejected;
  12399. }
  12400. }
  12401. if(strcmp(key, "WebSocketPingInterval") == 0)
  12402. {
  12403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12404. {
  12405. check_ascii = value[0];
  12406. if( (check_ascii < 48) || (check_ascii > 57) )
  12407. {
  12408. isSuccess = ConfigurationStatus_Rejected;
  12409. }
  12410. else
  12411. {
  12412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12413. isSuccess = ConfigurationStatus_Accepted;
  12414. }
  12415. }
  12416. else
  12417. {
  12418. isSuccess = ConfigurationStatus_Rejected;
  12419. }
  12420. }
  12421. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12422. {
  12423. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12424. {
  12425. strcpy(str, (const char*)value);
  12426. for(int i = 0; str[i]; i++)
  12427. {
  12428. str[i] = tolower(str[i]);
  12429. }
  12430. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12432. isSuccess = ConfigurationStatus_Accepted;
  12433. }
  12434. else
  12435. {
  12436. isSuccess = ConfigurationStatus_Rejected;
  12437. }
  12438. }
  12439. if(strcmp(key, "AuthorizationKey") == 0)
  12440. {
  12441. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12442. {
  12443. strcpy(str, (const char*)value);
  12444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12445. isSuccess = ConfigurationStatus_Accepted;
  12446. }
  12447. else
  12448. {
  12449. isSuccess = ConfigurationStatus_Rejected;
  12450. }
  12451. }
  12452. if(strcmp(key, "SecurityProfile") == 0)
  12453. {
  12454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12455. {
  12456. check_ascii = value[0];
  12457. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12458. {
  12459. isSuccess = ConfigurationStatus_Rejected;
  12460. }
  12461. else if(check_ascii == 0x33)
  12462. {
  12463. isSuccess = NotSupported;
  12464. }
  12465. else
  12466. {
  12467. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12468. {
  12469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12470. isSuccess = ConfigurationStatus_Accepted;
  12471. }
  12472. else
  12473. isSuccess = ConfigurationStatus_Rejected;
  12474. }
  12475. }
  12476. else
  12477. {
  12478. isSuccess = ConfigurationStatus_Rejected;
  12479. }
  12480. }
  12481. if(strcmp(key, "DefaultPrice") == 0)
  12482. {
  12483. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12484. {
  12485. strcpy(str, (const char*)value);
  12486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12487. isSuccess = ConfigurationStatus_Accepted;
  12488. }
  12489. else
  12490. {
  12491. isSuccess = ConfigurationStatus_Rejected;
  12492. }
  12493. }
  12494. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12495. {
  12496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12497. {
  12498. strcpy(str, (const char*)value);
  12499. for(int i = 0; str[i]; i++)
  12500. {
  12501. str[i] = tolower(str[i]);
  12502. }
  12503. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12505. isSuccess = ConfigurationStatus_Accepted;
  12506. }
  12507. else
  12508. {
  12509. isSuccess = ConfigurationStatus_Rejected;
  12510. }
  12511. }
  12512. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12513. {
  12514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12515. {
  12516. strcpy(str, (const char*)value);
  12517. for(int i = 0; str[i]; i++)
  12518. {
  12519. str[i] = tolower(str[i]);
  12520. }
  12521. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12523. isSuccess = ConfigurationStatus_Accepted;
  12524. }
  12525. else
  12526. {
  12527. isSuccess = ConfigurationStatus_Rejected;
  12528. }
  12529. }
  12530. #if 0
  12531. //For OCPP Test Case
  12532. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12533. {
  12534. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12535. {
  12536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12537. isSuccess = ConfigurationStatus_Accepted;
  12538. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12539. }
  12540. else
  12541. {
  12542. isSuccess = ConfigurationStatus_Rejected;
  12543. }
  12544. }
  12545. #endif
  12546. #if 1
  12547. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12548. {
  12549. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12550. {
  12551. strcpy(str, (const char*)value);
  12552. for(int i = 0; str[i]; i++)
  12553. {
  12554. str[i] = tolower(str[i]);
  12555. }
  12556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12557. isSuccess = ConfigurationStatus_Accepted;
  12558. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12559. }
  12560. else
  12561. {
  12562. isSuccess = ConfigurationStatus_Rejected;
  12563. }
  12564. }
  12565. #endif
  12566. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12567. {
  12568. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12569. {
  12570. check_ascii = value[0];
  12571. if( (check_ascii < 48) || (check_ascii > 57) )
  12572. {
  12573. isSuccess = ConfigurationStatus_Rejected;
  12574. }
  12575. else
  12576. {
  12577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12578. isSuccess = ConfigurationStatus_Accepted;
  12579. }
  12580. }
  12581. else
  12582. {
  12583. isSuccess = ConfigurationStatus_Rejected;
  12584. }
  12585. }
  12586. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12587. {
  12588. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12589. {
  12590. check_ascii = value[0];
  12591. if( (check_ascii < 48) || (check_ascii > 57) )
  12592. {
  12593. isSuccess = ConfigurationStatus_Rejected;
  12594. }
  12595. else
  12596. {
  12597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12598. isSuccess = ConfigurationStatus_Accepted;
  12599. }
  12600. }
  12601. else
  12602. {
  12603. isSuccess = ConfigurationStatus_Rejected;
  12604. }
  12605. }
  12606. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12607. {
  12608. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12609. {
  12610. strcpy(str, (const char*)value);
  12611. for(int i = 0; str[i]; i++)
  12612. {
  12613. str[i] = tolower(str[i]);
  12614. }
  12615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12616. isSuccess = ConfigurationStatus_Accepted;
  12617. }
  12618. else
  12619. {
  12620. isSuccess = ConfigurationStatus_Rejected;
  12621. }
  12622. }
  12623. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12624. {
  12625. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12626. {
  12627. check_ascii = value[0];
  12628. if( (check_ascii < 48) || (check_ascii > 57) )
  12629. {
  12630. isSuccess = ConfigurationStatus_Rejected;
  12631. }
  12632. else
  12633. {
  12634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12635. isSuccess = ConfigurationStatus_Accepted;
  12636. }
  12637. }
  12638. else
  12639. {
  12640. isSuccess = ConfigurationStatus_Rejected;
  12641. }
  12642. }
  12643. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12644. {
  12645. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12646. {
  12647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12648. isSuccess = ConfigurationStatus_Accepted;
  12649. }
  12650. else
  12651. {
  12652. isSuccess = ConfigurationStatus_Rejected;
  12653. }
  12654. }
  12655. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12656. {
  12657. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12658. {
  12659. check_ascii = value[0];
  12660. if( (check_ascii < 48) || (check_ascii > 57) )
  12661. {
  12662. isSuccess = ConfigurationStatus_Rejected;
  12663. }
  12664. else
  12665. {
  12666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12667. isSuccess = ConfigurationStatus_Accepted;
  12668. }
  12669. }
  12670. else
  12671. {
  12672. isSuccess = ConfigurationStatus_Rejected;
  12673. }
  12674. }
  12675. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12676. {
  12677. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12678. {
  12679. strcpy(str, (const char*)value);
  12680. for(int i = 0; str[i]; i++)
  12681. {
  12682. str[i] = tolower(str[i]);
  12683. }
  12684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12685. isSuccess = ConfigurationStatus_Accepted;
  12686. }
  12687. else
  12688. {
  12689. isSuccess = ConfigurationStatus_Rejected;
  12690. }
  12691. }
  12692. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12693. {
  12694. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12695. {
  12696. check_ascii = value[0];
  12697. if( (check_ascii < 48) || (check_ascii > 57) )
  12698. {
  12699. isSuccess = ConfigurationStatus_Rejected;
  12700. }
  12701. else
  12702. {
  12703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12704. isSuccess = ConfigurationStatus_Accepted;
  12705. }
  12706. }
  12707. else
  12708. {
  12709. isSuccess = ConfigurationStatus_Rejected;
  12710. }
  12711. }
  12712. return isSuccess;
  12713. }
  12714. int TransactionMessageAttemptsGet(void)
  12715. {
  12716. return TransactionMessageAttemptsValue;
  12717. }
  12718. int FirstHeartBeatResponse(void)
  12719. {
  12720. return FirstHeartBeat;
  12721. }
  12722. int TransactionMessageRetryIntervalGet(void)
  12723. {
  12724. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12725. }
  12726. int ReadHttpStatus(int sock)
  12727. {
  12728. //char c;
  12729. char buff[1024]="",*ptr=buff+1;
  12730. int bytes_received, status;
  12731. DEBUG_INFO("Begin Response ..\n");
  12732. while((bytes_received = recv(sock, ptr, 1, 0))){
  12733. if(bytes_received==-1){
  12734. perror("ReadHttpStatus");
  12735. exit(1);
  12736. }
  12737. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12738. ptr++;
  12739. }
  12740. *ptr=0;
  12741. ptr=buff+1;
  12742. sscanf(ptr,"%*s %d ", &status);
  12743. DEBUG_INFO("%s\n",ptr);
  12744. DEBUG_INFO("status=%d\n",status);
  12745. DEBUG_INFO("End Response ..\n");
  12746. return (bytes_received>0)?status:0;
  12747. }
  12748. //the only filed that it parsed is 'Content-Length'
  12749. int ParseHeader(int sock)
  12750. {
  12751. //char c;
  12752. char buff[1024]="",*ptr=buff+4;
  12753. int bytes_received;
  12754. DEBUG_INFO("Begin HEADER ..\n");
  12755. while((bytes_received = recv(sock, ptr, 1, 0))){
  12756. if(bytes_received==-1){
  12757. perror("Parse Header");
  12758. exit(1);
  12759. }
  12760. if(
  12761. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12762. (ptr[-1]=='\r') && (*ptr=='\n' )
  12763. ) break;
  12764. ptr++;
  12765. }
  12766. *ptr=0;
  12767. ptr=buff+4;
  12768. //printf("%s",ptr);
  12769. if(bytes_received){
  12770. ptr=strstr(ptr,"Content-Length:");
  12771. if(ptr){
  12772. sscanf(ptr,"%*s %d",&bytes_received);
  12773. }else
  12774. bytes_received=-1; //unknown size
  12775. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12776. }
  12777. DEBUG_INFO("End HEADER ..\n");
  12778. return bytes_received ;
  12779. }
  12780. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12781. {
  12782. char rmFileCmd[100]={0};
  12783. char FilePath[100]={0};
  12784. char ftpbuf[200];
  12785. int systemresult;
  12786. //DEBUG_INFO("filename=%s\n",filename);
  12787. //DEBUG_INFO("url=%s\n",url);
  12788. sprintf(FilePath,"/mnt/%s",filename);
  12789. system("ping 8.8.8.8 &");
  12790. if((access(FilePath,F_OK))!=-1)
  12791. {
  12792. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12793. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12794. system(rmFileCmd);
  12795. }
  12796. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12797. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12798. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12799. systemresult = system(ftpbuf);
  12800. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12801. if(systemresult != 0)
  12802. {
  12803. DEBUG_INFO("http DownLoad error!\n");
  12804. return FALSE;
  12805. }
  12806. system("pkill ping");
  12807. return TRUE;
  12808. }
  12809. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12810. {
  12811. char rmFileCmd[100]={0};
  12812. char FilePath[100]={0};
  12813. char ftpbuf[200];
  12814. int systemresult;
  12815. //char temp[100];
  12816. sprintf(FilePath,"/mnt/%s",filename);
  12817. system("ping 8.8.8.8 &");
  12818. if((access(FilePath,F_OK))!=-1)
  12819. {
  12820. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12821. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12822. system(rmFileCmd);
  12823. }
  12824. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12825. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12826. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12827. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12828. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12829. systemresult = system(ftpbuf);
  12830. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12831. if(systemresult != 0)
  12832. {
  12833. printf("wget error!\n");
  12834. return FALSE;
  12835. }
  12836. system("pkill ping");
  12837. return TRUE;
  12838. }
  12839. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12840. {
  12841. char rmFileCmd[100]={0};
  12842. char FilePath[100]={0};
  12843. char ftpbuf[200];
  12844. int systemresult;
  12845. //DEBUG_INFO("filename=%s\n",filename);
  12846. //DEBUG_INFO("url=%s\n",url);
  12847. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12848. if((access(FilePath,F_OK))!=-1)
  12849. {
  12850. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12851. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12852. system(rmFileCmd);
  12853. }
  12854. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12855. if(fp == NULL)
  12856. {
  12857. DEBUG_INFO("log is NULL\n");
  12858. return FALSE;
  12859. }
  12860. else
  12861. {
  12862. fprintf(fp, "%s\n", url);
  12863. fprintf(fp, "%s\n", filename);
  12864. fclose(fp);
  12865. }
  12866. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12867. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12868. systemresult = system(ftpbuf);
  12869. DEBUG_INFO("systemresult = %d\n",systemresult);
  12870. if(systemresult != 0)
  12871. {
  12872. DEBUG_INFO("http upload error!\n");
  12873. return FALSE;
  12874. }
  12875. return TRUE;
  12876. }
  12877. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12878. {
  12879. struct hostent* server;
  12880. char *IPbuffer;
  12881. char ftpbuf[200];
  12882. int systemresult;
  12883. // To retrieve host information
  12884. server = gethostbyname(location);
  12885. // To convert an Internet network
  12886. // address into ASCII string
  12887. IPbuffer = inet_ntoa(*((struct in_addr*)
  12888. server->h_addr_list[0]));
  12889. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12890. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12891. /* format : ftpput -u username -p passwd IP target source*/
  12892. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12893. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12894. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12895. systemresult = system(ftpbuf);
  12896. DEBUG_INFO("systemresult=%d\n",systemresult);
  12897. if(systemresult != 0)
  12898. {
  12899. DEBUG_INFO("ftpput error!\n");
  12900. return FALSE;
  12901. }
  12902. return TRUE;
  12903. }
  12904. /**
  12905. * Place the contents of the specified file into a memory buffer
  12906. *
  12907. * @param[in] filename The path and name of the file to read
  12908. * @param[out] filebuffer A pointer to the contents in memory
  12909. * @return status 0 success, 1 on failure
  12910. */
  12911. int get_file_contents(const char* filename, char** outbuffer) {
  12912. FILE* file = NULL;
  12913. long filesize;
  12914. const int blocksize = 1;
  12915. size_t readsize;
  12916. char* filebuffer;
  12917. // Open the file
  12918. file = fopen(filename, "r");
  12919. if (NULL == file)
  12920. {
  12921. printf("'%s' not opened\n", filename);
  12922. exit(EXIT_FAILURE);
  12923. }
  12924. // Determine the file size
  12925. fseek(file, 0, SEEK_END);
  12926. filesize = ftell(file);
  12927. rewind (file);
  12928. // Allocate memory for the file contents
  12929. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12930. *outbuffer = filebuffer;
  12931. if (filebuffer == NULL)
  12932. {
  12933. fputs ("malloc out-of-memory", stderr);
  12934. exit(EXIT_FAILURE);
  12935. }
  12936. // Read in the file
  12937. readsize = fread(filebuffer, blocksize, filesize, file);
  12938. if (readsize != filesize)
  12939. {
  12940. fputs ("didn't read file completely",stderr);
  12941. exit(EXIT_FAILURE);
  12942. }
  12943. // Clean exit
  12944. fclose(file);
  12945. return EXIT_SUCCESS;
  12946. }
  12947. static int selectSqlCount = 0;
  12948. static int callback(void *data, int argc, char **argv, char **azColName){
  12949. int i;
  12950. //printf("%s: ", (const char*)data);
  12951. selectSqlCount = argc;
  12952. for(i = 0; i<argc; i++){
  12953. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12954. }
  12955. //printf("\n");
  12956. return 0;
  12957. }
  12958. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12959. //int i;
  12960. //printf("%s:\n", (const char*)data);
  12961. localversion = argv[5] ? atoi(argv[5]) : 0;
  12962. //printf("localversion=%d\n", localversion);
  12963. return 0;
  12964. }
  12965. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  12966. //printf("%s:\n", (const char*)data);
  12967. //idTag
  12968. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  12969. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  12970. //parentIdTag
  12971. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  12972. //expir_date
  12973. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  12974. //status
  12975. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  12976. //version
  12977. if(columenCount > 5)
  12978. idTagQuery.listVersionInt = atoi(columnValue[5]);
  12979. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12980. return 0;
  12981. }
  12982. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12983. {
  12984. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12985. // printf("localversion=%d\n", localversion);
  12986. return 0;
  12987. }
  12988. //=========================================
  12989. // Sqlite3 related function
  12990. //=========================================
  12991. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12992. {
  12993. for (int i = 0; i < n_columns; i++)
  12994. {
  12995. DEBUG_INFO("%s\t", col_values[i]);
  12996. }
  12997. DEBUG_INFO("\n");
  12998. return 0;
  12999. }
  13000. int OCPP_cleanLocalCache()
  13001. {
  13002. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  13003. char *errMsg = 0;
  13004. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13005. if (SQLITE_OK != rc)
  13006. {
  13007. DEBUG_INFO("SQL error: %s\n",errMsg);
  13008. return FALSE;
  13009. }
  13010. return TRUE;
  13011. }
  13012. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  13013. {
  13014. int isSuccess = TRUE;
  13015. int ret = 0;
  13016. //const char* data = "Callback function called";
  13017. char sql[300];
  13018. char zErrMsg[200];
  13019. memset(sql, 0, 300);
  13020. memset(zErrMsg, 0, 200);
  13021. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  13022. //* Execute SQL statement */
  13023. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13024. if( ret != SQLITE_OK )
  13025. {
  13026. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13027. isSuccess = FALSE;
  13028. }
  13029. return isSuccess;
  13030. }
  13031. void OCPP_getIdTagFromLocalCache(char idTag[])
  13032. {
  13033. int rc = 0;
  13034. char sql[100];
  13035. char zErrMsg[100];
  13036. memset(sql, 0, 100);
  13037. memset(zErrMsg, 0, 100);
  13038. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13039. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13040. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  13041. /* Execute SQL statement */
  13042. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13043. if( rc != SQLITE_OK )
  13044. {
  13045. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13046. }
  13047. }
  13048. void OCPP_getListVerion()
  13049. {
  13050. int rc = 0;
  13051. // const char* data = "Callback function called";
  13052. char sql[100];
  13053. char zErrMsg[100];
  13054. memset(sql, 0, 100);
  13055. memset(zErrMsg, 0, 100);
  13056. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13057. /* Execute SQL statement */
  13058. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13059. if( rc != SQLITE_OK )
  13060. {
  13061. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13062. }
  13063. }
  13064. void OCPP_get_TableAuthlocalAllData(void)
  13065. {
  13066. int rc = 0;
  13067. char sql[100];
  13068. char zErrMsg[100];
  13069. memset(sql, 0, 100);
  13070. memset(zErrMsg, 0, 100);
  13071. sprintf(sql,"select * from ocpp_auth_local ");
  13072. /* Execute SQL statement */
  13073. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13074. if( rc != SQLITE_OK )
  13075. {
  13076. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13077. }
  13078. //return ver;
  13079. }
  13080. int OCPP_cleanLocalList()
  13081. {
  13082. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13083. char *errMsg = 0;
  13084. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13085. if (SQLITE_OK != rc)
  13086. {
  13087. DEBUG_INFO("%s\n",errMsg);
  13088. return FALSE;
  13089. }
  13090. return TRUE;
  13091. }
  13092. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13093. {
  13094. int isSuccess = FALSE;
  13095. int ret = 0;
  13096. //const char* data = "Callback function called";
  13097. char sql[300];
  13098. char zErrMsg[200];
  13099. memset(sql, 0, 300);
  13100. memset(zErrMsg, 0, 200);
  13101. 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);
  13102. //* Execute SQL statement */
  13103. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13104. if( ret != SQLITE_OK )
  13105. {
  13106. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13107. return isSuccess;
  13108. }
  13109. memset(sql, 0, 300);
  13110. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13111. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13112. if( ret != SQLITE_OK )
  13113. {
  13114. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13115. return isSuccess;
  13116. }
  13117. isSuccess = TRUE;
  13118. return isSuccess;
  13119. }
  13120. void OCPP_getIdTagFromLocalList(char idTag[])
  13121. {
  13122. int rc = 0;
  13123. // const char* data = "Callback function called";
  13124. char sql[100];
  13125. char zErrMsg[100];
  13126. memset(sql, 0, 100);
  13127. memset(zErrMsg, 0, 100);
  13128. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13129. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13130. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13131. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13132. /* Execute SQL statement */
  13133. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13134. if( rc != SQLITE_OK )
  13135. {
  13136. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13137. }
  13138. //return ver;
  13139. }
  13140. void OCPP_deleteIdTagFromLocalList(char idTag[])
  13141. {
  13142. //int ver = 0;
  13143. //int isSuccess = FALSE;
  13144. int rc = 0;
  13145. char sql[100];
  13146. char zErrMsg[100];
  13147. memset(sql, 0, 100);
  13148. memset(zErrMsg, 0, 100);
  13149. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13150. //* Execute SQL statement */
  13151. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13152. if( rc != SQLITE_OK )
  13153. {
  13154. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13155. }
  13156. }
  13157. int GetOcppServerURL()
  13158. {
  13159. int result = FALSE;
  13160. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13161. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13162. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13163. struct yuarel url;
  13164. char urlStr[512];
  13165. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13166. {
  13167. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13168. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13169. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13170. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13171. if(yuarel_parse(&url, urlStr) != -1)
  13172. {
  13173. sprintf(OcppProtocol, "%s", url.scheme);
  13174. sprintf(OcppHost, "%s", url.host);
  13175. if(url.path == NULL)
  13176. OcppTempPath[0] = '\0';
  13177. else
  13178. {
  13179. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13180. {
  13181. sprintf(OcppTempPath, "%s/", url.path);
  13182. }
  13183. else
  13184. {
  13185. sprintf(OcppTempPath, "%s", url.path);
  13186. }
  13187. }
  13188. if(url.port == 0)
  13189. {
  13190. if(strcmp(OcppProtocol, "wss") == 0)
  13191. OcppPort = 443;
  13192. else
  13193. OcppPort = 80;
  13194. }
  13195. else
  13196. OcppPort = url.port;
  13197. result = TRUE;
  13198. }
  13199. }
  13200. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13201. {
  13202. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13203. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13204. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13205. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13206. if(yuarel_parse(&url, urlStr) != -1)
  13207. {
  13208. sprintf(OcppProtocol, "%s", url.scheme);
  13209. sprintf(OcppHost, "%s", url.host);
  13210. if(url.path == NULL)
  13211. OcppTempPath[0] = '\0';
  13212. else
  13213. sprintf(OcppTempPath, "%s", url.path);
  13214. if(url.port == 0)
  13215. {
  13216. if(strcmp(OcppProtocol, "wss") == 0)
  13217. OcppPort = 443;
  13218. else
  13219. OcppPort = 80;
  13220. }
  13221. else
  13222. OcppPort = url.port;
  13223. result = TRUE;
  13224. }
  13225. }
  13226. else
  13227. {
  13228. strcpy(OcppHost,"");
  13229. }
  13230. return result;
  13231. }
  13232. int GetOcppPath()
  13233. {
  13234. int result = FALSE;
  13235. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13236. {
  13237. if(OcppTempPath == NULL)
  13238. {
  13239. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13240. }
  13241. else
  13242. {
  13243. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13244. }
  13245. result = TRUE;
  13246. goto End;
  13247. }
  13248. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13249. {
  13250. if(OcppTempPath == NULL)
  13251. {
  13252. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13253. }
  13254. else
  13255. {
  13256. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13257. }
  13258. result = TRUE;
  13259. goto End;
  13260. }
  13261. else
  13262. {
  13263. strcpy(OcppPath,"");
  13264. }
  13265. End:
  13266. return result;
  13267. }
  13268. int GetOcppPort()
  13269. {
  13270. return OcppPort;
  13271. }
  13272. int GetOcppConnStatus(void)
  13273. {
  13274. return ShmOCPP16Data->OcppConnStatus;
  13275. }
  13276. void SetOcppConnStatus(uint8_t status)
  13277. {
  13278. ShmOCPP16Data->OcppConnStatus = status;
  13279. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13280. }
  13281. int GetHeartBeatWithNOResponse(void)
  13282. {
  13283. return HeartBeatWithNOResponse;
  13284. }
  13285. void SetHeartBeatWithNOResponse(void)
  13286. {
  13287. HeartBeatWithNOResponse = 0;
  13288. }
  13289. void GetStartTransactionIdTag(int gun_index)
  13290. {
  13291. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13292. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13293. }
  13294. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13295. {
  13296. char ch;
  13297. FILE *fptr1;
  13298. int temptransactionId;
  13299. char str[100]={0};
  13300. temptransactionId = 0;
  13301. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  13302. {
  13303. DEBUG_INFO("IdTag is empty.\n");
  13304. return temptransactionId;
  13305. }
  13306. /*------ Read the file ----------------*/
  13307. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13308. if (!fptr1)
  13309. {
  13310. DEBUG_INFO("QueueTransactionId file open error.\n");
  13311. //printf(" File not found or unable to open the input file!!\n");
  13312. return temptransactionId;
  13313. }
  13314. ch=fgetc(fptr1);
  13315. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13316. rewind(fptr1);
  13317. if(ch!=EOF)
  13318. {
  13319. // printf("%c",ch);
  13320. while (fgets(str, 100, fptr1) != NULL)
  13321. {
  13322. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13323. if(str[0]=='\0')
  13324. {
  13325. break;
  13326. }
  13327. char *revbuf[8] = {0}; // Variable store string split
  13328. int num = 0;// Quantity after string split
  13329. DEBUG_INFO("Transaction queue data= %s\n", str);
  13330. splitstring(str,",",revbuf,&num); // String split
  13331. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13332. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13333. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13334. DEBUG_INFO("------------------------------\n");
  13335. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13336. {
  13337. if(isStopTransaction)
  13338. {
  13339. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13340. {
  13341. temptransactionId = atoi(revbuf[2]);
  13342. break;
  13343. }
  13344. }
  13345. else
  13346. {
  13347. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13348. {
  13349. temptransactionId = atoi(revbuf[2]);
  13350. break;
  13351. }
  13352. }
  13353. }
  13354. }
  13355. }
  13356. else
  13357. DEBUG_INFO("EOF\n");
  13358. fclose(fptr1);
  13359. /*------- End of reading ---------------*/
  13360. return temptransactionId;
  13361. }
  13362. void SetTransactionIdZero(int transactionId)
  13363. {
  13364. char ch;
  13365. FILE *fptr1, *fptr2;
  13366. int temptransactionId = 0;
  13367. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13368. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13369. if (!fptr1)
  13370. {
  13371. //printf(" File not found or unable to open the input file!!\n");
  13372. return ;
  13373. }
  13374. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13375. if (!fptr2)
  13376. {
  13377. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13378. fclose(fptr1);
  13379. return ;
  13380. }
  13381. ch=fgetc(fptr1);
  13382. rewind(fptr1);
  13383. if(ch!=EOF)
  13384. {
  13385. // copy all contents to the temporary file except the specific line
  13386. while (fgets(str, 100, fptr1) != NULL)
  13387. {
  13388. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13389. if(str[0]=='\0')
  13390. {
  13391. break;
  13392. }
  13393. char *revbuf[8] = {0};
  13394. int num = 0;
  13395. strcpy(strtemp, str);
  13396. splitstring(str,",",revbuf,&num);
  13397. if(revbuf[2][0] != '\0')
  13398. {
  13399. temptransactionId = atoi(revbuf[2]);
  13400. if(transactionId != temptransactionId)
  13401. {
  13402. fprintf(fptr2, "%s\n", strtemp);
  13403. }
  13404. }
  13405. }
  13406. }
  13407. fclose(fptr1);
  13408. fclose(fptr2);
  13409. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13410. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13411. /*------ Read the file ----------------*/
  13412. }
  13413. int InternetDisconnect(void)
  13414. {
  13415. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13416. }
  13417. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13418. void storeTempStopTransaction(int gun_index)
  13419. {
  13420. char guid[37]={0};
  13421. int tempIndex = 0;
  13422. char TempStopTransaction[256];
  13423. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13424. DEBUG_INFO("storeTempStopTransaction...\n");
  13425. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13426. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13427. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13428. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13429. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13430. {
  13431. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13432. {
  13433. tempIndex = ((gun_index==2) ? 1: 0);
  13434. }
  13435. else
  13436. {
  13437. tempIndex = gun_index;
  13438. }
  13439. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13440. {
  13441. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13442. {
  13443. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13444. }
  13445. }// END OF CHAdeMO_QUANTITY
  13446. }
  13447. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13448. {
  13449. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13450. {
  13451. tempIndex = ((gun_index==2) ? 1: 0);
  13452. }
  13453. else
  13454. {
  13455. tempIndex = gun_index;
  13456. }
  13457. for (int index = 0; index < CCS_QUANTITY; index++)
  13458. {
  13459. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13460. {
  13461. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13462. }
  13463. }// END OF CCS_QUANTITY
  13464. }
  13465. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13466. {
  13467. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13468. {
  13469. tempIndex = ((gun_index==2) ? 1: 0);
  13470. }
  13471. else
  13472. {
  13473. tempIndex = gun_index;
  13474. }
  13475. for (int index = 0; index < GB_QUANTITY; index++)
  13476. {
  13477. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13478. {
  13479. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13480. }
  13481. }// END OF GB_QUANTITY
  13482. }
  13483. else if(gunType[gun_index] == GUN_TYPE_DO)
  13484. {
  13485. tempIndex = gun_index;
  13486. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13487. {
  13488. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13489. {
  13490. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13491. }
  13492. }
  13493. }
  13494. else
  13495. {
  13496. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13497. {
  13498. tempIndex = 2;
  13499. }
  13500. else
  13501. {
  13502. tempIndex = gun_index;
  13503. }
  13504. for (int index = 0; index < AC_QUANTITY; index++)
  13505. {
  13506. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13507. {
  13508. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13509. }
  13510. }// END OF AC_QUANTITY
  13511. }
  13512. //Stop Transaction Time
  13513. struct timeval tmnow;
  13514. struct tm *tm;
  13515. char buf[28];//, usec_buf[6];
  13516. gettimeofday(&tmnow, NULL);
  13517. time_t t;
  13518. t = time(NULL);
  13519. /*UTC time and date*/
  13520. tm = gmtime(&t);
  13521. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13523. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13525. random_uuid(guid);
  13526. /***********************************transactionData******************************************************/
  13527. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13529. //=================================
  13530. //1. Transaction_Begin
  13531. //=================================
  13532. //============================== Energy.Active.Import.Interval ===========================================
  13533. //idx_sample=0;
  13534. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13537. 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*/]);
  13538. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13539. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  13540. {
  13541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13542. }
  13543. else
  13544. {
  13545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13546. }
  13547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13549. //=================================
  13550. //2. Transaction_End
  13551. //=================================
  13552. //2.1====================================== Current.Import L1 ==============================================
  13553. //idx_sample=1;
  13554. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13555. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13556. {
  13557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13558. {
  13559. tempIndex = ((gun_index==2) ? 1: 0);
  13560. }
  13561. else
  13562. {
  13563. tempIndex = gun_index;
  13564. }
  13565. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13566. {
  13567. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13568. {
  13569. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13570. }
  13571. }// End of for CHAdeMO_QUANTITY
  13572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13573. }
  13574. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13575. {
  13576. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13577. {
  13578. tempIndex = ((gun_index==2) ? 1: 0);
  13579. }
  13580. else
  13581. {
  13582. tempIndex = gun_index;
  13583. }
  13584. for (int index = 0; index < CCS_QUANTITY; index++)
  13585. {
  13586. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13587. {
  13588. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13589. }
  13590. }// End of for CCS_QUANTITY
  13591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13592. }
  13593. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13594. {
  13595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13596. {
  13597. tempIndex = ((gun_index==2) ? 1: 0);
  13598. }
  13599. else
  13600. {
  13601. tempIndex = gun_index;
  13602. }
  13603. for (int index = 0; index < GB_QUANTITY; index++)
  13604. {
  13605. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13606. {
  13607. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13608. }
  13609. }// End of for GB_QUANTITY
  13610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13611. }
  13612. else if(gunType[gun_index] == GUN_TYPE_DO)
  13613. {
  13614. tempIndex = gun_index;
  13615. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13616. {
  13617. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13618. {
  13619. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13620. }
  13621. }
  13622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13623. }
  13624. else
  13625. {
  13626. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13627. {
  13628. tempIndex = 2;
  13629. }
  13630. else
  13631. {
  13632. tempIndex = gun_index;
  13633. }
  13634. for (int index = 0; index < AC_QUANTITY; index++)
  13635. {
  13636. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13637. {
  13638. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13639. }
  13640. }// End of for AC_QUANTITY
  13641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13642. }
  13643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13646. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13648. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13649. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13650. //idx_sample=2;
  13651. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13652. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13653. {
  13654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13655. {
  13656. tempIndex = ((gun_index==2) ? 1: 0);
  13657. }
  13658. else
  13659. {
  13660. tempIndex = gun_index;
  13661. }
  13662. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13663. {
  13664. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13665. {
  13666. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13667. }
  13668. }// END OF CHAdeMO_QUANTITY
  13669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13670. }
  13671. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13672. {
  13673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13674. {
  13675. tempIndex = ((gun_index==2) ? 1: 0);
  13676. }
  13677. else
  13678. {
  13679. tempIndex = gun_index;
  13680. }
  13681. for (int index = 0; index < CCS_QUANTITY; index++)
  13682. {
  13683. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13684. {
  13685. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13686. }
  13687. }// END OF CCS_QUANTITY
  13688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13689. }
  13690. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13691. {
  13692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13693. {
  13694. tempIndex = ((gun_index==2) ? 1: 0);
  13695. }
  13696. else
  13697. {
  13698. tempIndex = gun_index;
  13699. }
  13700. for (int index = 0; index < GB_QUANTITY; index++)
  13701. {
  13702. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13703. {
  13704. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13705. }
  13706. }// END OF GB_QUANTITY
  13707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13708. }
  13709. else if(gunType[gun_index] == GUN_TYPE_DO)
  13710. {
  13711. tempIndex = gun_index;
  13712. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13713. {
  13714. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13715. {
  13716. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13717. }
  13718. }
  13719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13720. }
  13721. else
  13722. {
  13723. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13724. {
  13725. tempIndex = 2;
  13726. }
  13727. else
  13728. {
  13729. tempIndex = gun_index;
  13730. }
  13731. for (int index = 0; index < AC_QUANTITY; index++)
  13732. {
  13733. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13734. {
  13735. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13736. }
  13737. }// END OF AC_QUANTITY
  13738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13739. }
  13740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13743. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13746. //2.3====================================== Power.Active.Import =========================================
  13747. //idx_sample=3;
  13748. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13749. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13750. {
  13751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13752. {
  13753. tempIndex = ((gun_index==2) ? 1: 0);
  13754. }
  13755. else
  13756. {
  13757. tempIndex = gun_index;
  13758. }
  13759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13760. {
  13761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13762. {
  13763. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13764. }
  13765. } // End for CHAdeMO_QUANTITY
  13766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13767. }
  13768. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13769. {
  13770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13771. {
  13772. tempIndex = ((gun_index==2) ? 1: 0);
  13773. }
  13774. else
  13775. {
  13776. tempIndex = gun_index;
  13777. }
  13778. for (int index = 0; index < CCS_QUANTITY; index++)
  13779. {
  13780. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13781. {
  13782. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13783. }
  13784. } // END for CCS_QUANTITY
  13785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13786. }
  13787. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13788. {
  13789. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13790. {
  13791. tempIndex = ((gun_index==2) ? 1: 0);
  13792. }
  13793. else
  13794. {
  13795. tempIndex = gun_index;
  13796. }
  13797. for (int index = 0; index < GB_QUANTITY; index++)
  13798. {
  13799. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13800. {
  13801. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13802. }
  13803. }// END for GB_QUANTITY
  13804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13805. }
  13806. else if(gunType[gun_index] == GUN_TYPE_DO)
  13807. {
  13808. tempIndex = gun_index;
  13809. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13810. {
  13811. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13812. {
  13813. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13814. }
  13815. }
  13816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13817. }
  13818. else
  13819. {
  13820. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13821. {
  13822. tempIndex = 2;
  13823. }
  13824. else
  13825. {
  13826. tempIndex = gun_index;
  13827. }
  13828. for (int index = 0; index < AC_QUANTITY; index++)
  13829. {
  13830. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13831. {
  13832. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13833. }
  13834. } // END for AC_QUANTITY
  13835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13836. }
  13837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13839. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13840. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13841. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13842. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13843. //2.4====================================== Voltage L1 ====================================================
  13844. //idx_sample=4;
  13845. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13846. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13847. {
  13848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13849. {
  13850. tempIndex = ((gun_index==2) ? 1: 0);
  13851. }
  13852. else
  13853. {
  13854. tempIndex = gun_index;
  13855. }
  13856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13857. {
  13858. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13859. {
  13860. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13861. }
  13862. } // END OF FOR CHAdeMO_QUANTITY
  13863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13864. }
  13865. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13866. {
  13867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13868. {
  13869. tempIndex = ((gun_index==2) ? 1: 0);
  13870. }
  13871. else
  13872. {
  13873. tempIndex = gun_index;
  13874. }
  13875. for (int index = 0; index < CCS_QUANTITY; index++)
  13876. {
  13877. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13878. {
  13879. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13880. }
  13881. } // END OF FOR CCS_QUANTITY
  13882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13883. }
  13884. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13885. {
  13886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13887. {
  13888. tempIndex = ((gun_index==2) ? 1: 0);
  13889. }
  13890. else
  13891. {
  13892. tempIndex = gun_index;
  13893. }
  13894. for (int index = 0; index < GB_QUANTITY; index++)
  13895. {
  13896. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13897. {
  13898. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13899. }
  13900. } // END OF FOR GB_QUANTITY
  13901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13902. }
  13903. else if(gunType[gun_index] == GUN_TYPE_DO)
  13904. {
  13905. tempIndex = gun_index;
  13906. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13907. {
  13908. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13909. {
  13910. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13911. }
  13912. }
  13913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13914. }
  13915. else
  13916. {
  13917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13918. {
  13919. tempIndex = 2;
  13920. }
  13921. else
  13922. {
  13923. tempIndex = gun_index;
  13924. }
  13925. for (int index = 0; index < AC_QUANTITY; index++)
  13926. {
  13927. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13928. {
  13929. 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
  13930. }
  13931. } // END OF FOR AC_QUANTITY
  13932. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13933. }
  13934. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13937. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13940. //2.5============================================== End SoC =========================================================
  13941. //idx_sample=5;
  13942. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13943. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  13944. {
  13945. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  13946. {
  13947. tempIndex = ((gun_index==2) ? 1: 0);
  13948. }
  13949. else
  13950. {
  13951. tempIndex = gun_index;
  13952. }
  13953. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13954. {
  13955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13956. {
  13957. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13958. {
  13959. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13960. }
  13961. }
  13962. }
  13963. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13964. {
  13965. for (int index = 0; index < CCS_QUANTITY; index++)
  13966. {
  13967. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13968. {
  13969. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13970. }
  13971. }
  13972. }
  13973. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13974. {
  13975. for (int index = 0; index < GB_QUANTITY; index++)
  13976. {
  13977. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13978. {
  13979. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13980. }
  13981. }
  13982. }
  13983. else if(gunType[gun_index] == GUN_TYPE_DO)
  13984. {
  13985. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13986. {
  13987. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13988. {
  13989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  13990. }
  13991. }
  13992. }
  13993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  13998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13999. } // END FOR DC CASE
  14000. //2.6====================================== Current.Import L2 ==============================================
  14001. // idx_sample=6;
  14002. // AC 3 phase L2 current
  14003. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14004. {
  14005. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14006. {
  14007. tempIndex = 2;
  14008. }
  14009. else
  14010. {
  14011. tempIndex = gun_index;
  14012. }
  14013. for (int index = 0; index < AC_QUANTITY; index++)
  14014. {
  14015. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14016. {
  14017. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14018. }
  14019. }// End of for AC_QUANTITY
  14020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14021. }
  14022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14027. //2.7====================================== Current.Import L3 ==============================================
  14028. // idx_sample=7;
  14029. // AC 3 phase L3 current
  14030. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14031. {
  14032. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14033. {
  14034. tempIndex = 2;
  14035. }
  14036. else
  14037. {
  14038. tempIndex = gun_index;
  14039. }
  14040. for (int index = 0; index < AC_QUANTITY; index++)
  14041. {
  14042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14043. {
  14044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14045. }
  14046. }// End of for AC_QUANTITY
  14047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14048. }
  14049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14054. //2.9====================================== Voltage L2 ====================================================
  14055. //idx_sample=8;
  14056. // AC 3 phase L2 volatge
  14057. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14058. {
  14059. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14060. {
  14061. tempIndex = 2;
  14062. }
  14063. else
  14064. {
  14065. tempIndex = gun_index;
  14066. }
  14067. for (int index = 0; index < AC_QUANTITY; index++)
  14068. {
  14069. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14070. {
  14071. 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
  14072. }
  14073. } // END OF FOR AC_QUANTITY
  14074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14075. }
  14076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14081. //2.10====================================== Voltage L3 ====================================================
  14082. //idx_sample=9;
  14083. // AC 3 phase L3 volatge
  14084. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14085. {
  14086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14087. {
  14088. tempIndex = 2;
  14089. }
  14090. else
  14091. {
  14092. tempIndex = gun_index;
  14093. }
  14094. for (int index = 0; index < AC_QUANTITY; index++)
  14095. {
  14096. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14097. {
  14098. 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
  14099. }
  14100. } // END OF FOR AC_QUANTITY
  14101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14102. }
  14103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14108. //====================== Start SoC ================================
  14109. //idx_sample=10;
  14110. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14111. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  14112. {
  14113. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14114. {
  14115. tempIndex = ((gun_index==2) ? 1: 0);
  14116. }
  14117. else
  14118. {
  14119. tempIndex = gun_index;
  14120. }
  14121. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14122. {
  14123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14124. {
  14125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14126. {
  14127. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14128. }
  14129. }
  14130. }
  14131. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14132. {
  14133. for (int index = 0; index < CCS_QUANTITY; index++)
  14134. {
  14135. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14136. {
  14137. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14138. }
  14139. }
  14140. }
  14141. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14142. {
  14143. for (int index = 0; index < GB_QUANTITY; index++)
  14144. {
  14145. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14146. {
  14147. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14148. }
  14149. }
  14150. }
  14151. else if(gunType[gun_index] == GUN_TYPE_DO)
  14152. {
  14153. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14154. {
  14155. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14156. {
  14157. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14158. }
  14159. }
  14160. }
  14161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14167. } // END FOR DC CASE
  14168. //======================================== Message create ==============================================
  14169. json_object *StopTransaction = json_object_new_object();
  14170. json_object *transactionDatas = json_object_new_array();
  14171. json_object *sampledValues = json_object_new_array();
  14172. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14173. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14174. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14175. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14176. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14177. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  14178. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14179. {
  14180. json_object *transactionData = json_object_new_object();
  14181. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14182. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14183. {
  14184. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14185. {
  14186. json_object *sampledValue = json_object_new_object();
  14187. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14188. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14189. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14190. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14191. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14192. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14193. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14194. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14195. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14196. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14197. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14198. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14199. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14200. json_object_array_add(sampledValues, sampledValue);
  14201. }
  14202. }
  14203. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14204. json_object_array_add(transactionDatas, transactionData);
  14205. }
  14206. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14207. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14208. ,MESSAGE_TYPE_CALL
  14209. ,guid
  14210. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14211. json_object_put(StopTransaction);
  14212. // Check File "TempStopTransaction" Exist
  14213. if((access(TempStopTransaction,F_OK))!=-1)
  14214. {
  14215. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14216. fclose(fopen(TempStopTransaction, "w"));
  14217. }
  14218. else
  14219. {
  14220. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14221. FILE *log = fopen(TempStopTransaction, "w+");
  14222. if(log == NULL)
  14223. {
  14224. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14225. return ;
  14226. }
  14227. else
  14228. {
  14229. fclose(log);
  14230. }
  14231. }
  14232. //Add TempStopTransaction | Update TempStopTransaction
  14233. // open file for writing
  14234. FILE *outfile;
  14235. outfile = fopen (TempStopTransaction, "a");
  14236. //DEBUG_INFO("data = %s\n", queuedata);
  14237. fputs(queuedata, outfile);
  14238. fputs("\n", outfile);
  14239. fclose (outfile);
  14240. }
  14241. void checkTempStopTransaction(int gun_index)
  14242. {
  14243. FILE *fptr1;
  14244. char ch;
  14245. char str[QUEUE_MESSAGE_LENGTH]={0};
  14246. char guid[37]={0};
  14247. char tempdata[65]={0};
  14248. char connectorStr[2]={0};
  14249. char TempStopTransaction[256];
  14250. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14251. fptr1 = fopen(TempStopTransaction, "r");
  14252. //TempStopTransaction格式: 槍號,StopTransaction封包
  14253. if (!fptr1)
  14254. {
  14255. //printf(" File not found or unable to open the input file!!\n");
  14256. return ;
  14257. }
  14258. ch=fgetc(fptr1);
  14259. //printf(" Now the content of the file %s is : \n",fname);
  14260. rewind(fptr1);
  14261. if(ch!=EOF)
  14262. {
  14263. // copy all contents to the temporary file except the specific line
  14264. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14265. {
  14266. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14267. if(str[0]=='\0')
  14268. {
  14269. break;
  14270. }
  14271. //TempStopTransaction格式: 槍號,StopTransaction封包
  14272. strncpy(connectorStr, str, 1);
  14273. if(atoi(connectorStr) != (gun_index+1))
  14274. {
  14275. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14276. fclose(fptr1);
  14277. return ;
  14278. }
  14279. //random_uuid(guid);
  14280. strncpy(guid, str+6, 36); //copy guid
  14281. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14282. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14283. {
  14284. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14285. }
  14286. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14287. memset(str,0,ARRAY_SIZE(str));
  14288. }
  14289. }
  14290. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14291. fclose(fptr1);
  14292. remove(TempStopTransaction); // remove the original file
  14293. }
  14294. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14295. {
  14296. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14297. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14298. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14299. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14300. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14301. }
  14302. int GetWebSocketPingInterval(void)
  14303. {
  14304. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14305. }
  14306. int GetServerSign(void)
  14307. {
  14308. return server_sign;
  14309. }
  14310. uint8_t GetOcppSecurityProfile()
  14311. {
  14312. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14313. }
  14314. void GetOcppChargerBoxId(uint8_t *data)
  14315. {
  14316. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14317. }
  14318. void GetOcppSecurityPassword(uint8_t *data)
  14319. {
  14320. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14321. }
  14322. void SetOcppVersion(uint8_t *version)
  14323. {
  14324. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  14325. DEBUG_INFO("ocpp version: %s\n", version);
  14326. if(strstr((char*)version, "ocpp1.6") != NULL)
  14327. {
  14328. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  14329. }
  14330. else if(strstr((char*)version, "ocpp2.0") != NULL)
  14331. {
  14332. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  14333. system("pkill OcppBackend");
  14334. }
  14335. }
  14336. void SetServerSign(int value)
  14337. {
  14338. server_sign = value;
  14339. }
  14340. int GetBootNotificationInterval(void)
  14341. {
  14342. return BootNotificationInterval;
  14343. }
  14344. int GetInternetConn(void)
  14345. {
  14346. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14347. }
  14348. void InitialSystemValue(void)
  14349. {
  14350. int connectorIndex = 0;
  14351. //int valueASCII = 0;
  14352. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14353. gunTotalNumber=0;
  14354. SystemInitial = 0;
  14355. localversion=0;
  14356. BootNotificationInterval = 0;
  14357. authorizeRetryTimes = 0;
  14358. GunStatusInterval = 10;
  14359. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14360. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14361. //Hear Beat
  14362. HeartBeatWithNOResponse = 0;
  14363. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14364. FirstHeartBeat = 0;
  14365. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14366. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14367. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14368. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14369. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14370. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14371. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14372. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14373. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14374. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14375. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14376. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14377. memset(gunType, 0, ARRAY_SIZE(gunType));
  14378. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14379. {
  14380. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14381. {
  14382. // DO series
  14383. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14384. {
  14385. SystemInitial = SystemInitial + 1;
  14386. gunTotalNumber = gunTotalNumber + 1;
  14387. gunType[connectorIndex] = GUN_TYPE_DO;
  14388. connectorIndex = connectorIndex + 1;
  14389. }
  14390. }
  14391. else
  14392. {
  14393. // DM, DW, DS series
  14394. //check connector / socket type (index: 8, 9, 10)
  14395. for(int index=7; index <10 ; index++)
  14396. {
  14397. if(index != 8)
  14398. {
  14399. // DC Connector
  14400. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  14401. {
  14402. SystemInitial = SystemInitial + 1;
  14403. gunTotalNumber = gunTotalNumber + 1;
  14404. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  14405. connectorIndex = connectorIndex + 1;
  14406. }
  14407. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  14408. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  14409. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  14410. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  14411. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  14412. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  14413. {
  14414. SystemInitial = SystemInitial + 1;
  14415. gunTotalNumber = gunTotalNumber + 1;
  14416. gunType[connectorIndex] = GUN_TYPE_CCS;
  14417. connectorIndex = connectorIndex + 1;
  14418. }
  14419. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  14420. {
  14421. SystemInitial = SystemInitial + 1;
  14422. gunTotalNumber = gunTotalNumber + 1;
  14423. gunType[connectorIndex] = GUN_TYPE_GBT;
  14424. connectorIndex = connectorIndex + 1;
  14425. }
  14426. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  14427. {
  14428. SystemInitial = SystemInitial + 1;
  14429. gunTotalNumber = gunTotalNumber + 1;
  14430. gunType[connectorIndex] = GUN_TYPE_DO;
  14431. connectorIndex = connectorIndex + 1;
  14432. }
  14433. }
  14434. else
  14435. {
  14436. // AC Connector
  14437. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14438. {
  14439. SystemInitial = SystemInitial + 1;
  14440. gunTotalNumber = gunTotalNumber + 1;
  14441. gunType[connectorIndex] = GUN_TYPE_AC;
  14442. connectorIndex = connectorIndex + 1;
  14443. }
  14444. }
  14445. }
  14446. }
  14447. //DEBUG_INFO("DC ...\n");
  14448. }
  14449. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14450. {
  14451. //check connector / socket type (index: 8, 9, 10)
  14452. for(int index=7; index <10 ; index++)
  14453. {
  14454. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14455. {
  14456. SystemInitial = SystemInitial + 1;
  14457. gunTotalNumber = gunTotalNumber + 1;
  14458. gunType[connectorIndex] = GUN_TYPE_AC;
  14459. connectorIndex = connectorIndex + 1;
  14460. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14461. }
  14462. }
  14463. }
  14464. //Status && ConnectorPlugIn Setting
  14465. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14466. {
  14467. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14468. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14469. }
  14470. for (int index = 0; index < CCS_QUANTITY; index++)
  14471. {
  14472. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14473. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14474. }
  14475. for (int index = 0; index < GB_QUANTITY; index++)
  14476. {
  14477. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14478. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14479. }
  14480. for (int index = 0; index < AC_QUANTITY; index++)
  14481. {
  14482. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14483. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14484. }
  14485. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14486. {
  14487. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14488. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14489. }
  14490. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14491. {
  14492. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14493. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14494. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14495. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14496. }
  14497. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14498. clientTime.Heartbeat=time((time_t*)NULL);
  14499. sleep(1);
  14500. }
  14501. void LWS_Send(char * str)
  14502. {
  14503. //=====================================================
  14504. // Check InternetConn 0: disconnected, 1: connected
  14505. //====================================================
  14506. if(GetOcppConnStatus() == 0)
  14507. {
  14508. DEBUG_INFO("offline now !!!\n");
  14509. return;
  14510. }
  14511. pthread_mutex_lock(&lock_send);
  14512. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14513. sprintf((char *)SendBuffer, "%s", str);
  14514. SendBufLen = strlen(str);
  14515. pthread_mutex_unlock(&lock_send);
  14516. lws_callback_on_writable(wsi_client);
  14517. //lws_service(context, 0);
  14518. //sleep(1);
  14519. }
  14520. void LWS_SendNow(char * str)
  14521. {
  14522. //=====================================================
  14523. // Check InternetConn 0: disconnected, 1: connected
  14524. //====================================================
  14525. if(GetOcppConnStatus() == 0)
  14526. {
  14527. DEBUG_INFO("offline now !!!\n");
  14528. return;
  14529. }
  14530. pthread_mutex_lock(&lock_send);
  14531. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14532. sprintf((char *)SendBuffer, "%s", str);
  14533. SendBufLen = strlen(str);
  14534. pthread_mutex_unlock(&lock_send);
  14535. lws_callback_on_writable(wsi_client);
  14536. lws_service(context, 0);
  14537. //sleep(1);
  14538. }