MessageHandler.c 697 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657
  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].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  587. 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?
  588. 3:
  589. 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")));
  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].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  666. 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?
  667. 3:
  668. 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")));
  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].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  819. 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?
  820. 3:
  821. 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")));
  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].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  898. 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?
  899. 3:
  900. 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")));
  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].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1050. 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?
  1051. 3:
  1052. 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")));
  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].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1129. 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?
  1130. 3:
  1131. 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")));
  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");
  1945. result = FAIL;
  1946. }
  1947. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1948. {
  1949. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3973. {
  3974. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  3975. {
  3976. tempIndex = ((gun_index==2) ? 1: 0);
  3977. }
  3978. else
  3979. {
  3980. tempIndex = gun_index;
  3981. }
  3982. if(gunType[gun_index] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  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(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  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(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  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(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  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] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4141. {
  4142. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4143. {
  4144. tempIndex = ((gun_index==2) ? 1: 0);
  4145. }
  4146. else
  4147. {
  4148. tempIndex = gun_index;
  4149. }
  4150. if(gunType[gun_index] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4781. {
  4782. //idx_sample=5;
  4783. //sampledValue = NULL;
  4784. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4785. {
  4786. tempIndex = ((gun_index==2) ? 1: 0);
  4787. }
  4788. else
  4789. {
  4790. tempIndex = gun_index;
  4791. }
  4792. if(gunType[gun_index] == 'J')
  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] == 'U')||(gunType[gun_index] == 'E'))
  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] == 'G')
  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] == 'O')
  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(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  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(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  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(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  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(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  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] == 'J')
  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] == 'U') || (gunType[2] == 'E'))
  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] == 'G')
  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. if(gunType[2] == 'G')
  5461. {
  5462. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index + 1;
  5463. }
  5464. else
  5465. {
  5466. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5467. }
  5468. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5469. goto end;
  5470. }
  5471. }
  5472. for (int index = 0; index < AC_QUANTITY; index++)
  5473. {
  5474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5475. {
  5476. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5477. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5478. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5479. {
  5480. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5481. }
  5482. else
  5483. {
  5484. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5485. }
  5486. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5487. goto end;
  5488. }
  5489. }
  5490. }
  5491. //The reservationId does NOT match the reservationId
  5492. sendCancelReservationConfirmation(uuid, comfirmstr);
  5493. end:
  5494. // Fill in ocpp packet uuid
  5495. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5496. return result;
  5497. }
  5498. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5499. {
  5500. mtrace();
  5501. int result = FAIL;
  5502. int gunIndex = 0;
  5503. char typeStr[16]={0};
  5504. char comfirmstr[20];
  5505. int specificId = FALSE;
  5506. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5507. json_object *ChangeAvailability;
  5508. ChangeAvailability = json_tokener_parse(payload);
  5509. if(!is_error(ChangeAvailability))
  5510. {
  5511. // Required data
  5512. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5513. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5514. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5515. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5516. }
  5517. json_object_put(ChangeAvailability);
  5518. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5519. {
  5520. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5521. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5522. }
  5523. else if(gunIndex == 0)
  5524. {
  5525. for(int i=0; i < gunTotalNumber; i++)
  5526. {
  5527. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5528. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5529. }
  5530. }
  5531. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5532. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5533. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5534. {
  5535. specificId = TRUE;
  5536. }
  5537. if(specificId == FALSE)
  5538. goto end;
  5539. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5540. {
  5541. //----------------------gunIndex is 0 ------------------------------------------------//
  5542. if(gunIndex == 0)
  5543. {
  5544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5545. {
  5546. for(int i=0; i < gunTotalNumber; i++)
  5547. {
  5548. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5549. {
  5550. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5551. {
  5552. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5553. {
  5554. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5555. goto end;
  5556. }
  5557. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5558. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5559. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5560. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5561. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5562. {
  5563. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5564. goto end;
  5565. }
  5566. }
  5567. }//END FOR CHAdeMO_QUANTITY
  5568. for (int index = 0; index < CCS_QUANTITY; index++)
  5569. {
  5570. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5571. {
  5572. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5573. {
  5574. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5575. goto end;
  5576. }
  5577. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5578. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5579. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5580. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5581. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5582. {
  5583. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5584. goto end;
  5585. }
  5586. }
  5587. }//END FOR CCS_QUANTITY
  5588. for (int index = 0; index < GB_QUANTITY; index++)
  5589. {
  5590. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5591. {
  5592. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5593. {
  5594. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5595. goto end;
  5596. }
  5597. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5598. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5599. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5600. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5601. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5602. {
  5603. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5604. goto end;
  5605. }
  5606. }
  5607. }// END FOR GB_QUANTITY
  5608. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5609. {
  5610. if ((gunType[i] == 'O')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5611. {
  5612. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5613. {
  5614. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5615. goto end;
  5616. }
  5617. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5618. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5619. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5620. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5621. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5622. {
  5623. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5624. goto end;
  5625. }
  5626. }
  5627. }// END FOR GENERAL_GUN_QUANTITY
  5628. for (int index = 0; index < AC_QUANTITY; index++)
  5629. {
  5630. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5631. {
  5632. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5633. {
  5634. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5635. goto end;
  5636. }
  5637. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5638. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5639. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5640. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5641. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5642. {
  5643. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5644. goto end;
  5645. }
  5646. }
  5647. }//END FOR AC_QUANTITY
  5648. }// END FOR gunTotalNumber
  5649. }
  5650. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5651. {
  5652. for(int i=0; i < gunTotalNumber; i++)
  5653. {
  5654. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5655. {
  5656. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5657. goto end;
  5658. }
  5659. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5660. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5661. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5662. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5663. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5664. {
  5665. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5666. goto end;
  5667. }
  5668. }
  5669. }
  5670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5671. goto end;
  5672. }
  5673. //----------------------gunIndex is not 0 ------------------------------------------------//
  5674. //check Transaction active
  5675. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5676. {
  5677. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5678. {
  5679. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5680. {
  5681. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5682. goto end;
  5683. }
  5684. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5685. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5686. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5687. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5688. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5689. {
  5690. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5691. goto end;
  5692. }
  5693. else
  5694. {
  5695. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5696. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5697. goto end;
  5698. }
  5699. }
  5700. }//END FOR CHAdeMO_QUANTITY
  5701. for (int index = 0; index < CCS_QUANTITY; index++)
  5702. {
  5703. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5704. {
  5705. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5706. {
  5707. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5708. goto end;
  5709. }
  5710. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5711. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5712. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5713. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5714. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5715. {
  5716. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5717. goto end;
  5718. }
  5719. else
  5720. {
  5721. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5722. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5723. goto end;
  5724. }
  5725. }
  5726. }//END FOR CCS_QUANTITY
  5727. for (int index = 0; index < GB_QUANTITY; index++)
  5728. {
  5729. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5730. {
  5731. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5732. {
  5733. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5734. goto end;
  5735. }
  5736. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5737. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5738. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5739. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5740. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5741. {
  5742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5743. goto end;
  5744. }
  5745. else
  5746. {
  5747. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5749. goto end;
  5750. }
  5751. }
  5752. }// END FOR GB_QUANTITY
  5753. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5754. {
  5755. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))
  5756. {
  5757. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5758. {
  5759. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5760. goto end;
  5761. }
  5762. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5763. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5764. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5765. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5766. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5767. {
  5768. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5769. goto end;
  5770. }
  5771. else
  5772. {
  5773. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5774. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5775. goto end;
  5776. }
  5777. }
  5778. }// END FOR GENERAL_GUN_QUANTITY
  5779. for (int index = 0; index < AC_QUANTITY; index++)
  5780. {
  5781. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5782. {
  5783. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5784. {
  5785. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5786. goto end;
  5787. }
  5788. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5789. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5790. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5791. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5792. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5793. {
  5794. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5795. goto end;
  5796. }
  5797. else
  5798. {
  5799. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5800. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5801. goto end;
  5802. }
  5803. }
  5804. }//END FOR AC_QUANTITY
  5805. }//END FOR AvailabilityTypeStr[Inoperative]
  5806. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5807. {
  5808. //----------------------gunIndex is 0 ------------------------------------------------//
  5809. if(gunIndex == 0)
  5810. {
  5811. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5812. {
  5813. for(int i=0; i < gunTotalNumber; i++)
  5814. {
  5815. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5816. {
  5817. if ((gunType[i] == 'J' )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5818. {
  5819. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5820. goto end;
  5821. }
  5822. }//END FOR CHAdeMO_QUANTITY
  5823. for (int index = 0; index < CCS_QUANTITY; index++)
  5824. {
  5825. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5826. {
  5827. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5828. goto end;
  5829. }
  5830. }//END FOR CCS_QUANTITY
  5831. for (int index = 0; index < GB_QUANTITY; index++)
  5832. {
  5833. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5834. {
  5835. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5836. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5837. goto end;
  5838. }
  5839. }// END FOR GB_QUANTITY
  5840. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5841. {
  5842. if ((gunType[i] == 'O')&&(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
  5843. {
  5844. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5845. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5846. goto end;
  5847. }
  5848. }// END FOR GENERAL_GUN_QUANTITY
  5849. for (int index = 0; index < AC_QUANTITY; index++)
  5850. {
  5851. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5852. {
  5853. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5854. goto end;
  5855. }
  5856. }//END FOR CHAdeMO_QUANTITY
  5857. }// END FOR gunTotalNumber
  5858. }
  5859. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5860. {
  5861. for(int i=0; i < gunTotalNumber; i++)
  5862. {
  5863. for (int index = 0; index < AC_QUANTITY; index++)
  5864. {
  5865. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5866. {
  5867. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5868. goto end;
  5869. }
  5870. }//END FOR CHAdeMO_QUANTITY
  5871. } // END FOR gunTotalNumber
  5872. }
  5873. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5874. goto end;
  5875. }
  5876. //----------------------gunIndex is not 0 ------------------------------------------------//
  5877. //check Transaction active
  5878. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5879. {
  5880. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5881. {
  5882. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5883. goto end;
  5884. }
  5885. }//END FOR CHAdeMO_QUANTITY
  5886. for (int index = 0; index < CCS_QUANTITY; index++)
  5887. {
  5888. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5889. {
  5890. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5891. goto end;
  5892. }
  5893. }//END FOR CCS_QUANTITY
  5894. for (int index = 0; index < GB_QUANTITY; index++)
  5895. {
  5896. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5897. {
  5898. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5899. goto end;
  5900. }
  5901. }// END FOR GB_QUANTITY
  5902. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5903. {
  5904. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5905. {
  5906. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5907. goto end;
  5908. }
  5909. }// END FOR GENERAL_GUN_QUANTITY
  5910. for (int index = 0; index < AC_QUANTITY; index++)
  5911. {
  5912. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5913. {
  5914. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5915. goto end;
  5916. }
  5917. }//END FOR AC_QUANTITY
  5918. }//END FOR AvailabilityTypeStr[Operative]
  5919. end:
  5920. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5921. {
  5922. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5923. }
  5924. else
  5925. {
  5926. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5927. }
  5928. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5929. {
  5930. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5931. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5932. }
  5933. else if(gunIndex == 0)
  5934. {
  5935. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5936. {
  5937. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5938. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5939. }
  5940. }
  5941. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5942. return result;
  5943. }
  5944. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5945. {
  5946. mtrace();
  5947. int result = FAIL;
  5948. char keystr[40]={0};
  5949. char valuestr[100]={0};
  5950. char comfirmstr[20]={0};
  5951. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5952. json_object *ChangeConfiguration;
  5953. ChangeConfiguration = json_tokener_parse(payload);
  5954. if(!is_error(ChangeConfiguration))
  5955. {
  5956. // Required data
  5957. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  5958. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5959. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  5960. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5961. }
  5962. json_object_put(ChangeConfiguration);
  5963. if((uuid==NULL) || (payload ==NULL) )
  5964. {
  5965. DEBUG_ERROR("Payload is null\n");
  5966. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5967. }
  5968. else
  5969. {
  5970. int status = setKeyValue(keystr, valuestr);
  5971. switch(status)
  5972. {
  5973. case ConfigurationStatus_Accepted:
  5974. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5975. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5976. StoreConfigurationTable();
  5977. break;
  5978. case RebootRequired:
  5979. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5980. StoreConfigurationTable();
  5981. break;
  5982. case NotSupported:
  5983. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5984. break;
  5985. case ConfigurationStatus_Rejected:
  5986. default:
  5987. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5988. break;
  5989. }
  5990. }
  5991. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5992. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5993. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5994. {
  5995. ChageWebSocketPingInterval(atoi(valuestr));
  5996. }
  5997. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5998. {
  5999. SetOcppConnStatus(FALSE);
  6000. }
  6001. return result;
  6002. }
  6003. int handleClearCacheRequest(char *uuid, char *payload)
  6004. {
  6005. mtrace();
  6006. int result = FAIL;
  6007. char comfirmstr[20];
  6008. char rmFileCmd[100]={0};
  6009. struct stat stats;
  6010. DEBUG_INFO("handleClearCacheRequest...\n");
  6011. stat("/Storage/OCPP", &stats);
  6012. // Check for directory existence
  6013. if (S_ISDIR(stats.st_mode) == 1)
  6014. {}
  6015. else
  6016. {
  6017. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6018. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6019. system(rmFileCmd);
  6020. }
  6021. if(OCPP_cleanLocalCache())
  6022. {
  6023. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6024. }
  6025. else
  6026. {
  6027. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6028. }
  6029. sendClearCacheConfirmation(uuid, comfirmstr);
  6030. return result;
  6031. }
  6032. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6033. {
  6034. mtrace();
  6035. int result = FAIL;
  6036. int resultRename;
  6037. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6038. char chargingProfilePurposeStr[26]={0};
  6039. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6040. char tempchargingProfilePurposeStr[26]={0};
  6041. char str[100]={0};
  6042. char fname[200]={0};
  6043. char comfirmstr[20]={0};
  6044. char word[1600]={0};
  6045. int clearflag = FALSE;
  6046. int chargingProfileIdIsNULL = FALSE;
  6047. int connectorIsNULL = FALSE;
  6048. int chargingProfilePurposeIsNULL = FALSE;
  6049. int stackLevelIsNULL = FALSE;
  6050. //int GotoEnd = FALSE;
  6051. FILE *fptr1, *fptr2;
  6052. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6053. int n_chargingProfile=0;
  6054. int isEmptyFile = FALSE;
  6055. char sLineWord[1600]={0};
  6056. char chargingProfiles[10][100]={0};
  6057. int ChargeProfileCount = 0;
  6058. int ch;
  6059. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6060. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6061. json_object *ClearChargingProfile;
  6062. ClearChargingProfile = json_tokener_parse(payload);
  6063. if(!is_error(ClearChargingProfile))
  6064. {
  6065. // Optional data
  6066. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6067. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6068. else
  6069. chargingProfileIdIsNULL = TRUE;
  6070. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6071. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6072. else
  6073. connectorIsNULL = TRUE;
  6074. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6075. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6076. else
  6077. chargingProfilePurposeIsNULL = TRUE;
  6078. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6079. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6080. else
  6081. stackLevelIsNULL = TRUE;
  6082. }
  6083. json_object_put(ClearChargingProfile);
  6084. if(connectorIsNULL == FALSE)
  6085. {
  6086. switch(connectorIdInt)
  6087. {
  6088. case 0:
  6089. if(chargingProfilePurposeIsNULL == TRUE)
  6090. {
  6091. int l = 0;
  6092. strcpy(fname, ChargePointMaxProfile_JSON);
  6093. if((access(fname,F_OK))!=-1)
  6094. {
  6095. strcpy(chargingProfiles[l], fname);
  6096. l = l + 1;
  6097. }
  6098. strcpy(fname, TxDefaultProfile_0_JSON);
  6099. if((access(fname,F_OK))!=-1)
  6100. {
  6101. strcpy(chargingProfiles[l], fname);
  6102. l = l + 1;
  6103. }
  6104. ChargeProfileCount = l;
  6105. }
  6106. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6107. {
  6108. strcpy(fname, ChargePointMaxProfile_JSON);
  6109. if((access(fname,F_OK))!=-1)
  6110. {
  6111. strcpy(chargingProfiles[0], fname);
  6112. ChargeProfileCount = 1;
  6113. }
  6114. }
  6115. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6116. {
  6117. strcpy(fname, TxDefaultProfile_0_JSON);
  6118. if((access(fname,F_OK))!=-1)
  6119. {
  6120. strcpy(chargingProfiles[0], fname);
  6121. ChargeProfileCount = 1;
  6122. }
  6123. }
  6124. break;
  6125. default:
  6126. if(chargingProfilePurposeIsNULL == TRUE)
  6127. {
  6128. int m = 0;
  6129. memset(fname, 0, ARRAY_SIZE(fname));
  6130. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6131. if((access(fname,F_OK))!=-1)
  6132. {
  6133. strcpy(chargingProfiles[m], fname);
  6134. m = m + 1;
  6135. }
  6136. memset(fname, 0, ARRAY_SIZE(fname));
  6137. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6138. if((access(fname,F_OK))!=-1)
  6139. {
  6140. strcpy(chargingProfiles[m], fname);
  6141. m = m + 1;
  6142. }
  6143. ChargeProfileCount = m;
  6144. }
  6145. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6146. {
  6147. //strcpy(fname, TxDefaultProfile_1_JSON);
  6148. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6149. if((access(fname,F_OK))!=-1)
  6150. {
  6151. strcpy(chargingProfiles[0], fname);
  6152. ChargeProfileCount = 1;
  6153. }
  6154. }
  6155. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6156. {
  6157. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6158. if((access(fname,F_OK))!=-1)
  6159. {
  6160. strcpy(chargingProfiles[0], fname);
  6161. ChargeProfileCount = 1;
  6162. }
  6163. //strcpy(fname, TxProfile_1_JSON);
  6164. }
  6165. //strcpy(fname, ChargePointMaxProfile_JSON );
  6166. break;
  6167. }
  6168. }
  6169. else // Check all Charging Profiles
  6170. {
  6171. int i = 0;
  6172. char fnametemp[200]={0};
  6173. ChargeProfileCount = 0;
  6174. //Check ChargePointMaxProfile.json exit
  6175. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6176. {
  6177. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6178. i = i + 1;
  6179. }
  6180. //Check TxDefaultProfile_0.json exit
  6181. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6182. {
  6183. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6184. i = i + 1;
  6185. }
  6186. //Check TxDefaultProfile_%d.json
  6187. for(int j=1; j <= gunTotalNumber; j++)
  6188. {
  6189. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6190. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6191. if((access(fnametemp,F_OK))!=-1)
  6192. {
  6193. strcpy(chargingProfiles[i], fnametemp);
  6194. i = i + 1;
  6195. }
  6196. }
  6197. //Check TxProfile_%d.json
  6198. for(int j=1; j <= gunTotalNumber; j++)
  6199. {
  6200. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6201. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6202. if((access(fnametemp,F_OK))!=-1)
  6203. {
  6204. strcpy(chargingProfiles[i], fnametemp);
  6205. i = i + 1;
  6206. }
  6207. }
  6208. ChargeProfileCount = i;
  6209. }// End connectorIsNULL is TRUE
  6210. if(ChargeProfileCount == 0)
  6211. {
  6212. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6213. goto end;
  6214. }
  6215. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6216. {
  6217. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6218. goto end;
  6219. }
  6220. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6221. {
  6222. memset(str, 0, ARRAY_SIZE(str));
  6223. // clear temp file
  6224. sprintf(str,"rm -f %s",temp);
  6225. system(str);
  6226. for(int k=0; k < ChargeProfileCount; k++)
  6227. {
  6228. memset(str, 0, ARRAY_SIZE(str));
  6229. //clear file in C
  6230. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6231. system(str);
  6232. }
  6233. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6234. goto end;
  6235. }
  6236. else if(connectorIsNULL == TRUE)
  6237. {
  6238. for(int k=0; k < ChargeProfileCount; k++)
  6239. {
  6240. fptr1 = fopen(chargingProfiles[k], "r");
  6241. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6242. //Check Charging Profile Count
  6243. while(fscanf(fptr1, "%s", word) != EOF)
  6244. {
  6245. //DEBUG_INFO("word=%s\n",word);
  6246. if(strstr(word, "chargingProfileId")!= NULL)
  6247. {
  6248. //DEBUG_INFO("test chargingProfileId \n");
  6249. n_chargingProfile = n_chargingProfile + 1;
  6250. //DEBUG_INFO("chargingProfileId Found\n");
  6251. }
  6252. }
  6253. rewind(fptr1);
  6254. //search Charging Profile Element
  6255. //int i= 0;
  6256. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6257. {
  6258. json_object *tmpProfilee;
  6259. tmpProfilee = json_tokener_parse(sLineWord);
  6260. if(!is_error(tmpProfilee))
  6261. {
  6262. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6263. {
  6264. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6265. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6266. }
  6267. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6268. {
  6269. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6270. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6271. }
  6272. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6273. {
  6274. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6275. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6276. }
  6277. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6278. {
  6279. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6280. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6281. }
  6282. }
  6283. json_object_put(tmpProfilee);
  6284. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6285. {
  6286. //------- not write to fptr2-------//
  6287. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6288. //clearflag = TRUE;
  6289. }
  6290. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6291. {
  6292. //------- not write to fptr2-------//
  6293. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6294. }
  6295. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6296. {
  6297. //------- not write to fptr2-------//
  6298. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6299. }
  6300. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6301. {
  6302. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6303. }
  6304. else
  6305. {
  6306. fprintf(fptr2, sLineWord);//writing data into file
  6307. }
  6308. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6309. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6310. if(clearflag == TRUE)
  6311. {
  6312. fclose(fptr1);
  6313. fclose(fptr2);
  6314. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6315. system(str);
  6316. // clear temp file
  6317. sprintf(str,"rm -f %s",temp);
  6318. system(str);
  6319. }
  6320. else
  6321. {
  6322. fclose(fptr1);
  6323. fclose(fptr2);
  6324. memset(str, 0, ARRAY_SIZE(str));
  6325. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6326. system(str);
  6327. resultRename = rename(temp, chargingProfiles[k]);
  6328. if(resultRename == 0)
  6329. {
  6330. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6331. }
  6332. else
  6333. {
  6334. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6335. }
  6336. if(comfirmstr[0]== 0)
  6337. {
  6338. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6339. }
  6340. //Check chargingProfile is empty file
  6341. /*------ Read the file ----------------*/
  6342. fptr1=fopen(chargingProfiles[k],"r");
  6343. ch=fgetc(fptr1);
  6344. rewind(fptr1);
  6345. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6346. if(ch!=EOF)
  6347. {
  6348. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6349. {
  6350. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6351. if(sLineWord[0]=='\0')
  6352. {
  6353. isEmptyFile = TRUE;
  6354. break;
  6355. }
  6356. else
  6357. {
  6358. isEmptyFile = FALSE;
  6359. break;
  6360. }
  6361. }
  6362. }
  6363. else
  6364. isEmptyFile = TRUE;
  6365. fclose(fptr1);
  6366. if(isEmptyFile == TRUE)
  6367. {
  6368. memset(str, 0, ARRAY_SIZE(str));
  6369. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6370. system(str);
  6371. }
  6372. }
  6373. }// End of while(int k=0; k < ChargePointCount; k++)
  6374. }
  6375. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6376. {
  6377. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6378. for(int k=0; k < ChargeProfileCount; k++)
  6379. {
  6380. fptr1 = fopen(chargingProfiles[k], "r");
  6381. fptr2 = fopen(temp, "w+");
  6382. //Check Charging Profile Count
  6383. while(fscanf(fptr1, "%s", word) != EOF)
  6384. {
  6385. //DEBUG_INFO("word=%s\n",word);
  6386. if(strstr(word, "chargingProfileId")!= NULL)
  6387. {
  6388. n_chargingProfile = n_chargingProfile + 1;
  6389. }
  6390. }
  6391. rewind(fptr1);
  6392. //search Charging Profile Element
  6393. //int i= 0;
  6394. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6395. {
  6396. json_object *tmpProfilee;
  6397. tmpProfilee = json_tokener_parse(sLineWord);
  6398. if(!is_error(tmpProfilee))
  6399. {
  6400. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6401. {
  6402. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6403. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6404. }
  6405. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6406. {
  6407. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6408. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6409. }
  6410. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6411. {
  6412. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6413. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6414. }
  6415. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6416. {
  6417. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6418. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6419. }
  6420. }
  6421. json_object_put(tmpProfilee);
  6422. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6423. {
  6424. //------- not write to fptr2-------//
  6425. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6426. //clearflag = TRUE;
  6427. }
  6428. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6429. {
  6430. //------- not write to fptr2-------//
  6431. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6432. }
  6433. else if(stackLevelIsNULL == TRUE)
  6434. {
  6435. //Clear Whole File
  6436. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6437. clearflag = TRUE;
  6438. break;
  6439. }
  6440. else
  6441. {
  6442. fprintf(fptr2, sLineWord);//writing data into file
  6443. }
  6444. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6445. }
  6446. if(clearflag == TRUE)
  6447. {
  6448. fclose(fptr1);
  6449. fclose(fptr2);
  6450. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6451. system(str);
  6452. // clear temp file
  6453. sprintf(str,"rm -f %s",temp);
  6454. system(str);
  6455. }
  6456. else
  6457. {
  6458. fclose(fptr1);
  6459. fclose(fptr2);
  6460. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6461. system(str);
  6462. resultRename = rename(temp, chargingProfiles[k]);
  6463. if(resultRename == 0)
  6464. {
  6465. DEBUG_INFO("File ChargingProfile renamed successfully");
  6466. }
  6467. else
  6468. {
  6469. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6470. }
  6471. if(comfirmstr[0]== 0)
  6472. {
  6473. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6474. }
  6475. //Check chargingProfile is empty file
  6476. /*------ Read the file ----------------*/
  6477. fptr1=fopen(chargingProfiles[k],"r");
  6478. ch=fgetc(fptr1);
  6479. rewind(fptr1);
  6480. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6481. if(ch!=EOF)
  6482. {
  6483. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6484. {
  6485. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6486. if(sLineWord[0]=='\0')
  6487. {
  6488. isEmptyFile = TRUE;
  6489. break;
  6490. }
  6491. else
  6492. {
  6493. isEmptyFile = FALSE;
  6494. break;
  6495. }
  6496. }
  6497. }
  6498. else
  6499. isEmptyFile = TRUE;
  6500. fclose(fptr1);
  6501. if(isEmptyFile == TRUE)
  6502. {
  6503. memset(str, 0, ARRAY_SIZE(str));
  6504. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6505. system(str);
  6506. }
  6507. /*------- End of reading ---------------*/
  6508. }
  6509. } // while(int k=0; k < ChargeProfileCount; k++)
  6510. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6511. end:
  6512. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6513. {
  6514. if(connectorIdInt == 0)
  6515. {
  6516. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6517. {
  6518. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  6519. }
  6520. }
  6521. else
  6522. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  6523. }
  6524. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6525. return result;
  6526. }
  6527. void createFirmwareVersionByDataTransfer(void)
  6528. {
  6529. json_object *FirmwareDataTransfer = json_object_new_object();
  6530. // AC & DC model
  6531. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6532. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6533. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6534. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6535. // DC model
  6536. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  6537. {
  6538. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6539. {
  6540. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6541. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6542. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6543. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6544. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6545. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6546. }
  6547. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6548. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6549. {
  6550. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6551. }
  6552. }
  6553. else
  6554. {
  6555. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6556. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6557. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6558. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6559. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  6560. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  6561. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  6562. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  6563. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  6564. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  6565. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  6566. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  6567. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  6568. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  6569. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  6570. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  6571. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  6572. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  6573. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  6574. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  6575. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  6576. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  6577. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  6578. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  6579. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  6580. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  6581. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  6582. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  6583. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  6584. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  6585. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  6586. }
  6587. // 4G model
  6588. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6589. {
  6590. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6591. }
  6592. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6593. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6594. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6595. json_object_put(FirmwareDataTransfer);
  6596. }
  6597. int handleDataTransferRequest(char *uuid, char *payload)
  6598. {
  6599. mtrace();
  6600. json_object *response = json_object_new_object();
  6601. int result = FAIL;
  6602. char tempvendorId[255]={0};
  6603. char tempmessageId[50]={0};
  6604. char tempdata[512]={0};
  6605. char message[2048]={0};
  6606. DEBUG_INFO("handleDataTransferRequest...\n");
  6607. if((uuid != NULL) && (payload != NULL))
  6608. {
  6609. json_object *DataTransfer;
  6610. DataTransfer = json_tokener_parse(payload);
  6611. if(!is_error(DataTransfer))
  6612. {
  6613. // Required data
  6614. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6615. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6616. // Optional data
  6617. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6618. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6619. if(json_object_object_get(DataTransfer, "data") != NULL)
  6620. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6621. result = PASS;
  6622. }
  6623. json_object_put(DataTransfer);
  6624. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6625. {
  6626. // Send all moudle firmware version on EVSE
  6627. createFirmwareVersionByDataTransfer();
  6628. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6629. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6630. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6631. json_object_put(response);
  6632. }
  6633. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  6634. {
  6635. system("/usr/bin/run_tmate_restart.sh &");
  6636. }
  6637. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6638. {
  6639. json_object *data;
  6640. data = json_tokener_parse(tempdata);
  6641. if(!is_error(data))
  6642. {
  6643. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6644. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6645. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6646. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6647. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6648. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6649. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6650. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6651. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6652. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6653. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6654. }
  6655. else
  6656. {
  6657. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6658. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6659. }
  6660. json_object_put(data);
  6661. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6662. json_object_put(response);
  6663. }
  6664. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6665. {
  6666. json_object *data;
  6667. data = json_tokener_parse(tempdata);
  6668. if(!is_error(data))
  6669. {
  6670. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  6671. if(json_object_object_get(data, "idToken") != NULL)
  6672. {
  6673. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  6674. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6675. }
  6676. if(json_object_object_get(data, "price") != NULL)
  6677. {
  6678. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  6679. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6680. }
  6681. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6682. }
  6683. else
  6684. {
  6685. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6686. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6687. }
  6688. json_object_put(data);
  6689. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6690. json_object_put(response);
  6691. }
  6692. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6693. {
  6694. json_object *data;
  6695. data = json_tokener_parse(tempdata);
  6696. if(!is_error(data))
  6697. {
  6698. if(json_object_object_get(data, "txId") != NULL)
  6699. {
  6700. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6701. for(int idx = 0;idx<gunTotalNumber;idx++)
  6702. {
  6703. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6704. {
  6705. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6706. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6707. if(json_object_object_get(data, "description") != NULL)
  6708. {
  6709. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6710. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6711. }
  6712. }
  6713. }
  6714. }
  6715. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6716. }
  6717. else
  6718. {
  6719. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6720. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6721. }
  6722. json_object_put(data);
  6723. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6724. json_object_put(response);
  6725. }
  6726. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6727. {
  6728. json_object *data;
  6729. data = json_tokener_parse(tempdata);
  6730. if(!is_error(data))
  6731. {
  6732. if(json_object_object_get(data, "txId") != NULL)
  6733. {
  6734. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6735. for(int idx = 0;idx<gunTotalNumber;idx++)
  6736. {
  6737. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6738. {
  6739. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6740. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6741. if(json_object_object_get(data, "description") != NULL)
  6742. {
  6743. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6744. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6745. }
  6746. }
  6747. }
  6748. }
  6749. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6750. }
  6751. else
  6752. {
  6753. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6754. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6755. }
  6756. json_object_put(data);
  6757. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6758. json_object_put(response);
  6759. }
  6760. else
  6761. {
  6762. // Can not find valid message id
  6763. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6764. }
  6765. }
  6766. else
  6767. {
  6768. // Payload is null
  6769. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6770. }
  6771. LWS_Send(message);
  6772. return result;
  6773. }
  6774. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6775. {
  6776. mtrace();
  6777. int result = FAIL;
  6778. int connectorIdInt, durationInt;
  6779. char chargingRateUnitStr[4]={0};
  6780. char comfirmstr[20];
  6781. int confirmPeriods = 0;
  6782. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6783. json_object *GetCompositeSchedule;
  6784. GetCompositeSchedule = json_tokener_parse(payload);
  6785. if(!is_error(GetCompositeSchedule))
  6786. {
  6787. // Required data
  6788. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6789. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6790. else
  6791. connectorIdInt = -1;
  6792. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6793. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6794. else
  6795. durationInt = 86400;
  6796. // Optional data
  6797. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6798. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6799. }
  6800. json_object_put(GetCompositeSchedule);
  6801. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6802. if((connectorIdInt == 0) ||
  6803. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6804. {
  6805. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6806. struct StructChargingProfile tmpProfile[1];
  6807. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6808. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6809. {
  6810. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6811. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6812. }
  6813. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6814. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6815. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6816. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6817. {
  6818. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6819. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6820. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6821. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6822. {
  6823. confirmPeriods = idx;
  6824. break;
  6825. }
  6826. }
  6827. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6828. }
  6829. else
  6830. {
  6831. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6832. }
  6833. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6834. return result;
  6835. }
  6836. int handleGetConfigurationRequest(char *uuid, char *payload)
  6837. {
  6838. mtrace();
  6839. int result = FAIL;
  6840. int MaxKeySupported = 0;
  6841. int n_keys = 0;
  6842. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6843. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6844. json_object *GetConfiguration;
  6845. GetConfiguration = json_tokener_parse(payload);
  6846. if(!is_error(GetConfiguration))
  6847. {
  6848. // Optional data
  6849. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6850. {
  6851. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6852. {
  6853. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6854. n_keys = idx + 1;
  6855. }
  6856. }
  6857. }
  6858. json_object_put(GetConfiguration);
  6859. UnknownKeynum = 0;
  6860. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6861. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6862. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6863. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6864. if(n_keys != 0)
  6865. {
  6866. for(int i=0;i<n_keys;i++)
  6867. {
  6868. getKeyValue(requestKey[i]);
  6869. }
  6870. }
  6871. else
  6872. {
  6873. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6874. getKeyValue("");
  6875. }
  6876. processUnkownKey();
  6877. sendGetConfigurationConfirmation(uuid);
  6878. return result;
  6879. }
  6880. static char fnamePlusPath[100]={0};
  6881. static char fnamePWithNoPath[60]={0};
  6882. void checkUploadLog(void)
  6883. {
  6884. FILE *fp;
  6885. /* Open the command for reading. */
  6886. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6887. if (fp == NULL) {
  6888. printf("Failed to run command\n" );
  6889. exit(1);
  6890. }
  6891. int ftppathlen = 0;
  6892. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6893. int i = 0;
  6894. /* Read the output a line at a time - output it. */
  6895. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6896. if(i==0)
  6897. {
  6898. ftppathlen = strlen(fnamePlusPath);
  6899. printf("%s\n", fnamePlusPath);
  6900. fnamePlusPath[ftppathlen]='\0';
  6901. break;
  6902. }
  6903. i= i+1;
  6904. }
  6905. /* close */
  6906. pclose(fp);
  6907. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6908. {
  6909. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  6910. {
  6911. fnamePlusPath[k]='\0';
  6912. }
  6913. }
  6914. i=1;
  6915. //char fname[60]={0};
  6916. while(i < ftppathlen)
  6917. {
  6918. int len=ftppathlen-i;
  6919. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6920. {
  6921. printf("compare '/' all right\n");
  6922. break;
  6923. }
  6924. i=i+1;
  6925. }
  6926. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6927. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6928. fnamePWithNoPath[i+1] = '\0';
  6929. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6930. {
  6931. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6932. {
  6933. fnamePWithNoPath[j]='\0';
  6934. }
  6935. }
  6936. FILE* fp1 = fopen(fnamePlusPath, "r");
  6937. if (fp1)
  6938. {
  6939. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6940. // file exists
  6941. fclose(fp1);
  6942. }
  6943. else
  6944. {
  6945. // file doesn't exist
  6946. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6947. }
  6948. }
  6949. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6950. {
  6951. mtrace();
  6952. int result = FAIL;
  6953. time_t CurrentTime;
  6954. struct tm *tm;
  6955. pthread_t th_Status;
  6956. CurrentTime = time(NULL);
  6957. tm = localtime(&CurrentTime);
  6958. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  6959. 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);
  6960. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6961. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6962. return result;
  6963. }
  6964. void* GetDiagnosticsProcess(void* data)
  6965. {
  6966. pthread_detach(pthread_self());
  6967. mtrace();
  6968. int retriesInt=0, retryIntervalInt=0;
  6969. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6970. 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};
  6971. int port=0;
  6972. int isSuccess = FALSE;
  6973. char ftpbuf[200]={0};
  6974. char cmdBuf[512];
  6975. json_object *GetDiagnostics;
  6976. DEBUG_INFO("GetDiagnosticsProcess...\n");
  6977. GetDiagnostics = json_tokener_parse(data);
  6978. if(!is_error(GetDiagnostics))
  6979. {
  6980. // Required data
  6981. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  6982. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  6983. // Optional data
  6984. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  6985. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  6986. else
  6987. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6988. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  6989. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  6990. else
  6991. retryIntervalInt = 30;
  6992. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  6993. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  6994. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  6995. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  6996. }
  6997. json_object_put(GetDiagnostics);
  6998. // Pack log to compress file
  6999. system("exec /root/logPackTools 'log' 6");
  7000. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7001. system(cmdBuf);
  7002. checkUploadLog();
  7003. //****************location*******************/
  7004. if(strcmp(locationstr,"")==0)
  7005. {
  7006. DEBUG_INFO("location is <Empty>!\n");
  7007. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7008. goto end;
  7009. }
  7010. memset(protocol, 0, ARRAY_SIZE(protocol));
  7011. memset(user, 0, ARRAY_SIZE(user) );
  7012. memset(password, 0, ARRAY_SIZE(password));
  7013. memset(host, 0, ARRAY_SIZE(host));
  7014. memset(path, 0, ARRAY_SIZE(path));
  7015. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7016. memset(host1, 0, ARRAY_SIZE(host1));
  7017. memset(path1, 0, ARRAY_SIZE(path1));
  7018. /*location: ftp://user:password@host:port/path*/
  7019. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7020. if((access(fnamePlusPath,F_OK))!=-1)
  7021. {
  7022. DEBUG_INFO("fnamePlusPath exist.\n");
  7023. }
  7024. else
  7025. {
  7026. DEBUG_INFO("fnamePlusPath not exist!\n");
  7027. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7028. goto end;
  7029. }
  7030. if(strchr(locationstr,'@')==NULL)
  7031. {
  7032. sscanf(locationstr,
  7033. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7034. protocol, host, &port, path);
  7035. strcpy(user,"anonymous");
  7036. strcpy(password,"");
  7037. }
  7038. else
  7039. {
  7040. //DEBUG_INFO("pch=%s\n", pch);
  7041. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7042. protocol, user, password, host, &port, path);
  7043. }
  7044. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7045. {
  7046. DEBUG_INFO("protocol is not ftp/http ! \n");
  7047. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7048. goto end;
  7049. }
  7050. if(strncmp(locationstr,"http", 4) == 0)
  7051. {
  7052. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7053. sprintf(ftppath,"/%s", path);
  7054. do
  7055. {
  7056. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7057. sleep(3);
  7058. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7059. if(!isSuccess)
  7060. {
  7061. DEBUG_INFO("Diagnostics fail.\n");
  7062. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7063. sleep(retryIntervalInt);
  7064. }
  7065. else
  7066. {
  7067. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7068. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7069. }
  7070. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  7071. }
  7072. else
  7073. {
  7074. sscanf(host,"%[^/]%s",host1, path1);
  7075. sprintf(ftppath,"%s", path1);
  7076. int ftppathlen=strlen(ftppath);
  7077. int i=1;
  7078. char filenametemp[50];
  7079. while(i < ftppathlen)
  7080. {
  7081. int len=ftppathlen-i;
  7082. if(ftppath[len]== 47) // '/' ascll code: 47
  7083. {
  7084. DEBUG_INFO("find '/' all right\n");
  7085. break;
  7086. }
  7087. i=i+1;
  7088. }
  7089. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7090. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7091. filenametemp[i+1] = 0;
  7092. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7093. if(port == 0)
  7094. port = 21;
  7095. do
  7096. {
  7097. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7098. sleep(3);
  7099. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7100. if(!isSuccess)
  7101. {
  7102. DEBUG_INFO("Diagnostics fail.\n");
  7103. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7104. sleep(retryIntervalInt);
  7105. }
  7106. else
  7107. {
  7108. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7109. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7110. }
  7111. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  7112. }
  7113. end:
  7114. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7115. pthread_exit(NULL);
  7116. }
  7117. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7118. {
  7119. mtrace();
  7120. int result = FAIL;
  7121. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7122. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7123. {
  7124. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7125. localversion = -1;
  7126. }
  7127. else
  7128. {
  7129. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7130. OCPP_getListVerion();
  7131. }
  7132. //from db.OCPP_getListVerion
  7133. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7134. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7135. sendGetLocalListVersionConfirmation(uuid,"");
  7136. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7137. return result;
  7138. }
  7139. int handleRemoteStartRequest(char *uuid, char *payload)
  7140. {
  7141. mtrace();
  7142. int result = FAIL;
  7143. int connectorIdInt=0;
  7144. int tempIndex = 0;
  7145. int connectorIdIsNULL, chargingProfileIsNULL;
  7146. char comfirmstr[20]={0};
  7147. char cmdBuf[512];
  7148. json_object *RemoteStartTransaction;
  7149. FILE *fp;
  7150. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7151. if(server_pending == TRUE)
  7152. {
  7153. return 0;
  7154. }
  7155. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7156. RemoteStartTransaction = json_tokener_parse(payload);
  7157. if(!is_error(RemoteStartTransaction))
  7158. {
  7159. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7160. {
  7161. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7162. if(connectorIdInt <= gunTotalNumber)
  7163. {
  7164. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7165. // Required data
  7166. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7167. // Optional data
  7168. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7169. {
  7170. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7171. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7172. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7173. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7174. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7175. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7176. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7177. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7178. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7179. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7180. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7181. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7182. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7183. {
  7184. 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")));
  7185. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7186. 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"));
  7187. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7188. 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"));
  7189. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7190. 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")));
  7191. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7192. {
  7193. 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++)
  7194. {
  7195. 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"));
  7196. 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"));
  7197. 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)
  7198. 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"));
  7199. }
  7200. }
  7201. }
  7202. }
  7203. else
  7204. chargingProfileIsNULL = TRUE;
  7205. }
  7206. }
  7207. else
  7208. connectorIdIsNULL = TRUE;
  7209. }
  7210. else
  7211. connectorIdIsNULL = TRUE;
  7212. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7213. {
  7214. DEBUG_WARN("Connector id is NULL\n.");
  7215. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7216. goto end;
  7217. }
  7218. /*
  7219. enum _SYSTEM_STATUS
  7220. {
  7221. S_BOOTING = 0,
  7222. S_IDLE, = 1
  7223. S_AUTHORIZING, = 2
  7224. S_REASSIGN_CHECK, = 3
  7225. S_REASSIGN, = 4
  7226. S_PRECHARGE, = 5
  7227. S_PREPARING_FOR_EV, = 6
  7228. S_PREPARING_FOR_EVSE, = 7
  7229. S_CHARGING, = 8
  7230. S_TERMINATING, = 9
  7231. S_COMPLETE, = 10
  7232. S_ALARM, = 11
  7233. S_FAULT = 12
  7234. }
  7235. */
  7236. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7237. {
  7238. //check Transaction active
  7239. if(gunType[connectorIdInt -1] == 'J')
  7240. {
  7241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7242. {
  7243. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7244. }
  7245. else
  7246. {
  7247. tempIndex = connectorIdInt -1;
  7248. }
  7249. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7250. {
  7251. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7252. {
  7253. 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))
  7254. {
  7255. //Reserved
  7256. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7257. }
  7258. 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))
  7259. {
  7260. //Reserved
  7261. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7262. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7263. goto end;
  7264. }
  7265. else
  7266. {
  7267. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7268. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7269. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7270. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7271. {
  7272. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7273. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7274. goto end;
  7275. }
  7276. }//END FOR ELSE
  7277. }
  7278. }// END FOR CHAdeMO_QUANTITY
  7279. }
  7280. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7281. {
  7282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7283. {
  7284. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7285. }
  7286. else
  7287. {
  7288. tempIndex = connectorIdInt -1;
  7289. }
  7290. for (int index = 0; index < CCS_QUANTITY; index++)
  7291. {
  7292. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7293. {
  7294. 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))
  7295. {
  7296. //Reserved
  7297. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7298. }
  7299. 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))
  7300. {
  7301. //Reserved
  7302. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7303. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7304. goto end;
  7305. }
  7306. else
  7307. {
  7308. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7309. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7310. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7311. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7312. {
  7313. DEBUG_WARN("CCS connector not allow start\n.");
  7314. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7315. goto end;
  7316. }
  7317. }// END FOR ELSE
  7318. }
  7319. }// END FOR CCS_QUANTITY
  7320. }
  7321. else if(gunType[connectorIdInt -1] == 'G')
  7322. {
  7323. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7324. {
  7325. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7326. }
  7327. else
  7328. {
  7329. tempIndex = connectorIdInt -1;
  7330. }
  7331. for (int index = 0; index < GB_QUANTITY; index++)
  7332. {
  7333. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7334. {
  7335. 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))
  7336. {
  7337. //Reserved
  7338. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7339. }
  7340. 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))
  7341. {
  7342. //Reserved
  7343. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7344. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7345. goto end;
  7346. }
  7347. else
  7348. {
  7349. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7350. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7351. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7352. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7353. {
  7354. DEBUG_WARN("GB connector not allow start\n.");
  7355. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7356. goto end;
  7357. }
  7358. }// END FOR ELSE
  7359. }
  7360. } // END FOR GB_QUANTITY
  7361. }
  7362. else if(gunType[connectorIdInt -1] == 'O')
  7363. {
  7364. tempIndex = connectorIdInt -1;
  7365. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7366. {
  7367. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7368. {
  7369. 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))
  7370. {
  7371. //Reserved
  7372. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7373. }
  7374. 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))
  7375. {
  7376. //Reserved
  7377. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7378. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7379. goto end;
  7380. }
  7381. else
  7382. {
  7383. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7384. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7385. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7386. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7387. {
  7388. DEBUG_WARN("GB connector not allow start\n.");
  7389. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7390. goto end;
  7391. }
  7392. }// END FOR ELSE
  7393. }
  7394. } // END FOR GB_QUANTITY
  7395. }
  7396. else
  7397. {
  7398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7399. {
  7400. tempIndex = 2;
  7401. }
  7402. else
  7403. {
  7404. tempIndex = connectorIdInt -1;
  7405. }
  7406. for (int index = 0; index < AC_QUANTITY; index++)
  7407. {
  7408. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7409. {
  7410. 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))
  7411. {
  7412. //Reserved
  7413. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7414. }
  7415. 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))
  7416. {
  7417. //Reserved
  7418. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7419. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7420. goto end;
  7421. }
  7422. else
  7423. {
  7424. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7425. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7426. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7427. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7428. {
  7429. DEBUG_WARN("AC connector not allow start\n.");
  7430. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7431. goto end;
  7432. }
  7433. }//END FOR ELSE
  7434. }
  7435. }// END FOR AC_QUANTITY
  7436. }
  7437. if(chargingProfileIsNULL == FALSE)
  7438. {
  7439. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7440. {
  7441. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7442. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7443. //memset idTag
  7444. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7445. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7446. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7447. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7448. // Save profile to file
  7449. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7450. system(cmdBuf);
  7451. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7452. fp = fopen(cmdBuf, "w");
  7453. 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));
  7454. fclose(fp);
  7455. }
  7456. else
  7457. {
  7458. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7459. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7460. }
  7461. }
  7462. else
  7463. {
  7464. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7465. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7466. //memset idTag
  7467. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7468. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7469. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7470. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7471. }
  7472. }
  7473. else
  7474. {
  7475. DEBUG_WARN("Connector id over\n.");
  7476. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7477. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7478. }
  7479. end:
  7480. json_object_put(RemoteStartTransaction);
  7481. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7482. {
  7483. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7484. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7485. }
  7486. //OCPP send RemoteStartConfirmation by first.
  7487. sendRemoteStartConfirmation(uuid, comfirmstr);
  7488. return result;
  7489. }
  7490. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7491. {
  7492. mtrace();
  7493. int result = FAIL;
  7494. int match = FALSE;
  7495. int GunNO = 0;
  7496. int tempIndex = 0;
  7497. int transactionIdInt=0;
  7498. int transactionIdIsNULL= TRUE;
  7499. char comfirmstr[20];
  7500. json_object *RemoteStopTransaction;
  7501. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7502. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7503. if(server_pending == TRUE)
  7504. {
  7505. return 0;
  7506. }
  7507. RemoteStopTransaction = json_tokener_parse(payload);
  7508. if(!is_error(RemoteStopTransaction))
  7509. {
  7510. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7511. {
  7512. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7513. transactionIdIsNULL = FALSE;
  7514. }
  7515. }
  7516. json_object_put(RemoteStopTransaction);
  7517. if(transactionIdIsNULL == FALSE)
  7518. {
  7519. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7520. {
  7521. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7522. {
  7523. //check Transaction active
  7524. if(gunType[gun_index] == 'J')
  7525. {
  7526. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7527. {
  7528. tempIndex = ((gun_index==2) ? 1: 0);
  7529. }
  7530. else
  7531. {
  7532. tempIndex = gun_index;
  7533. }
  7534. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7535. {
  7536. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7537. {
  7538. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7539. {
  7540. match = TRUE;
  7541. GunNO = gun_index;
  7542. }
  7543. }
  7544. }// END FOR CHAdeMO_QUANTITY
  7545. }
  7546. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7547. {
  7548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7549. {
  7550. tempIndex = ((gun_index==2) ? 1: 0);
  7551. }
  7552. else
  7553. {
  7554. tempIndex = gun_index;
  7555. }
  7556. for (int index = 0; index < CCS_QUANTITY; index++)
  7557. {
  7558. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7559. {
  7560. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7561. {
  7562. match = TRUE;
  7563. GunNO = gun_index;
  7564. }
  7565. }
  7566. }// END FOR CCS_QUANTITY
  7567. }
  7568. else if(gunType[gun_index] == 'G')
  7569. {
  7570. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7571. {
  7572. tempIndex = ((gun_index==2) ? 1: 0);
  7573. }
  7574. else
  7575. {
  7576. tempIndex = gun_index;
  7577. }
  7578. for (int index = 0; index < GB_QUANTITY; index++)
  7579. {
  7580. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7581. {
  7582. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7583. {
  7584. match = TRUE;
  7585. GunNO = gun_index;
  7586. }
  7587. }
  7588. }// END FOR GB_QUANTITY
  7589. }
  7590. else if(gunType[gun_index] == 'O')
  7591. {
  7592. tempIndex = gun_index;
  7593. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7594. {
  7595. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7596. {
  7597. 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
  7598. {
  7599. match = TRUE;
  7600. GunNO = gun_index;
  7601. }
  7602. }
  7603. }// END FOR GB_QUANTITY
  7604. }
  7605. else
  7606. {
  7607. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7608. {
  7609. tempIndex = 2;
  7610. }
  7611. else
  7612. {
  7613. tempIndex = gun_index;
  7614. }
  7615. for (int index = 0; index < AC_QUANTITY; index++)
  7616. {
  7617. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7618. {
  7619. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7620. {
  7621. match = TRUE;
  7622. GunNO = gun_index;
  7623. }
  7624. }
  7625. }// END FOR CHAdeMO_QUANTITY
  7626. } // END FOR AC ELSE
  7627. }// CHECK IF ResponseTransactionId == transactionIdInt
  7628. }//END FOR
  7629. if( match == TRUE)
  7630. {
  7631. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7632. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7633. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7634. }
  7635. else
  7636. {
  7637. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7638. }
  7639. }
  7640. else
  7641. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7642. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7643. return result;
  7644. }
  7645. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7646. {
  7647. mtrace();
  7648. int result = FAIL;
  7649. int connectorIdInt=0, reservationIdInt=0;
  7650. int tempIndex = 0;
  7651. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7652. char comfirmstr[20]={0};
  7653. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7654. int c = 0;
  7655. char *loc;
  7656. //char *ptr;
  7657. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7658. strcpy(sstrtemp, stringtrimspace(payload));
  7659. //***(1)connectorId ****/
  7660. c=0;
  7661. loc = strstr(sstrtemp, "connectorId");
  7662. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7663. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7664. {
  7665. sstr[c] = loc[strlen("connectorId")+2+c];
  7666. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7667. c++;
  7668. }
  7669. sstr[c] = '\0';
  7670. connectorIdInt = atoi(sstr);
  7671. //***(2)expiryDate ****/
  7672. loc = strstr(sstrtemp, "expiryDate");
  7673. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7674. c = 0;
  7675. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7676. {
  7677. sstr[c] = loc[3+strlen("expiryDate")+c];
  7678. c++;
  7679. }
  7680. sstr[c] = '\0';
  7681. strcpy(expiryDatestr, sstr);
  7682. //***(3)idTag ****/
  7683. loc = strstr(sstrtemp, "idTag");
  7684. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7685. c = 0;
  7686. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7687. {
  7688. sstr[c] = loc[3+strlen("idTag")+c];
  7689. c++;
  7690. }
  7691. sstr[c] = '\0';
  7692. strcpy(idTagstr, sstr);
  7693. //***(4)parentIdTag ****/
  7694. loc = strstr(sstrtemp, "parentIdTag");
  7695. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7696. c = 0;
  7697. if(loc == NULL)
  7698. {
  7699. strcpy(parentIdTagstr, "");
  7700. }
  7701. else
  7702. {
  7703. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7704. {
  7705. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7706. c++;
  7707. }
  7708. sstr[c] = '\0';
  7709. strcpy(parentIdTagstr, sstr);
  7710. }
  7711. //***(5)reservationId ****/
  7712. c=0;
  7713. loc = strstr(sstrtemp, "reservationId");
  7714. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7715. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7716. {
  7717. sstr[c] = loc[strlen("reservationId")+2+c];
  7718. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7719. c++;
  7720. }
  7721. sstr[c] = '\0';
  7722. reservationIdInt = atoi(sstr);
  7723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7724. /*
  7725. enum SYSTEM_STATUS
  7726. {
  7727. SYS_MODE_BOOTING = 0,
  7728. SYS_MODE_IDLE = 1,
  7729. SYS_MODE_AUTHORIZING = 2,
  7730. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7731. SYS_MODE_REASSIGN = 4,
  7732. SYS_MODE_PREPARING = 5,
  7733. SYS_MODE_PREPARE_FOR_EV = 6,
  7734. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7735. SYS_MODE_CHARGING = 8,
  7736. SYS_MODE_TERMINATING = 9,
  7737. SYS_MODE_COMPLETE = 10,
  7738. SYS_MODE_ALARM = 11,
  7739. SYS_MODE_FAULT = 12,
  7740. SYS_MODE_RESERVATION = 13,
  7741. SYS_MODE_BOOKING = 14,
  7742. SYS_MODE_MAINTAIN = 15,
  7743. SYS_MODE_DEBUG = 16,
  7744. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7745. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7746. SYS_MODE_UPDATE = 19
  7747. };
  7748. */
  7749. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7750. {
  7751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7752. goto end;
  7753. }
  7754. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7755. {
  7756. //check Transaction active
  7757. if(gunType[connectorIdInt -1] == 'J')
  7758. {
  7759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7760. {
  7761. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7762. }
  7763. else
  7764. {
  7765. tempIndex = connectorIdInt -1;
  7766. }
  7767. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7768. {
  7769. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7770. {
  7771. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7772. {
  7773. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7774. {
  7775. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7776. {
  7777. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7778. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7779. }
  7780. 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'))
  7781. {
  7782. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7783. }
  7784. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7785. {
  7786. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7787. }
  7788. else
  7789. {
  7790. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7791. }
  7792. }
  7793. 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
  7794. {
  7795. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7796. }
  7797. }
  7798. else
  7799. {
  7800. //replace reservation
  7801. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7802. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7803. }
  7804. }
  7805. } // END FOR CHAdeMO_QUANTITY
  7806. }
  7807. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7808. {
  7809. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7810. {
  7811. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7812. }
  7813. else
  7814. {
  7815. tempIndex = connectorIdInt -1;
  7816. }
  7817. for (int index = 0; index < CCS_QUANTITY; index++)
  7818. {
  7819. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7820. {
  7821. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7822. {
  7823. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7824. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7825. {
  7826. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7827. {
  7828. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7830. }
  7831. 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'))
  7832. {
  7833. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7834. }
  7835. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7836. {
  7837. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7838. }
  7839. else
  7840. {
  7841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7842. }
  7843. }
  7844. 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
  7845. {
  7846. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7847. }
  7848. }
  7849. else
  7850. {
  7851. //replace reservation
  7852. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7853. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7854. }
  7855. }
  7856. } // END FOR CCS_QUANTITY
  7857. }
  7858. else if(gunType[connectorIdInt -1] == 'G')
  7859. {
  7860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7861. {
  7862. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7863. }
  7864. else
  7865. {
  7866. tempIndex = connectorIdInt -1;
  7867. }
  7868. for (int index = 0; index < GB_QUANTITY; index++)
  7869. {
  7870. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7871. {
  7872. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7873. {
  7874. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7875. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7876. {
  7877. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7878. {
  7879. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7881. }
  7882. 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'))
  7883. {
  7884. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7885. }
  7886. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7887. {
  7888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7889. }
  7890. else
  7891. {
  7892. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7893. }
  7894. }
  7895. 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
  7896. {
  7897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7898. }
  7899. }
  7900. else
  7901. {
  7902. //replace reservation
  7903. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7905. }
  7906. }
  7907. }// END FOR GB_QUANTITY
  7908. }
  7909. else if(gunType[connectorIdInt -1] == 'O')
  7910. {
  7911. tempIndex = connectorIdInt -1;
  7912. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7913. {
  7914. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7915. {
  7916. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  7917. {
  7918. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7919. 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
  7920. {
  7921. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7922. {
  7923. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7925. }
  7926. 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'))
  7927. {
  7928. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7929. }
  7930. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7931. {
  7932. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7933. }
  7934. else
  7935. {
  7936. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7937. }
  7938. }
  7939. 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
  7940. {
  7941. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7942. }
  7943. }
  7944. else
  7945. {
  7946. //replace reservation
  7947. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7949. }
  7950. }
  7951. }// END FOR GB_QUANTITY
  7952. }
  7953. else
  7954. {
  7955. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7956. {
  7957. tempIndex = 2;
  7958. }
  7959. else
  7960. {
  7961. tempIndex = (connectorIdInt -1);
  7962. }
  7963. for (int index = 0; index < AC_QUANTITY; index++)
  7964. {
  7965. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7966. {
  7967. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7968. {
  7969. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7970. {
  7971. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7972. {
  7973. 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))
  7974. {
  7975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7976. }
  7977. else
  7978. {
  7979. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7980. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7981. }
  7982. }
  7983. 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'))
  7984. {
  7985. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7986. }
  7987. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7988. {
  7989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7990. }
  7991. else
  7992. {
  7993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7994. }
  7995. }
  7996. 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
  7997. {
  7998. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7999. }
  8000. }
  8001. else
  8002. {
  8003. //replace reservation
  8004. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8006. }
  8007. }
  8008. } // END FOR AC_QUANTITY
  8009. }
  8010. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8011. }
  8012. else if(connectorIdInt == 0)
  8013. {
  8014. //check Transaction active
  8015. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8016. {
  8017. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8018. {
  8019. 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'))
  8020. {
  8021. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8022. goto end;
  8023. }
  8024. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8025. {
  8026. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8027. goto end;
  8028. }
  8029. 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
  8030. {
  8031. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8032. goto end;
  8033. }
  8034. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8035. {
  8036. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8037. goto end;
  8038. }
  8039. }
  8040. }// END FOR CHAdeMO_QUANTITY
  8041. for (int index = 0; index < CCS_QUANTITY; index++)
  8042. {
  8043. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8044. {
  8045. 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'))
  8046. {
  8047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8048. goto end;
  8049. }
  8050. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8051. {
  8052. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8053. goto end;
  8054. }
  8055. 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
  8056. {
  8057. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8058. goto end;
  8059. }
  8060. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8061. {
  8062. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8063. goto end;
  8064. }
  8065. }
  8066. } // END FOR CCS_QUANTITY
  8067. for (int index = 0; index < GB_QUANTITY; index++)
  8068. {
  8069. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8070. {
  8071. 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'))
  8072. {
  8073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8074. goto end;
  8075. }
  8076. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8077. {
  8078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8079. goto end;
  8080. }
  8081. 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
  8082. {
  8083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8084. goto end;
  8085. }
  8086. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8087. {
  8088. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8089. goto end;
  8090. }
  8091. }
  8092. } // END FOR GB_QUANTITY
  8093. for (int index = 0; index < AC_QUANTITY; index++)
  8094. {
  8095. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8096. {
  8097. 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'))
  8098. {
  8099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8100. goto end;
  8101. }
  8102. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8103. {
  8104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8105. goto end;
  8106. }
  8107. 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
  8108. {
  8109. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8110. goto end;
  8111. }
  8112. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8113. {
  8114. 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))
  8115. {
  8116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8117. goto end;
  8118. }
  8119. }
  8120. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8121. {
  8122. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8123. goto end;
  8124. }
  8125. }
  8126. }// END FOR AC_QUANTITY
  8127. //The connectorId is 0
  8128. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8130. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8131. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8132. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8133. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8134. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8135. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8136. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8137. result = TRUE;
  8138. return result;
  8139. }
  8140. else
  8141. {
  8142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8143. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8144. }
  8145. if(strcmp(comfirmstr,"Accepted") == 0)
  8146. {
  8147. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8148. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8149. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8150. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8151. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8152. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8153. result = TRUE;
  8154. return result;
  8155. }
  8156. end:
  8157. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8158. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8159. return result;
  8160. }
  8161. int handleResetRequest(char *uuid, char *payload)
  8162. {
  8163. mtrace();
  8164. int result = FAIL;
  8165. char sstr[10]={0},sstrtemp[30]={ 0 };
  8166. char typestr[10]={0};
  8167. char comfirmstr[20]={0};
  8168. int c = 0;
  8169. char *loc;
  8170. DEBUG_INFO("handleResetRequest...\n");
  8171. strcpy(sstrtemp, stringtrimspace(payload));
  8172. loc = strstr(sstrtemp, "type");
  8173. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8174. c = 0;
  8175. while (loc[3+strlen("type")+c] != '\"')
  8176. {
  8177. sstr[c] = loc[3+strlen("type")+c];
  8178. c++;
  8179. }
  8180. sstr[c] = '\0';
  8181. strcpy(typestr,sstr);
  8182. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8183. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8184. {
  8185. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8186. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8187. result = TRUE;
  8188. return result;
  8189. }
  8190. else
  8191. {
  8192. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8193. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8194. goto errorend;
  8195. }
  8196. errorend:
  8197. sendResetConfirmation(uuid, comfirmstr);
  8198. return result;
  8199. }
  8200. int handleSendLocalListRequest(char *uuid, char *payload)
  8201. {
  8202. mtrace();
  8203. int result = FAIL;
  8204. int listVersionInt;
  8205. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8206. char listsearch[]="listVersion";
  8207. char updateTypesearch[]="updateType";
  8208. char localAuthorizationListsearch[]="localAuthorizationList";
  8209. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8210. char CardList[500][160]={0};
  8211. char updateTypestr[15]={0};
  8212. char idTagstr[20]={0};
  8213. char parentIdTag[20]={0};
  8214. char expiryDate[30]={0};
  8215. char idTagstatus[16]={0};
  8216. int c = 0;
  8217. int i = 0;
  8218. char *delim1 = "}";
  8219. char * pch;
  8220. char *loc;
  8221. //char *ptr;
  8222. char comfirmstr[20];
  8223. //int n_localAuthorizations = 0;
  8224. int checkState_Faulted = FALSE;
  8225. DEBUG_INFO("handleSendLocalListRequest...\n");
  8226. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8227. {
  8228. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8229. goto end;
  8230. }
  8231. //check Charge Point state
  8232. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8233. {
  8234. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8235. {
  8236. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8237. }
  8238. }
  8239. for (int index = 0; index < CCS_QUANTITY; index++)
  8240. {
  8241. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8242. {
  8243. checkState_Faulted = TRUE; //OCPP Status
  8244. }
  8245. }
  8246. for (int index = 0; index < GB_QUANTITY; index++)
  8247. {
  8248. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8249. {
  8250. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8251. }
  8252. }
  8253. //check Charge Point state
  8254. for (int index = 0; index < AC_QUANTITY; index++)
  8255. {
  8256. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8257. {
  8258. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8259. }
  8260. }
  8261. if(checkState_Faulted == TRUE)
  8262. {
  8263. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8264. goto end;
  8265. }
  8266. //Filter payload space
  8267. strcpy(sstrtemp, stringtrimspace(payload));
  8268. //listVersion
  8269. c = 0;
  8270. loc = strstr(sstrtemp, listsearch);
  8271. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8272. {
  8273. sstr[c] = loc[strlen("listVersion")+2+c];
  8274. c++;
  8275. }
  8276. sstr[c] = '\0';
  8277. listVersionInt = atoi(sstr);
  8278. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8279. //updateType
  8280. loc = strstr(sstrtemp, updateTypesearch);
  8281. c = 0;
  8282. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8283. {
  8284. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8285. c++;
  8286. }
  8287. sstr[c] = '\0';
  8288. strcpy(updateTypestr, sstr);
  8289. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8290. //localAuthorizationList
  8291. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8292. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8293. if(loc != NULL) // localAuthorizationList is not NULL
  8294. {
  8295. //Check UpdateType
  8296. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8297. {
  8298. //Local list full update
  8299. printf("Local list full update.\n");
  8300. OCPP_getListVerion();
  8301. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8302. {
  8303. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8304. goto end;
  8305. }
  8306. OCPP_cleanLocalList();
  8307. }
  8308. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8309. {
  8310. //Local list different update
  8311. printf("Local list different update.\n");
  8312. OCPP_getListVerion();
  8313. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8314. {
  8315. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8316. goto end;
  8317. }
  8318. }
  8319. else
  8320. {
  8321. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8322. goto end;
  8323. }
  8324. c = 0;
  8325. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8326. {
  8327. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8328. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8329. c++;
  8330. }
  8331. sstr[c] = '\0';
  8332. //DEBUG_INFO("sstr=%s\n", sstr);
  8333. //parsing strings to words
  8334. i = 0;
  8335. pch = strtok(sstr,delim1);
  8336. while (pch != NULL)
  8337. {
  8338. strcpy(CardList[i], pch);
  8339. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8340. pch = strtok (NULL, delim1);
  8341. i = i + 1;
  8342. }
  8343. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8344. //local Authorizations List Numbers
  8345. //n_localAuthorizations = i;
  8346. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8347. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8348. c= 0;
  8349. while(c < i) // i is CardList Number
  8350. {
  8351. //Search "IdToken"
  8352. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8353. loc = strstr(CardList[c], "idTag");
  8354. int j = 0;
  8355. while (loc[3+strlen("idTag")+j] != '\"')
  8356. {
  8357. sstr[j] = loc[3+strlen("idTag")+j];
  8358. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8359. j++;
  8360. }
  8361. sstr[j] = '\0';
  8362. strcpy(idTagstr, sstr);
  8363. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8364. //Search "expiryDate"
  8365. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8366. loc = strstr(CardList[c], "expiryDate");
  8367. j = 0;
  8368. if(loc != NULL)
  8369. {
  8370. while (loc[3+strlen("expiryDate")+j] != '\"')
  8371. {
  8372. sstr[j] = loc[3+strlen("expiryDate")+j];
  8373. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8374. j++;
  8375. }
  8376. sstr[j] = '\0';
  8377. strcpy(expiryDate, sstr);
  8378. }
  8379. else
  8380. {
  8381. strcpy(expiryDate, "");
  8382. }
  8383. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8384. //Search "parentIdTag"
  8385. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8386. loc = strstr(CardList[c], "parentIdTag");
  8387. j = 0;
  8388. if(loc != NULL)
  8389. {
  8390. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8391. {
  8392. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8393. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8394. j++;
  8395. }
  8396. sstr[j] = '\0';
  8397. strcpy(parentIdTag, sstr);
  8398. }
  8399. else
  8400. {
  8401. strcpy(parentIdTag, "");
  8402. }
  8403. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8404. //Search "status"
  8405. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8406. loc = strstr(CardList[c], "status");
  8407. j = 0;
  8408. while (loc[3+strlen("status")+j] != '\"')
  8409. {
  8410. sstr[j] = loc[3+strlen("status")+j];
  8411. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8412. j++;
  8413. }
  8414. sstr[j] = '\0';
  8415. strcpy(idTagstatus, sstr);
  8416. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8417. OCPP_getIdTagFromLocalList(idTagstr);
  8418. //OCPP_getIdTagFromLocalList("test"); For Test
  8419. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8420. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8421. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8422. {
  8423. //Local list full update
  8424. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8425. // update list
  8426. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8427. //DEBUG_INFO("Local list full update. 1\n");
  8428. //OCPP_get_TableAuthlocalAllData();
  8429. //DEBUG_INFO("Local list full update. 2\n");
  8430. }
  8431. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8432. {
  8433. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8434. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8435. }
  8436. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8437. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8438. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8439. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8440. c++;
  8441. }
  8442. }
  8443. else
  8444. {
  8445. //Check UpdateType
  8446. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8447. {
  8448. //Local list full update
  8449. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8450. OCPP_cleanLocalList();
  8451. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8452. goto end;
  8453. }
  8454. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8455. {
  8456. //Local list different update
  8457. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8458. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8459. goto end;
  8460. }
  8461. }
  8462. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8463. end:
  8464. sendSendLocalListConfirmation(uuid, comfirmstr);
  8465. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8466. return result;
  8467. }
  8468. #define MAX 200
  8469. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8470. {
  8471. mtrace();
  8472. int result = FAIL;
  8473. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8474. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8475. char chargingProfilePurposeStr[30]={0};
  8476. char chargingProfileKindStr[16]={0};
  8477. char recurrencyKindStr[10]={0};
  8478. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8479. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8480. int chargingSchedulePeriodCount = 0;
  8481. char comfirmstr[20]={0};
  8482. int meet= FALSE;
  8483. FILE *fptr1;
  8484. char filename[MAX]={0};
  8485. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8486. char rmFileCmd[50]={0};
  8487. char tempchargingProfilePurposeStr[30]={0};
  8488. char word[1600]={0};
  8489. int n_chargingProfile = 0;
  8490. json_object *SetChargingProfile;
  8491. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8492. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8493. SetChargingProfile = json_tokener_parse(payload);
  8494. if(!is_error(SetChargingProfile))
  8495. {
  8496. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8497. {
  8498. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8499. if(connectorIdInt == 0)
  8500. {
  8501. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8502. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8503. }
  8504. else
  8505. {
  8506. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8507. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8508. }
  8509. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8510. }
  8511. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8512. {
  8513. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8514. {
  8515. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8516. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8517. {
  8518. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8519. }
  8520. else
  8521. {
  8522. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8523. }
  8524. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8525. }
  8526. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8527. {
  8528. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8529. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8530. {
  8531. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8532. }
  8533. else
  8534. {
  8535. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8536. }
  8537. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8538. }
  8539. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8540. {
  8541. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8542. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8543. {
  8544. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8545. }
  8546. else
  8547. {
  8548. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8549. }
  8550. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8551. }
  8552. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8553. {
  8554. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8555. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8556. {
  8557. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8558. }
  8559. else
  8560. {
  8561. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8562. }
  8563. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8564. }
  8565. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8566. {
  8567. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8568. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8569. {
  8570. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8571. }
  8572. else
  8573. {
  8574. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8575. }
  8576. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8577. }
  8578. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8579. {
  8580. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8581. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8582. {
  8583. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8584. }
  8585. else
  8586. {
  8587. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8588. }
  8589. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8590. }
  8591. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8592. {
  8593. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8594. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8595. {
  8596. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8597. }
  8598. else
  8599. {
  8600. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8601. }
  8602. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8603. }
  8604. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8605. {
  8606. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8607. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8608. {
  8609. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8610. }
  8611. else
  8612. {
  8613. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8614. }
  8615. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8616. }
  8617. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8618. {
  8619. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8620. {
  8621. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8622. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8623. {
  8624. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8625. }
  8626. else
  8627. {
  8628. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8629. }
  8630. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8631. }
  8632. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8633. {
  8634. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8635. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8636. {
  8637. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8638. }
  8639. else
  8640. {
  8641. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8642. }
  8643. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8644. }
  8645. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8646. {
  8647. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8648. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8649. {
  8650. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8651. }
  8652. else
  8653. {
  8654. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8655. }
  8656. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8657. }
  8658. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8659. {
  8660. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8661. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8662. {
  8663. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8664. }
  8665. else
  8666. {
  8667. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8668. }
  8669. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8670. }
  8671. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8672. {
  8673. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8674. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8675. if(chargingSchedulePeriodCount <= 10)
  8676. {
  8677. 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++)
  8678. {
  8679. 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)
  8680. {
  8681. 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"));
  8682. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8683. {
  8684. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8685. }
  8686. else
  8687. {
  8688. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8689. }
  8690. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8691. }
  8692. 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)
  8693. {
  8694. 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"));
  8695. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8696. {
  8697. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8698. }
  8699. else
  8700. {
  8701. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8702. }
  8703. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8704. }
  8705. 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)
  8706. {
  8707. 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"));
  8708. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8709. {
  8710. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8711. }
  8712. else
  8713. {
  8714. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8715. }
  8716. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8717. }
  8718. }
  8719. }
  8720. }
  8721. }
  8722. }
  8723. }
  8724. json_object_put(SetChargingProfile);
  8725. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8726. {
  8727. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8728. goto end;
  8729. }
  8730. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8731. {
  8732. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8733. if(connectorIdInt != 0)
  8734. {
  8735. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8736. goto end;
  8737. }
  8738. strcpy(filename, ChargePointMaxProfile_JSON );
  8739. fptr1 = fopen(filename, "r");
  8740. if (!fptr1)
  8741. {
  8742. //file not exist
  8743. DEBUG_INFO("Unable to open the input file!!\n");
  8744. fptr1 = fopen(filename, "w+");
  8745. }
  8746. else
  8747. {
  8748. //Check Charging Profile Count
  8749. while(fscanf(fptr1, "%s", word) != EOF)
  8750. {
  8751. //DEBUG_INFO("word=%s\n",word);
  8752. if(strstr(word, "chargingProfileId")!= NULL)
  8753. {
  8754. //DEBUG_INFO("test chargingProfileId \n");
  8755. n_chargingProfile = n_chargingProfile + 1;
  8756. //DEBUG_INFO("chargingProfileId Found\n");
  8757. }
  8758. }
  8759. }
  8760. fclose(fptr1);
  8761. }
  8762. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8763. {
  8764. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8765. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8766. {
  8767. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8768. goto end;
  8769. }
  8770. memset(filename, 0, ARRAY_SIZE(filename));
  8771. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8772. fptr1 = fopen(filename, "r");
  8773. if (!fptr1)
  8774. {
  8775. //file not exist
  8776. //DEBUG_INFO("Unable to open the input file!!\n");
  8777. fptr1 = fopen(filename, "w+");
  8778. }
  8779. else
  8780. {
  8781. //Check Charging Profile Count
  8782. while(fscanf(fptr1, "%s", word) != EOF)
  8783. {
  8784. //DEBUG_INFO("word=%s\n",word);
  8785. if(strstr(word, "chargingProfileId")!= NULL)
  8786. {
  8787. //DEBUG_INFO("test chargingProfileId \n");
  8788. n_chargingProfile = n_chargingProfile + 1;
  8789. //DEBUG_INFO("chargingProfileId Found\n");
  8790. }
  8791. }
  8792. }
  8793. fclose(fptr1);
  8794. }
  8795. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8796. {
  8797. //printf("set chargingProfile 1-4\n");
  8798. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8799. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8800. if(connectorIdInt == 0)
  8801. {
  8802. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8803. goto end;
  8804. }
  8805. int tempIndex = 0;
  8806. //check Transaction active
  8807. if(gunType[connectorIdInt -1] == 'J')
  8808. {
  8809. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8810. {
  8811. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8812. }
  8813. else
  8814. {
  8815. tempIndex = connectorIdInt -1;
  8816. }
  8817. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8818. {
  8819. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8820. {
  8821. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8822. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8823. {
  8824. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8825. {
  8826. meet = TRUE;
  8827. break;
  8828. }
  8829. }
  8830. }
  8831. }
  8832. }
  8833. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8834. {
  8835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8836. {
  8837. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8838. }
  8839. else
  8840. {
  8841. tempIndex = connectorIdInt -1;
  8842. }
  8843. for (int index = 0; index < CCS_QUANTITY; index++)
  8844. {
  8845. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8846. {
  8847. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8848. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8849. {
  8850. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8851. {
  8852. meet = TRUE;
  8853. break;
  8854. }
  8855. }
  8856. }
  8857. }
  8858. }
  8859. else if(gunType[connectorIdInt -1] == 'G')
  8860. {
  8861. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8862. {
  8863. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8864. }
  8865. else
  8866. {
  8867. tempIndex = connectorIdInt -1;
  8868. }
  8869. for (int index = 0; index < GB_QUANTITY; index++)
  8870. {
  8871. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8872. {
  8873. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8874. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8875. {
  8876. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8877. {
  8878. meet = TRUE;
  8879. break;
  8880. }
  8881. }
  8882. }
  8883. }
  8884. }
  8885. else if(gunType[connectorIdInt -1] == 'O')
  8886. {
  8887. tempIndex = connectorIdInt -1;
  8888. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8889. {
  8890. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8891. {
  8892. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8893. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8894. {
  8895. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8896. {
  8897. meet = TRUE;
  8898. break;
  8899. }
  8900. }
  8901. }
  8902. }
  8903. }
  8904. else
  8905. {
  8906. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8907. {
  8908. tempIndex = 2;
  8909. }
  8910. else
  8911. {
  8912. tempIndex = (connectorIdInt -1);
  8913. }
  8914. for (int index = 0; index < AC_QUANTITY; index++)
  8915. {
  8916. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8917. {
  8918. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8919. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8920. {
  8921. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8922. {
  8923. meet = TRUE;
  8924. break;
  8925. }
  8926. }
  8927. }
  8928. }
  8929. }
  8930. //check Transaction active
  8931. if(meet == FALSE)
  8932. {
  8933. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8934. goto end;
  8935. }
  8936. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8937. {
  8938. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8939. goto end;
  8940. }
  8941. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8942. fptr1 = fopen(filename, "r");
  8943. if (!fptr1)
  8944. {
  8945. //file not exist
  8946. DEBUG_INFO("Unable to open the input file!!\n");
  8947. fptr1 = fopen(filename, "w+");
  8948. }
  8949. else
  8950. {
  8951. //Check Charging Profile Count
  8952. while(fscanf(fptr1, "%s", word) != EOF)
  8953. {
  8954. //DEBUG_INFO("word=%s\n",word);
  8955. if(strstr(word, "chargingProfileId")!= NULL)
  8956. {
  8957. //DEBUG_INFO("test chargingProfileId \n");
  8958. n_chargingProfile = n_chargingProfile + 1;
  8959. //DEBUG_INFO("chargingProfileId Found\n");
  8960. }
  8961. }
  8962. }
  8963. fclose(fptr1);
  8964. }
  8965. // Check ChargeProfileMaxStackLevel
  8966. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8967. {
  8968. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8969. goto end;
  8970. }
  8971. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8972. {
  8973. int i = 0;
  8974. char fnametemp[200]={0};
  8975. n_chargingProfile = 0;
  8976. //Check ChargePointMaxProfile.json exit
  8977. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8978. {
  8979. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8980. //Check Charging Profile Count
  8981. while(fscanf(fptr1, "%s", word) != EOF)
  8982. {
  8983. //DEBUG_INFO("word=%s\n",word);
  8984. if(strstr(word, "chargingProfileId")!= NULL)
  8985. {
  8986. //DEBUG_INFO("test chargingProfileId \n");
  8987. n_chargingProfile = n_chargingProfile + 1;
  8988. i = i + 1;
  8989. //DEBUG_INFO("chargingProfileId Found\n");
  8990. }
  8991. memset(word, 0, ARRAY_SIZE(word));
  8992. }
  8993. fclose(fptr1);
  8994. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8995. }
  8996. //Check TxDefaultProfile_0.json exit
  8997. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8998. {
  8999. i = 0;
  9000. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9001. //Check Charging Profile Count
  9002. while(fscanf(fptr1, "%s", word) != EOF)
  9003. {
  9004. //DEBUG_INFO("word=%s\n",word);
  9005. if(strstr(word, "chargingProfileId")!= NULL)
  9006. {
  9007. //DEBUG_INFO("test chargingProfileId \n");
  9008. n_chargingProfile = n_chargingProfile + 1;
  9009. i = i + 1;
  9010. //DEBUG_INFO("chargingProfileId Found\n");
  9011. }
  9012. memset(word, 0, ARRAY_SIZE(word));
  9013. }
  9014. fclose(fptr1);
  9015. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9016. }
  9017. //Check TxDefaultProfile_%d.json
  9018. for(int j=1; j <= gunTotalNumber; j++)
  9019. {
  9020. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9021. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9022. if((access(fnametemp,F_OK))!=-1)
  9023. {
  9024. i = 0;
  9025. fptr1 = fopen(fnametemp, "r");
  9026. //Check Charging Profile Count
  9027. while(fscanf(fptr1, "%s", word) != EOF)
  9028. {
  9029. //DEBUG_INFO("word=%s\n",word);
  9030. if(strstr(word, "chargingProfileId")!= NULL)
  9031. {
  9032. //DEBUG_INFO("test chargingProfileId \n");
  9033. n_chargingProfile = n_chargingProfile + 1;
  9034. i = i + 1;
  9035. //DEBUG_INFO("chargingProfileId Found\n");
  9036. }
  9037. memset(word, 0, ARRAY_SIZE(word));
  9038. }
  9039. fclose(fptr1);
  9040. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9041. }
  9042. }
  9043. //Check TxProfile_%d.json
  9044. for(int j=1; j <= gunTotalNumber; j++)
  9045. {
  9046. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9047. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9048. if((access(fnametemp,F_OK))!=-1)
  9049. {
  9050. i = 0;
  9051. fptr1 = fopen(fnametemp, "r");
  9052. //Check Charging Profile Count
  9053. while(fscanf(fptr1, "%s", word) != EOF)
  9054. {
  9055. //DEBUG_INFO("word=%s\n",word);
  9056. if(strstr(word, "chargingProfileId")!= NULL)
  9057. {
  9058. //DEBUG_INFO("test chargingProfileId \n");
  9059. n_chargingProfile = n_chargingProfile + 1;
  9060. i = i + 1;
  9061. //DEBUG_INFO("chargingProfileId Found\n");
  9062. }
  9063. memset(word, 0, ARRAY_SIZE(word));
  9064. }
  9065. fclose(fptr1);
  9066. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9067. }
  9068. }
  9069. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9070. {
  9071. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9072. goto end;
  9073. }
  9074. }
  9075. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9076. //**********************************Write to File********************************************************/
  9077. FILE *infile;
  9078. FILE *outfile;
  9079. infile = fopen (filename, "r");
  9080. outfile = fopen (tempfile, "w");
  9081. int d =0;
  9082. d = fgetc(infile);
  9083. rewind(infile);
  9084. if(d == EOF)
  9085. {
  9086. // Profile is empty
  9087. fprintf(outfile,"%s\n",payload);
  9088. fclose(infile);
  9089. fclose(outfile);
  9090. sprintf(rmFileCmd,"rm -f %s",filename);
  9091. system(rmFileCmd);
  9092. rename(tempfile, filename);
  9093. }
  9094. else
  9095. {
  9096. // Profile is not empty
  9097. char buf[2048]={0};
  9098. int ChargingProfileAdded = FALSE;
  9099. while (fgets(buf, sizeof(buf), infile) != NULL)
  9100. {
  9101. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9102. json_object *tmpChargingProfile;
  9103. tmpChargingProfile = json_tokener_parse(buf);
  9104. if(!is_error(SetChargingProfile))
  9105. {
  9106. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9107. {
  9108. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9109. }
  9110. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9111. {
  9112. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9113. {
  9114. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9115. }
  9116. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9117. {
  9118. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9119. }
  9120. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9121. {
  9122. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9123. }
  9124. }
  9125. }
  9126. json_object_put(tmpChargingProfile);
  9127. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9128. {
  9129. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9130. {
  9131. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9132. if(ChargingProfileAdded == FALSE)
  9133. {
  9134. fprintf(outfile,"%s\n",payload);
  9135. ChargingProfileAdded = TRUE;
  9136. }
  9137. }
  9138. else
  9139. {
  9140. if(tempstackLevelInt < stackLevelInt)
  9141. {
  9142. if(ChargingProfileAdded == FALSE)
  9143. {
  9144. fprintf(outfile,"%s\n",buf);
  9145. fprintf(outfile,"%s\n",payload);
  9146. ChargingProfileAdded = TRUE;
  9147. }
  9148. else
  9149. {
  9150. fprintf(outfile,"%s\n",buf);
  9151. }
  9152. }
  9153. else
  9154. {
  9155. if(ChargingProfileAdded == FALSE)
  9156. {
  9157. fprintf(outfile,"%s\n",buf);
  9158. fprintf(outfile,"%s\n",payload);
  9159. ChargingProfileAdded = TRUE;
  9160. }
  9161. else
  9162. {
  9163. fprintf(outfile,"%s\n",buf);
  9164. }
  9165. }
  9166. }
  9167. }
  9168. else
  9169. {
  9170. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9171. {
  9172. if(ChargingProfileAdded == FALSE)
  9173. {
  9174. fprintf(outfile,"%s\n",buf);
  9175. fprintf(outfile,"%s\n",payload);
  9176. ChargingProfileAdded = TRUE;
  9177. }
  9178. else
  9179. {
  9180. fprintf(outfile,"%s\n",buf);
  9181. }
  9182. }
  9183. else if(tempstackLevelInt < stackLevelInt)
  9184. {
  9185. if(ChargingProfileAdded == FALSE)
  9186. {
  9187. fprintf(outfile,"%s\n",buf);
  9188. fprintf(outfile,"%s\n",payload);
  9189. ChargingProfileAdded = TRUE;
  9190. }
  9191. else
  9192. {
  9193. fprintf(outfile,"%s\n",buf);
  9194. }
  9195. }
  9196. else
  9197. {
  9198. if(ChargingProfileAdded == FALSE)
  9199. {
  9200. fprintf(outfile,"%s\n",buf);
  9201. fprintf(outfile,"%s\n",payload);
  9202. ChargingProfileAdded = TRUE;
  9203. }
  9204. else
  9205. {
  9206. fprintf(outfile,"%s\n",buf);
  9207. }
  9208. }
  9209. }
  9210. } // end of while loop
  9211. fclose(infile);
  9212. fclose(outfile);
  9213. sprintf(rmFileCmd,"rm -f %s",filename);
  9214. system(rmFileCmd);
  9215. rename(tempfile, filename);
  9216. }
  9217. sleep(1);
  9218. result = TRUE;
  9219. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9220. end:
  9221. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9222. {
  9223. if(connectorIdInt == 0)
  9224. {
  9225. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9226. {
  9227. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  9228. }
  9229. }
  9230. else
  9231. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  9232. }
  9233. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9234. return result;
  9235. }
  9236. int handleTriggerMessageRequest(char *uuid, char *payload)
  9237. {
  9238. mtrace();
  9239. int result = FAIL;
  9240. int connectorIdIsNULL = FALSE;
  9241. int connectorIdInt =0;
  9242. char sstr[40]={0},sstrtemp[100]={ 0 };
  9243. char requestedMessagestr[40]={0};
  9244. char comfirmstr[20]={0};
  9245. int c = 0;
  9246. char *loc;
  9247. DEBUG_INFO("handleTriggerMessageRequest\n");
  9248. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9249. strcpy(sstrtemp, stringtrimspace(payload));
  9250. c = 0;
  9251. loc = strstr(sstrtemp, "requestedMessage");
  9252. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9253. {
  9254. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9255. c++;
  9256. }
  9257. sstr[c] = '\0';
  9258. strcpy(requestedMessagestr, sstr);
  9259. c = 0;
  9260. loc = strstr(sstrtemp, "connectorId");
  9261. if(loc == NULL)
  9262. {
  9263. connectorIdIsNULL = TRUE;
  9264. }
  9265. else
  9266. {
  9267. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9268. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9269. {
  9270. sstr[c] = loc[strlen("connectorId")+2+c];
  9271. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9272. c++;
  9273. }
  9274. sstr[c] = '\0';
  9275. connectorIdInt = atoi(sstr);
  9276. }
  9277. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9278. {
  9279. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9280. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9281. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9282. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9283. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9284. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9285. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9286. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9287. {
  9288. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9289. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9290. return TRUE;
  9291. }
  9292. else
  9293. {
  9294. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9295. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9296. }
  9297. }
  9298. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9299. {
  9300. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9301. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9302. return TRUE;
  9303. }
  9304. //==========================
  9305. // Trigger message
  9306. //==========================
  9307. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9308. {
  9309. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9310. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9311. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9312. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9313. {
  9314. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9315. }
  9316. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9317. }
  9318. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9319. {
  9320. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9321. }
  9322. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9323. {
  9324. //sendBootNotificationRequest();
  9325. server_sign = FALSE;
  9326. }
  9327. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9328. {
  9329. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9330. }
  9331. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9332. {
  9333. if(connectorIdIsNULL == FALSE)
  9334. {
  9335. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9336. {
  9337. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9338. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9339. }
  9340. }
  9341. else
  9342. {
  9343. for(int idx=0;idx< gunTotalNumber;idx++)
  9344. {
  9345. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9346. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9347. }
  9348. }
  9349. }
  9350. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9351. {
  9352. if(connectorIdIsNULL == FALSE)
  9353. {
  9354. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9355. {
  9356. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9357. }
  9358. }
  9359. else
  9360. {
  9361. for(int idx=0;idx< gunTotalNumber;idx++)
  9362. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9363. }
  9364. }
  9365. return result;
  9366. }
  9367. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9368. {
  9369. mtrace();
  9370. int result = FAIL;
  9371. int connectorIdInt =0;
  9372. char comfirmstr[20]={0};
  9373. int tempIndex = 0;
  9374. json_object *UnlockConnector;
  9375. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9376. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9377. UnlockConnector = json_tokener_parse(payload);
  9378. if(!is_error(UnlockConnector))
  9379. {
  9380. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9381. {
  9382. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9383. }
  9384. }
  9385. json_object_put(UnlockConnector);
  9386. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9387. if(gunTotalNumber == 0)
  9388. {
  9389. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9390. goto end;
  9391. }
  9392. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9393. {
  9394. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9395. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9396. goto end;
  9397. }
  9398. else
  9399. {
  9400. //check Transaction active
  9401. if(gunType[connectorIdInt-1] == 'J')
  9402. {
  9403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9404. {
  9405. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9406. }
  9407. else
  9408. {
  9409. tempIndex = connectorIdInt -1;
  9410. }
  9411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9412. {
  9413. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9414. {
  9415. //stop Transaction
  9416. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9417. }
  9418. }
  9419. }
  9420. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9421. {
  9422. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9423. {
  9424. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9425. }
  9426. else
  9427. {
  9428. tempIndex = connectorIdInt -1;
  9429. }
  9430. for (int index = 0; index < CCS_QUANTITY; index++)
  9431. {
  9432. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9433. {
  9434. //stop Transaction
  9435. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9436. }
  9437. }
  9438. }
  9439. else if(gunType[connectorIdInt-1] == 'G')
  9440. {
  9441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9442. {
  9443. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9444. }
  9445. else
  9446. {
  9447. tempIndex = connectorIdInt -1;
  9448. }
  9449. for (int index = 0; index < GB_QUANTITY; index++)
  9450. {
  9451. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9452. {
  9453. //stop Transaction
  9454. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9455. }
  9456. }
  9457. }
  9458. else if(gunType[connectorIdInt-1] == 'O')
  9459. {
  9460. tempIndex = connectorIdInt -1;
  9461. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9462. {
  9463. 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)))
  9464. {
  9465. //stop Transaction
  9466. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9467. }
  9468. }
  9469. }
  9470. else
  9471. {
  9472. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9473. {
  9474. tempIndex = 2;
  9475. }
  9476. else
  9477. {
  9478. tempIndex = connectorIdInt-1;
  9479. }
  9480. for (int index = 0; index < AC_QUANTITY; index++)
  9481. {
  9482. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9483. {
  9484. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9485. }
  9486. }
  9487. }
  9488. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9489. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9490. result = TRUE;
  9491. return result;
  9492. }
  9493. end:
  9494. //json_object_put(obj); --- remove temporally
  9495. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9496. return result;
  9497. }
  9498. static char UpdateFirmwarepayloadData[300]={0};
  9499. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9500. {
  9501. mtrace();
  9502. int result = FAIL;
  9503. pthread_t t;
  9504. sendUpdateFirmwareConfirmation(uuid);
  9505. memset(UpdateFirmwarepayloadData, 0, 300);
  9506. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9507. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9508. ////pthread_join(t, NULL); //
  9509. //pthread_detach(t);
  9510. //sendUpdateFirmwareConfirmation(uuid);
  9511. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9512. return result;
  9513. }
  9514. void *UpdateFirmwareProcess(void *data)
  9515. {
  9516. pthread_detach(pthread_self());
  9517. mtrace();
  9518. int retriesInt =0, retryIntervalInt=0;
  9519. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9520. int port=0;
  9521. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9522. int isSuccess = 0;
  9523. char ftpbuf[200];
  9524. char temp[100];
  9525. char * pch;
  9526. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9527. json_object *UpdateFirmware;
  9528. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9529. if(!is_error(UpdateFirmware))
  9530. {
  9531. // Required data
  9532. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9533. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9534. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9535. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9536. // Optional data
  9537. if(json_object_object_get(UpdateFirmware, "retries"))
  9538. {
  9539. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9540. }
  9541. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9542. {
  9543. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9544. }
  9545. }
  9546. json_object_put(UpdateFirmware);
  9547. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9548. memset(path, 0, ARRAY_SIZE(path));
  9549. system("rm -f /mnt/*");
  9550. if(strncmp(locationstr,"http", 4) == 0)
  9551. {
  9552. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9553. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9554. // protocol, user, password, host, path);
  9555. sprintf(ftppath,"/%s", path);
  9556. DEBUG_INFO("locationstr: %s\n", locationstr);
  9557. DEBUG_INFO("protocol: %s\n",protocol);
  9558. DEBUG_INFO("host: %s\n",host);
  9559. DEBUG_INFO("path: %s\n",path);
  9560. DEBUG_INFO("ftppath: %s\n",ftppath);
  9561. int ftppathlen=strlen(ftppath);
  9562. int i=1;
  9563. char filenametemp[50];
  9564. while(i < ftppathlen)
  9565. {
  9566. int len=ftppathlen-i;
  9567. if(ftppath[len]== 47) // '/' ascll code: 47
  9568. {
  9569. DEBUG_INFO("compare '/' all right\n");
  9570. break;
  9571. }
  9572. i=i+1;
  9573. }
  9574. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9575. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9576. filenametemp[i+1] = 0;
  9577. do
  9578. {
  9579. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9580. sleep(3);
  9581. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9582. if(!isSuccess)
  9583. {
  9584. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9585. sleep(retryIntervalInt);
  9586. }
  9587. else
  9588. {
  9589. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9590. }
  9591. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9592. }
  9593. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9594. {
  9595. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9596. memset(temp, 0, ARRAY_SIZE(temp));
  9597. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9598. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9599. int ftppathlen=strlen(ftpbuf);
  9600. int i=1;
  9601. char filenametemp[50];
  9602. while(i < ftppathlen)
  9603. {
  9604. int len=ftppathlen-i;
  9605. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9606. {
  9607. DEBUG_INFO(" compare '/' all right\n");
  9608. break;
  9609. }
  9610. i=i+1;
  9611. }
  9612. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9613. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9614. filenametemp[i+1] = 0;
  9615. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9616. pch=strchr(temp,'@');
  9617. if(pch==NULL)
  9618. {
  9619. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9620. protocol, host, &port, path);
  9621. strcpy(user,"anonymous");
  9622. strcpy(password,"");
  9623. }
  9624. else
  9625. {
  9626. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9627. protocol, user, password, host, &port, path);
  9628. }
  9629. sscanf(host,"%[^/]%s",host1, path1);
  9630. sprintf(ftppath,"%s", path1);
  9631. //DEBUG_INFO("protocol =%s\n",protocol);
  9632. //DEBUG_INFO("user =%s\n",user);
  9633. //DEBUG_INFO("password =%s\n",password);
  9634. //DEBUG_INFO("host1 =%s\n",host1);
  9635. //DEBUG_INFO("port =%d\n",port);
  9636. //DEBUG_INFO("path1 =%s\n",path1);
  9637. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9638. //ftpFile(host, user, password, port, ftppath, fname);
  9639. //download firmware pthred
  9640. if(port == 0)
  9641. {
  9642. port = 21;
  9643. }
  9644. do
  9645. {
  9646. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9647. sleep(3);
  9648. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9649. if(!isSuccess)
  9650. {
  9651. //BulldogUtil.sleepMs(interval*1000);
  9652. DEBUG_INFO("Update firmware request and download file fail.\n");
  9653. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9654. sleep(retryIntervalInt);
  9655. }
  9656. else
  9657. {
  9658. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9659. }
  9660. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9661. }
  9662. else
  9663. {
  9664. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9665. }
  9666. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9667. pthread_exit(NULL);
  9668. }
  9669. //==========================================
  9670. // Handle server response routine
  9671. //==========================================
  9672. void handleAuthorizeResponse(char *payload, int gun_index)
  9673. {
  9674. mtrace();
  9675. char expiryDatestr[30]={0};
  9676. char parentIdTagstr[20]={0};
  9677. char statusstr[20]={0};
  9678. int expiryDateISNULL=FALSE;
  9679. int parentIdTagISNULL=FALSE;
  9680. DEBUG_INFO("handleAuthorizeResponse...\n");
  9681. json_object *Authorize;
  9682. Authorize = json_tokener_parse(payload);
  9683. if(!is_error(Authorize))
  9684. {
  9685. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9686. {
  9687. // Required data
  9688. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9689. // Optional data
  9690. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9691. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9692. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9693. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9694. }
  9695. }
  9696. json_object_put(Authorize);
  9697. if(expiryDateISNULL == FALSE)
  9698. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9699. if(parentIdTagISNULL == FALSE)
  9700. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9701. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9702. //Update idTag information to authorization cache if supproted
  9703. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9704. {
  9705. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  9706. }
  9707. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9708. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9709. authorizeRetryTimes = 0;
  9710. }
  9711. void handleBootNotificationResponse(char *payload, int gun_index)
  9712. {
  9713. mtrace();
  9714. char statusStr[12]={0};
  9715. char currentTimeStr[30]={0};
  9716. int intervalInt = 0;
  9717. struct tm tp;
  9718. char buf[28]={0};
  9719. char timebuf[50]={0};
  9720. DEBUG_INFO("handleBootNotificationResponse...\n");
  9721. json_object *BootNotification;
  9722. BootNotification = json_tokener_parse(payload);
  9723. if(!is_error(BootNotification))
  9724. {
  9725. // Required data
  9726. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9727. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9728. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9729. }
  9730. json_object_put(BootNotification);
  9731. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9732. BootNotificationInterval = intervalInt;
  9733. HeartBeatWaitTime = intervalInt;
  9734. //write back to ShmOCPP16Data->BootNotification
  9735. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9736. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9737. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9738. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9739. {
  9740. server_sign = TRUE;
  9741. server_pending =FALSE;
  9742. }
  9743. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9744. {
  9745. server_pending = TRUE;
  9746. }
  9747. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9748. tp.tm_isdst = -1;
  9749. //time_t utc = mktime(&tp);
  9750. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9751. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9752. sprintf(timebuf,"date -s '%s'",buf);
  9753. system(timebuf);
  9754. srand(time(NULL));
  9755. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9756. //==============================================
  9757. // RTC sync
  9758. //==============================================
  9759. system("/sbin/hwclock -w --systohc");
  9760. SetOcppConnStatus(TRUE);
  9761. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9762. }
  9763. void handleDataTransferResponse(char *payload, int gun_index)
  9764. {
  9765. char sstr[160]={0};//sstr[200]={ 0 };
  9766. int c = 0;
  9767. char *loc;
  9768. DEBUG_INFO("handleDataTransferResponse ...\n");
  9769. loc = strstr(payload, "status");
  9770. printf("loc=%s\n",loc);
  9771. c = 0;
  9772. while (loc[3+strlen("status")+c] != '\"')
  9773. {
  9774. sstr[c] = loc[3+strlen("status")+c];
  9775. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9776. c++;
  9777. }
  9778. sstr[c] = '\0';
  9779. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9780. }
  9781. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9782. {
  9783. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9784. //struct json_object *obj;
  9785. // obj = json_tokener_parse(payload);
  9786. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9787. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9788. //No fields are defined.
  9789. }
  9790. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9791. {
  9792. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9793. //struct json_object *obj;
  9794. // obj = json_tokener_parse(payload);
  9795. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9796. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9797. //No fields are defined.
  9798. }
  9799. void handleHeartbeatResponse(char *payload, int gun_index)
  9800. {
  9801. mtrace();
  9802. struct tm tp;
  9803. char buf[28]={0};
  9804. char timebuf[50]={0};
  9805. DEBUG_INFO("handleHeartbeatResponse...\n");
  9806. json_object *Heartbeat;
  9807. Heartbeat = json_tokener_parse(payload);
  9808. if(!is_error(Heartbeat))
  9809. {
  9810. // Required data
  9811. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9812. }
  9813. json_object_put(Heartbeat);
  9814. if(FirstHeartBeat == 0)
  9815. {
  9816. FirstHeartBeat = 1;
  9817. DEBUG_INFO("FirstHeartBeat \n");
  9818. }
  9819. HeartBeatWithNOResponse = 0;
  9820. clientTime.Heartbeat=time((time_t*)NULL);
  9821. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9822. tp.tm_isdst = -1;
  9823. //time_t utc = mktime(&tp);
  9824. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9825. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9826. sprintf(timebuf,"date -s '%s'",buf);
  9827. system(timebuf);
  9828. //==============================================
  9829. // RTC sync
  9830. //==============================================
  9831. system("/sbin/hwclock -w --systohc");
  9832. }
  9833. void handleMeterValuesResponse(char *payload, int gun_index)
  9834. {
  9835. mtrace();
  9836. DEBUG_INFO("handleMeterValuesResponse...\n");
  9837. }
  9838. void handleStartTransactionResponse(char *payload, int gun_index)
  9839. {
  9840. mtrace();
  9841. //int transactionIdInt = 0;
  9842. FILE *outfile;
  9843. char data[100]={0};
  9844. DEBUG_INFO("handleStartTransactionResponse...\n");
  9845. json_object *StartTransaction;
  9846. StartTransaction = json_tokener_parse(payload);
  9847. if(!is_error(StartTransaction))
  9848. {
  9849. // Required data
  9850. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9851. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9852. // Optional data
  9853. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9854. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9855. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9856. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9857. }
  9858. json_object_put(StartTransaction);
  9859. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9860. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9861. //-----------Start : write to the Queue TransactionId file -----------------//
  9862. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9863. {}
  9864. else
  9865. {
  9866. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9867. if(log == NULL)
  9868. {
  9869. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9870. return ;
  9871. }
  9872. else
  9873. {
  9874. fclose(log);
  9875. }
  9876. }
  9877. // open file for writing
  9878. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9879. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9880. {
  9881. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9882. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9883. fputs(data, outfile);
  9884. fclose (outfile);
  9885. }
  9886. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9887. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9888. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9889. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9890. }
  9891. void handleStatusNotificationResponse(char *payload, int gun_index)
  9892. {
  9893. mtrace();
  9894. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9895. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9896. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9897. }
  9898. void handleStopTransactionnResponse(char *payload, int gun_index)
  9899. {
  9900. mtrace();
  9901. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9902. json_object *StopTransaction;
  9903. StopTransaction = json_tokener_parse(payload);
  9904. if(!is_error(StopTransaction))
  9905. {
  9906. // Optional data
  9907. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9908. {
  9909. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9910. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9911. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9912. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9913. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9914. }
  9915. }
  9916. json_object_put(StopTransaction);
  9917. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9918. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9919. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9920. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9921. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9922. }
  9923. //==========================================
  9924. // Handle Error routine
  9925. //==========================================
  9926. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9927. {
  9928. mtrace();
  9929. #ifdef SystemLogMessage
  9930. DEBUG_INFO("errorCode: %s\n", errorCode);
  9931. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9932. DEBUG_INFO("errorDetails: %s\n", payload);
  9933. #endif
  9934. }
  9935. //===============================================
  9936. // Common routine
  9937. //===============================================
  9938. int initialConfigurationTable(void)
  9939. {
  9940. //clock_t start_t, end_t, total_t;
  9941. FILE *fp;
  9942. FILE *outfile;
  9943. char str[200]={0};
  9944. char sstr[100]={0};
  9945. int c = 0;
  9946. char *loc;
  9947. DEBUG_INFO("initialConfigurationTable...\n");
  9948. //start_t = clock();
  9949. //printf("Starting of the program, start_t = %ld\n", start_t);
  9950. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9951. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9952. {
  9953. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9954. if(outfile == NULL)
  9955. {
  9956. DEBUG_INFO("Error opening file\n");
  9957. return FALSE;
  9958. }
  9959. /*Core Profile*/
  9960. //AllowOfflineTxForUnknownId
  9961. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9965. //AuthorizationCacheEnabled
  9966. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9970. //AuthorizeRemoteTxRequests
  9971. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9975. //BlinkRepeat
  9976. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9980. //ClockAlignedDataInterval
  9981. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9985. //ConnectionTimeOut
  9986. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9990. //GetConfigurationMaxKeys
  9991. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  9994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9995. // HeartbeatInterval
  9996. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  9999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10000. // LightIntensity
  10001. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10005. // LocalAuthorizeOffline
  10006. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10010. // LocalPreAuthorize
  10011. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10015. // MaxEnergyOnInvalidId
  10016. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10019. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10021. // MeterValuesAlignedData
  10022. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10026. else
  10027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10029. // MeterValuesAlignedDataMaxLength
  10030. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10032. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10034. else
  10035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10037. // MeterValuesSampledData
  10038. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10040. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10042. else
  10043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10045. // MeterValuesSampledDataMaxLength
  10046. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10048. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10050. else
  10051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10053. // MeterValueSampleInterval
  10054. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10058. // MinimumStatusDuration
  10059. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10062. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10064. // NumberOfConnectors
  10065. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10068. {
  10069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10070. }
  10071. else
  10072. {
  10073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10074. }
  10075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10076. // ResetRetries
  10077. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10081. // ConnectorPhaseRotation
  10082. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10086. // ConnectorPhaseRotationMaxLength
  10087. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10091. // StopTransactionOnEVSideDisconnect
  10092. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10096. // StopTransactionOnInvalidId
  10097. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10101. // StopTxnAlignedData
  10102. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10106. // StopTxnAlignedDataMaxLength
  10107. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10111. // StopTxnSampledData
  10112. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10114. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10116. else
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10119. // StopTxnSampledDataMaxLength
  10120. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10123. {
  10124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10125. }
  10126. else
  10127. {
  10128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10129. }
  10130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10131. // SupportedFeatureProfiles
  10132. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10136. // SupportedFeatureProfilesMaxLength
  10137. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10141. // TransactionMessageAttempts
  10142. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10145. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10147. // TransactionMessageRetryInterval
  10148. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10151. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10153. // UnlockConnectorOnEVSideDisconnect
  10154. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10158. // WebSocketPingInterval
  10159. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10163. // QueueOffLineStartTransactionMessage
  10164. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10168. // AuthorizationKey
  10169. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10173. // SecurityProfile
  10174. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10178. // DefaultPrice
  10179. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10183. // CustomDisplayCostAndPrice
  10184. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10188. // CustomIdleFeeAfterStop
  10189. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10193. //* Local Auth List Management Profile*/
  10194. #if 0
  10195. //For OCTT Test Case
  10196. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10199. #endif
  10200. #if 1
  10201. //LocalAuthListEnabled
  10202. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10206. #endif
  10207. //LocalAuthListMaxLength
  10208. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10212. //SendLocalListMaxLength
  10213. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10217. //ReserveConnectorZeroSupported
  10218. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10222. //* Smart Charging Profile */
  10223. //ChargeProfileMaxStackLevel
  10224. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10228. // ChargingScheduleAllowedChargingRateUnit
  10229. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10233. // ChargingScheduleMaxPeriods
  10234. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10238. // ConnectorSwitch3to1PhaseSupported
  10239. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10243. // MaxChargingProfilesInstalled
  10244. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10248. fclose(outfile);
  10249. }
  10250. else
  10251. {
  10252. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10253. char keystr[60]={0};
  10254. char readonlystr[10]={0};
  10255. char valuestr[100]={0};
  10256. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10257. if(fp == NULL) {
  10258. DEBUG_INFO("Error opening file");
  10259. return FALSE;
  10260. }
  10261. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10262. {
  10263. //DEBUG_INFO("Get Configuration \n");
  10264. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10265. //*************************key*********************************/
  10266. loc = strstr(str, "key");
  10267. c = 0;
  10268. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10269. while (loc[strlen("key")+3+c] != '\"')
  10270. {
  10271. sstr[c] = loc[strlen("key")+3+c];
  10272. c++;
  10273. }
  10274. sstr[c] = '\0';
  10275. strcpy(keystr,sstr);
  10276. //*************************readonly*********************************/
  10277. loc = strstr(str, "readonly");
  10278. c = 0;
  10279. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10280. while (loc[strlen("readonly")+2+c] != ',')
  10281. {
  10282. sstr[c] = loc[strlen("readonly")+2+c];
  10283. c++;
  10284. }
  10285. sstr[c] = '\0';
  10286. strcpy(readonlystr,sstr);
  10287. //*************************value*********************************/
  10288. loc = strstr(str, "value");
  10289. c = 0;
  10290. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10291. while (loc[strlen("value")+3+c] != '\"')
  10292. {
  10293. sstr[c] = loc[strlen("value")+3+c];
  10294. c++;
  10295. }
  10296. sstr[c] = '\0';
  10297. strcpy(valuestr,sstr);
  10298. // DEBUG_INFO("keystr=%s\n",keystr);
  10299. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10300. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10301. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10302. {
  10303. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10304. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10306. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10307. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10308. }
  10309. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10310. {
  10311. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10312. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10314. }
  10315. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10316. {
  10317. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10319. }
  10320. if(strcmp(keystr, "BlinkRepeat") == 0)
  10321. {
  10322. //Charger.BlinkRepeat = Integer.parseInt(value);
  10323. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10325. }
  10326. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10327. {
  10328. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10330. }
  10331. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10332. {
  10333. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10335. }
  10336. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10337. {
  10338. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10340. }
  10341. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10342. {
  10343. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10345. HeartBeatWaitTime = atoi(valuestr);
  10346. }
  10347. if(strcmp(keystr, "LightIntensity") == 0)
  10348. {
  10349. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10351. }
  10352. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10353. {
  10354. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10356. }
  10357. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10358. {
  10359. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10361. }
  10362. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10363. {
  10364. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10366. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10367. }
  10368. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10369. {
  10370. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10372. }
  10373. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10374. {
  10375. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10377. }
  10378. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10379. {
  10380. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10382. }
  10383. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10384. {
  10385. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10387. }
  10388. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10389. {
  10390. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10392. }
  10393. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10394. {
  10395. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10397. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10398. }
  10399. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10400. {
  10401. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10403. }
  10404. if(strcmp(keystr, "ResetRetries") == 0)
  10405. {
  10406. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10408. }
  10409. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10410. {
  10411. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10413. }
  10414. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10415. {
  10416. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10418. }
  10419. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10420. {
  10421. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10423. }
  10424. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10425. {
  10426. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10428. }
  10429. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10430. {
  10431. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10433. }
  10434. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10435. {
  10436. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10438. }
  10439. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10440. {
  10441. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10443. }
  10444. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10445. {
  10446. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10448. }
  10449. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10450. {
  10451. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10453. }
  10454. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10455. {
  10456. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10458. }
  10459. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10460. {
  10461. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10463. TransactionMessageAttemptsValue = atoi(valuestr);
  10464. }
  10465. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10466. {
  10467. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10469. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10470. }
  10471. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10472. {
  10473. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10475. }
  10476. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10477. {
  10478. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10480. }
  10481. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10482. {
  10483. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10485. }
  10486. if(strcmp(keystr, "AuthorizationKey") == 0)
  10487. {
  10488. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10490. }
  10491. if(strcmp(keystr, "SecurityProfile") == 0)
  10492. {
  10493. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10495. }
  10496. if(strcmp(keystr, "DefaultPrice") == 0)
  10497. {
  10498. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10500. }
  10501. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10502. {
  10503. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10505. }
  10506. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10507. {
  10508. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10510. }
  10511. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10512. {
  10513. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10515. }
  10516. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10517. {
  10518. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10520. }
  10521. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10522. {
  10523. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10525. }
  10526. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10527. {
  10528. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10530. }
  10531. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10532. {
  10533. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10535. }
  10536. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10537. {
  10538. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10540. }
  10541. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10542. {
  10543. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10545. }
  10546. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10547. {
  10548. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10550. }
  10551. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10552. {
  10553. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10555. }
  10556. }
  10557. fclose(fp);
  10558. }
  10559. return 0;
  10560. }
  10561. void StoreConfigurationTable(void)
  10562. {
  10563. FILE *outfile;
  10564. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10565. if(outfile == NULL)
  10566. {
  10567. DEBUG_INFO("Error opening file");
  10568. return ;
  10569. }
  10570. /*Core Profile*/
  10571. //AllowOfflineTxForUnknownId
  10572. /*
  10573. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10574. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10577. */
  10578. //DEBUG_INFO("data=%s\n",data);
  10579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10580. //AuthorizationCacheEnabled
  10581. /*
  10582. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10585. */
  10586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10587. //AuthorizeRemoteTxRequests
  10588. /*
  10589. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10592. */
  10593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10594. //BlinkRepeat
  10595. /*
  10596. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10599. */
  10600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10601. //ClockAlignedDataInterval
  10602. /*
  10603. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10606. */
  10607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10608. //ConnectionTimeOut
  10609. /*
  10610. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10613. */
  10614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10615. //GetConfigurationMaxKeys
  10616. /*
  10617. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10620. */
  10621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10622. // HeartbeatInterval
  10623. /*
  10624. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10627. */
  10628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10629. // LightIntensity
  10630. /*
  10631. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10634. */
  10635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10636. // LocalAuthorizeOffline
  10637. /*
  10638. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10641. */
  10642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10643. // LocalPreAuthorize
  10644. /*
  10645. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10648. */
  10649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10650. // MaxEnergyOnInvalidId
  10651. /*
  10652. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10655. */
  10656. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10658. // MeterValuesAlignedData
  10659. /*
  10660. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10663. */
  10664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10665. // MeterValuesAlignedDataMaxLength
  10666. /*
  10667. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10670. */
  10671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10672. // MeterValuesSampledData
  10673. /*
  10674. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10677. */
  10678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10679. // MeterValuesSampledDataMaxLength
  10680. /*
  10681. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10684. */
  10685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10686. // MeterValueSampleInterval
  10687. /*
  10688. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10691. */
  10692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10693. // MinimumStatusDuration
  10694. /*
  10695. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10698. */
  10699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10700. // NumberOfConnectors
  10701. /*
  10702. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10704. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10705. {
  10706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10707. }
  10708. else
  10709. {
  10710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10711. }
  10712. */
  10713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10714. // ResetRetries
  10715. /*
  10716. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10719. */
  10720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10721. // ConnectorPhaseRotation
  10722. /*
  10723. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10726. */
  10727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10728. // ConnectorPhaseRotationMaxLength
  10729. /*
  10730. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10733. */
  10734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10735. // StopTransactionOnEVSideDisconnect
  10736. /*
  10737. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10740. */
  10741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10742. // StopTransactionOnInvalidId
  10743. /*
  10744. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10747. */
  10748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10749. // StopTxnAlignedData
  10750. /*
  10751. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10754. */
  10755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10756. // StopTxnAlignedDataMaxLength
  10757. /*
  10758. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10761. */
  10762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10763. // StopTxnSampledData
  10764. /*
  10765. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10768. */
  10769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10770. // StopTxnSampledDataMaxLength
  10771. /*
  10772. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10775. */
  10776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10777. // SupportedFeatureProfiles
  10778. /*
  10779. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10782. */
  10783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10784. // SupportedFeatureProfilesMaxLength
  10785. /*
  10786. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10789. */
  10790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10791. // TransactionMessageAttempts
  10792. /*
  10793. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10796. */
  10797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10798. // TransactionMessageRetryInterval
  10799. /*
  10800. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10803. */
  10804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10805. // UnlockConnectorOnEVSideDisconnect
  10806. /*
  10807. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10810. */
  10811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10812. // WebSocketPingInterval
  10813. /*
  10814. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10817. */
  10818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10819. // QueueOffLineStartTransactionMessage
  10820. /*
  10821. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10824. */
  10825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10826. // AuthorizationKey
  10827. /*
  10828. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10831. */
  10832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10833. // SecurityProfile
  10834. /*
  10835. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10838. */
  10839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10840. // DefaultPrice
  10841. /*
  10842. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10845. */
  10846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10847. // CustomDisplayCostAndPrice
  10848. /*
  10849. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10852. */
  10853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10854. // CustomIdleFeeAfterStop
  10855. /*
  10856. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10859. */
  10860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10861. //* Local Auth List Management Profile*/
  10862. //LocalAuthListEnabled
  10863. /*
  10864. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10867. */
  10868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10869. //LocalAuthListMaxLength
  10870. /*
  10871. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10874. */
  10875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10876. //SendLocalListMaxLength
  10877. /*
  10878. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10881. */
  10882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10883. //ReserveConnectorZeroSupported
  10884. /*
  10885. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10888. */
  10889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10890. //* Smart Charging Profile */
  10891. //ChargeProfileMaxStackLevel
  10892. /*
  10893. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10896. */
  10897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10898. // ChargingScheduleAllowedChargingRateUnit
  10899. /*
  10900. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10903. */
  10904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10905. // ChargingScheduleMaxPeriods
  10906. /*
  10907. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10910. */
  10911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10912. // ConnectorSwitch3to1PhaseSupported
  10913. /*
  10914. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10917. */
  10918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10919. // MaxChargingProfilesInstalled
  10920. /*
  10921. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10924. */
  10925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10926. fclose(outfile);
  10927. }
  10928. void getKeyValue(char *keyReq)
  10929. {
  10930. int isEmpty = FALSE;
  10931. int isKnowKey = FALSE;
  10932. DEBUG_INFO("keyReq = %s\n", keyReq);
  10933. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10934. isEmpty = TRUE;
  10935. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10936. {
  10937. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10940. {
  10941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10942. }
  10943. else
  10944. {
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10946. }
  10947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10948. isKnowKey = TRUE;
  10949. }
  10950. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10951. {
  10952. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10955. {
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10957. }
  10958. else
  10959. {
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10961. }
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10963. isKnowKey = TRUE;
  10964. }
  10965. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10966. {
  10967. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10970. {
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10972. }
  10973. else
  10974. {
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10976. }
  10977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10978. isKnowKey = TRUE;
  10979. }
  10980. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10981. {
  10982. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10985. {
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10987. }
  10988. else
  10989. {
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10991. }
  10992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10993. isKnowKey = TRUE;
  10994. }
  10995. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10996. {
  10997. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11000. {
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11002. }
  11003. else
  11004. {
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11006. }
  11007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11008. isKnowKey = TRUE;
  11009. }
  11010. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11011. {
  11012. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11015. {
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11017. }
  11018. else
  11019. {
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11021. }
  11022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11023. isKnowKey = TRUE;
  11024. }
  11025. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11026. {
  11027. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11030. {
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11032. }
  11033. else
  11034. {
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11036. }
  11037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11038. isKnowKey = TRUE;
  11039. }
  11040. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11041. {
  11042. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11045. {
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11047. }
  11048. else
  11049. {
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11051. }
  11052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11053. isKnowKey = TRUE;
  11054. }
  11055. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11056. {
  11057. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11059. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11060. {
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11062. }
  11063. else
  11064. {
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11066. }
  11067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11068. isKnowKey = TRUE;
  11069. }
  11070. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11071. {
  11072. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11074. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11075. {
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11077. }
  11078. else
  11079. {
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11081. }
  11082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11083. isKnowKey = TRUE;
  11084. }
  11085. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11086. {
  11087. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11090. {
  11091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11092. }
  11093. else
  11094. {
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11096. }
  11097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11098. isKnowKey = TRUE;
  11099. }
  11100. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11101. {
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11104. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11105. {
  11106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11107. }
  11108. else
  11109. {
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11111. }
  11112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11113. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11114. isKnowKey = TRUE;
  11115. }
  11116. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11117. {
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11121. {
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11123. }
  11124. else
  11125. {
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11127. }
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11129. isKnowKey = TRUE;
  11130. }
  11131. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11132. {
  11133. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11136. {
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11138. }
  11139. else
  11140. {
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11142. }
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11144. isKnowKey = TRUE;
  11145. }
  11146. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11147. {
  11148. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11151. {
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11153. }
  11154. else
  11155. {
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11157. }
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11159. isKnowKey = TRUE;
  11160. }
  11161. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11162. {
  11163. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11166. {
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11168. }
  11169. else
  11170. {
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11172. }
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11174. isKnowKey = TRUE;
  11175. }
  11176. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11177. {
  11178. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11181. {
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11183. }
  11184. else
  11185. {
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11187. }
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11189. isKnowKey = TRUE;
  11190. }
  11191. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11192. {
  11193. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11196. {
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11198. }
  11199. else
  11200. {
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11202. }
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11204. isKnowKey = TRUE;
  11205. }
  11206. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11207. {
  11208. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11211. {
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11213. }
  11214. else
  11215. {
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11217. }
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11219. isKnowKey = TRUE;
  11220. }
  11221. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11222. {
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11226. {
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11228. }
  11229. else
  11230. {
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11232. }
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11234. isKnowKey = TRUE;
  11235. }
  11236. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11237. {
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11241. {
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11243. }
  11244. else
  11245. {
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11247. }
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11249. isKnowKey = TRUE;
  11250. }
  11251. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11252. {
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11256. {
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11258. }
  11259. else
  11260. {
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11262. }
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11264. isKnowKey = TRUE;
  11265. }
  11266. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11267. {
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11271. {
  11272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11273. }
  11274. else
  11275. {
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11277. }
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11279. isKnowKey = TRUE;
  11280. }
  11281. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11282. {
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11286. {
  11287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11288. }
  11289. else
  11290. {
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11292. }
  11293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11294. isKnowKey = TRUE;
  11295. }
  11296. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11297. {
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11301. {
  11302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11303. }
  11304. else
  11305. {
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11307. }
  11308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11309. isKnowKey = TRUE;
  11310. }
  11311. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11312. {
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11316. {
  11317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11318. }
  11319. else
  11320. {
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11322. }
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11324. isKnowKey = TRUE;
  11325. }
  11326. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11327. {
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11331. {
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11333. }
  11334. else
  11335. {
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11337. }
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11339. isKnowKey = TRUE;
  11340. }
  11341. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11342. {
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11346. {
  11347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11348. }
  11349. else
  11350. {
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11352. }
  11353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11354. isKnowKey = TRUE;
  11355. }
  11356. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11357. {
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11361. {
  11362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11363. }
  11364. else
  11365. {
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11367. }
  11368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11369. isKnowKey = TRUE;
  11370. }
  11371. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11372. {
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11376. {
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11378. }
  11379. else
  11380. {
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11382. }
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11384. isKnowKey = TRUE;
  11385. }
  11386. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11387. {
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11391. {
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11393. }
  11394. else
  11395. {
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11397. }
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11399. isKnowKey = TRUE;
  11400. }
  11401. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11402. {
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11406. {
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11408. }
  11409. else
  11410. {
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11412. }
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11414. isKnowKey = TRUE;
  11415. }
  11416. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11417. {
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11421. {
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11423. }
  11424. else
  11425. {
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11427. }
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11429. isKnowKey = TRUE;
  11430. }
  11431. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11432. {
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11436. {
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11438. }
  11439. else
  11440. {
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11442. }
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11444. isKnowKey = TRUE;
  11445. }
  11446. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11447. {
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11451. {
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11453. }
  11454. else
  11455. {
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11457. }
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11459. isKnowKey = TRUE;
  11460. }
  11461. /*
  11462. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11463. {
  11464. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11466. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11467. {
  11468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11469. }
  11470. else
  11471. {
  11472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11473. }
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11475. isKnowKey = TRUE;
  11476. }*/
  11477. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11478. {
  11479. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11482. {
  11483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11484. }
  11485. else
  11486. {
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11488. }
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11490. isKnowKey = TRUE;
  11491. }
  11492. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11493. {
  11494. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11497. {
  11498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11499. }
  11500. else
  11501. {
  11502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11503. }
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11505. isKnowKey = TRUE;
  11506. }
  11507. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11508. {
  11509. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11511. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11512. {
  11513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11514. }
  11515. else
  11516. {
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11518. }
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11520. isKnowKey = TRUE;
  11521. }
  11522. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11523. {
  11524. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11527. {
  11528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11529. }
  11530. else
  11531. {
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11533. }
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11535. isKnowKey = TRUE;
  11536. }
  11537. #if 1
  11538. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11539. {
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11542. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11543. {
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11545. }
  11546. else
  11547. {
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11549. }
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11551. isKnowKey = TRUE;
  11552. }
  11553. #endif
  11554. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11555. {
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11558. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11561. }
  11562. else
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11565. }
  11566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11567. isKnowKey = TRUE;
  11568. }
  11569. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11570. {
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11573. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11574. {
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11576. }
  11577. else
  11578. {
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11580. }
  11581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11582. isKnowKey = TRUE;
  11583. }
  11584. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11585. {
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11588. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11589. {
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11591. }
  11592. else
  11593. {
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11595. }
  11596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11597. isKnowKey = TRUE;
  11598. }
  11599. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11600. {
  11601. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11603. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11604. {
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11606. }
  11607. else
  11608. {
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11610. }
  11611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11612. isKnowKey = TRUE;
  11613. }
  11614. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11615. {
  11616. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11618. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11619. {
  11620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11621. }
  11622. else
  11623. {
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11625. }
  11626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11627. isKnowKey = TRUE;
  11628. }
  11629. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11630. {
  11631. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11633. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11634. {
  11635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11636. }
  11637. else
  11638. {
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11640. }
  11641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11642. isKnowKey = TRUE;
  11643. }
  11644. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11645. {
  11646. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11648. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11649. {
  11650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11651. }
  11652. else
  11653. {
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11655. }
  11656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11657. isKnowKey = TRUE;
  11658. }
  11659. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11660. {
  11661. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11663. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11664. {
  11665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11666. }
  11667. else
  11668. {
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11670. }
  11671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11672. isKnowKey = TRUE;
  11673. }
  11674. //=========================================================
  11675. if(!isEmpty && !isKnowKey)
  11676. {
  11677. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11678. strcpy(unknownkey[UnknownKeynum], keyReq);
  11679. UnknownKeynum = UnknownKeynum + 1;
  11680. }
  11681. }
  11682. void processUnkownKey(void)
  11683. {
  11684. DEBUG_INFO("processUnkownKey...\n");
  11685. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11686. for(int index=0; index < UnknownKeynum; index++)
  11687. {
  11688. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11689. {
  11690. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11691. }
  11692. }
  11693. }
  11694. int setKeyValue(char *key, char *value)
  11695. {
  11696. int isSuccess = NotSupported;
  11697. int check_ascii=0;
  11698. char str[10]={0};
  11699. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11700. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11701. {
  11702. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11704. {
  11705. strcpy(str, (const char*)value);
  11706. for(int i = 0; str[i]; i++){
  11707. str[i] = tolower(str[i]);
  11708. }
  11709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11710. isSuccess = ConfigurationStatus_Accepted;
  11711. }
  11712. else
  11713. {
  11714. isSuccess = ConfigurationStatus_Rejected;
  11715. }
  11716. }
  11717. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11718. {
  11719. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11720. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11721. {
  11722. strcpy(str, (const char*)value);
  11723. for(int i = 0; str[i]; i++){
  11724. str[i] = tolower(str[i]);
  11725. }
  11726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11727. isSuccess = ConfigurationStatus_Accepted;
  11728. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11729. }
  11730. else
  11731. {
  11732. isSuccess = ConfigurationStatus_Rejected;
  11733. }
  11734. }
  11735. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11736. {
  11737. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11738. {
  11739. strcpy(str, (const char*)value);
  11740. for(int i = 0; str[i]; i++)
  11741. {
  11742. str[i] = tolower(str[i]);
  11743. }
  11744. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11746. isSuccess = ConfigurationStatus_Accepted;
  11747. }
  11748. else
  11749. {
  11750. isSuccess = ConfigurationStatus_Rejected;
  11751. }
  11752. }
  11753. if(strcmp(key, "BlinkRepeat") == 0)
  11754. {
  11755. //Charger.BlinkRepeat = Integer.parseInt(value);
  11756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11757. {
  11758. check_ascii = value[0];
  11759. if( (check_ascii < 48) || (check_ascii > 57) )
  11760. {
  11761. isSuccess = ConfigurationStatus_Rejected;
  11762. }
  11763. else
  11764. {
  11765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11766. isSuccess = ConfigurationStatus_Accepted;
  11767. }
  11768. }
  11769. else
  11770. {
  11771. isSuccess = ConfigurationStatus_Rejected;
  11772. }
  11773. }
  11774. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11775. {
  11776. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11777. {
  11778. check_ascii = value[0];
  11779. if( (check_ascii < 48) || (check_ascii > 57) )
  11780. {
  11781. isSuccess = ConfigurationStatus_Rejected;
  11782. }
  11783. else
  11784. {
  11785. if((atoi(value) == 0) || (atoi(value) >= 10))
  11786. {
  11787. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11789. isSuccess = ConfigurationStatus_Accepted;
  11790. }
  11791. else
  11792. isSuccess = ConfigurationStatus_Rejected;
  11793. }
  11794. }
  11795. else
  11796. {
  11797. isSuccess = ConfigurationStatus_Rejected;
  11798. }
  11799. }
  11800. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11801. {
  11802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11803. {
  11804. check_ascii = value[0];
  11805. if( (check_ascii < 48) || (check_ascii > 57) )
  11806. {
  11807. isSuccess = ConfigurationStatus_Rejected;
  11808. }
  11809. else
  11810. {
  11811. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11813. isSuccess = ConfigurationStatus_Accepted;
  11814. }
  11815. }
  11816. else
  11817. {
  11818. isSuccess = ConfigurationStatus_Rejected;
  11819. }
  11820. }
  11821. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11822. {
  11823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11824. {
  11825. check_ascii = value[0];
  11826. if( (check_ascii < 48) || (check_ascii > 57) )
  11827. {
  11828. isSuccess = ConfigurationStatus_Rejected;
  11829. }
  11830. else
  11831. {
  11832. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11834. isSuccess = ConfigurationStatus_Accepted;
  11835. }
  11836. }
  11837. else
  11838. {
  11839. isSuccess = ConfigurationStatus_Rejected;
  11840. }
  11841. }
  11842. if(strcmp(key, "HeartbeatInterval") == 0)
  11843. {
  11844. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11845. {
  11846. check_ascii = value[0];
  11847. if( (check_ascii < 48) || (check_ascii > 57) )
  11848. {
  11849. isSuccess = ConfigurationStatus_Rejected;
  11850. }
  11851. else
  11852. {
  11853. if((atoi(value) == 0) || (atoi(value) >= 10))
  11854. {
  11855. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11857. HeartBeatWaitTime = atoi(value);
  11858. isSuccess = ConfigurationStatus_Accepted;
  11859. }
  11860. else
  11861. {
  11862. isSuccess = ConfigurationStatus_Rejected;
  11863. }
  11864. }
  11865. }
  11866. else
  11867. {
  11868. isSuccess = ConfigurationStatus_Rejected;
  11869. }
  11870. }
  11871. if(strcmp(key, "LightIntensity") == 0)
  11872. {
  11873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11874. {
  11875. check_ascii = value[0];
  11876. if( (check_ascii < 48) || (check_ascii > 57) )
  11877. {
  11878. isSuccess = ConfigurationStatus_Rejected;
  11879. }
  11880. else
  11881. {
  11882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11883. isSuccess = ConfigurationStatus_Accepted;
  11884. }
  11885. }
  11886. else
  11887. {
  11888. isSuccess = ConfigurationStatus_Rejected;
  11889. }
  11890. }
  11891. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11892. {
  11893. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11894. {
  11895. strcpy(str, (const char*)value);
  11896. for(int i = 0; str[i]; i++)
  11897. {
  11898. str[i] = tolower(str[i]);
  11899. }
  11900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11901. isSuccess = ConfigurationStatus_Accepted;
  11902. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11903. }
  11904. else
  11905. {
  11906. isSuccess = ConfigurationStatus_Rejected;
  11907. }
  11908. }
  11909. if(strcmp(key, "LocalPreAuthorize") == 0)
  11910. {
  11911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11912. {
  11913. strcpy(str, (const char*)value);
  11914. for(int i = 0; str[i]; i++)
  11915. {
  11916. str[i] = tolower(str[i]);
  11917. }
  11918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11919. isSuccess = ConfigurationStatus_Accepted;
  11920. }
  11921. else
  11922. {
  11923. isSuccess = ConfigurationStatus_Rejected;
  11924. }
  11925. }
  11926. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11927. {
  11928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11929. {
  11930. check_ascii = value[0];
  11931. if( (check_ascii < 48) || (check_ascii > 57) )
  11932. {
  11933. isSuccess = ConfigurationStatus_Rejected;
  11934. }
  11935. else
  11936. {
  11937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11938. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11939. isSuccess = ConfigurationStatus_Accepted;
  11940. }
  11941. }
  11942. else
  11943. {
  11944. isSuccess = ConfigurationStatus_Rejected;
  11945. }
  11946. }
  11947. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11948. {
  11949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11950. {
  11951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11952. isSuccess = ConfigurationStatus_Accepted;
  11953. }
  11954. else
  11955. {
  11956. isSuccess = ConfigurationStatus_Rejected;
  11957. }
  11958. }
  11959. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11960. {
  11961. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11962. {
  11963. check_ascii = value[0];
  11964. if( (check_ascii < 48) || (check_ascii > 57) )
  11965. {
  11966. isSuccess = ConfigurationStatus_Rejected;
  11967. }
  11968. else
  11969. {
  11970. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11972. isSuccess = ConfigurationStatus_Accepted;
  11973. }
  11974. }
  11975. else
  11976. {
  11977. isSuccess = ConfigurationStatus_Rejected;
  11978. }
  11979. }
  11980. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11981. {
  11982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11983. {
  11984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11985. isSuccess = ConfigurationStatus_Accepted;
  11986. }
  11987. else
  11988. {
  11989. isSuccess = ConfigurationStatus_Rejected;
  11990. }
  11991. }
  11992. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11993. {
  11994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11995. {
  11996. check_ascii = value[0];
  11997. if( (check_ascii < 48) || (check_ascii > 57) )
  11998. {
  11999. isSuccess = ConfigurationStatus_Rejected;
  12000. }
  12001. else
  12002. {
  12003. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12005. isSuccess = ConfigurationStatus_Accepted;
  12006. }
  12007. }
  12008. else
  12009. {
  12010. isSuccess = ConfigurationStatus_Rejected;
  12011. }
  12012. }
  12013. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12014. {
  12015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12016. {
  12017. check_ascii = value[0];
  12018. if( (check_ascii < 48) || (check_ascii > 57) )
  12019. {
  12020. isSuccess = ConfigurationStatus_Rejected;
  12021. }
  12022. else
  12023. {
  12024. if((atoi(value) == 0) || (atoi(value) >= 10))
  12025. {
  12026. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12028. isSuccess = ConfigurationStatus_Accepted;
  12029. }
  12030. else
  12031. {
  12032. isSuccess = ConfigurationStatus_Rejected;
  12033. }
  12034. }
  12035. }
  12036. else
  12037. {
  12038. isSuccess = ConfigurationStatus_Rejected;
  12039. }
  12040. }
  12041. if(strcmp(key, "MinimumStatusDuration") == 0)
  12042. {
  12043. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12044. {
  12045. check_ascii = value[0];
  12046. if( (check_ascii < 48) || (check_ascii > 57) )
  12047. {
  12048. isSuccess = ConfigurationStatus_Rejected;
  12049. }
  12050. else
  12051. {
  12052. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12053. {
  12054. isSuccess = ConfigurationStatus_Rejected;
  12055. }
  12056. else
  12057. {
  12058. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12060. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12061. isSuccess = ConfigurationStatus_Accepted;
  12062. }
  12063. }
  12064. }
  12065. else
  12066. {
  12067. isSuccess = ConfigurationStatus_Rejected;
  12068. }
  12069. }
  12070. if(strcmp(key, "NumberOfConnectors") == 0)
  12071. {
  12072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12073. {
  12074. check_ascii = value[0];
  12075. if( (check_ascii < 48) || (check_ascii > 57) )
  12076. {
  12077. isSuccess = ConfigurationStatus_Rejected;
  12078. }
  12079. else
  12080. {
  12081. //Charger.ResetRetries = Integer.parseInt(value);
  12082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12083. isSuccess = ConfigurationStatus_Accepted;
  12084. }
  12085. }
  12086. else
  12087. {
  12088. isSuccess = ConfigurationStatus_Rejected;
  12089. }
  12090. }
  12091. if(strcmp(key, "ResetRetries") == 0)
  12092. {
  12093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12094. {
  12095. check_ascii = value[0];
  12096. if( (check_ascii < 48) || (check_ascii > 57) )
  12097. {
  12098. isSuccess = ConfigurationStatus_Rejected;
  12099. }
  12100. else
  12101. {
  12102. //Charger.ResetRetries = Integer.parseInt(value);
  12103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12104. isSuccess = ConfigurationStatus_Accepted;
  12105. }
  12106. }
  12107. else
  12108. {
  12109. isSuccess = ConfigurationStatus_Rejected;
  12110. }
  12111. }
  12112. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12113. {
  12114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12115. {
  12116. strcpy(str, (const char*)value);
  12117. for(int i = 0; str[i]; i++)
  12118. {
  12119. str[i] = tolower(str[i]);
  12120. }
  12121. if(strcmp(str, "notapplicable")== 0)
  12122. {
  12123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12124. isSuccess = ConfigurationStatus_Accepted;
  12125. }
  12126. else if(strcmp(str, "unknown")== 0)
  12127. {
  12128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12129. isSuccess = ConfigurationStatus_Accepted;
  12130. }
  12131. else if(strcmp(str, "rst")== 0)
  12132. {
  12133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12134. isSuccess = ConfigurationStatus_Accepted;
  12135. }
  12136. else if(strcmp(str, "rts")== 0)
  12137. {
  12138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12139. isSuccess = ConfigurationStatus_Accepted;
  12140. }
  12141. else if(strcmp(str, "srt")== 0)
  12142. {
  12143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12144. isSuccess = ConfigurationStatus_Accepted;
  12145. }
  12146. else if(strcmp(str, "str")== 0)
  12147. {
  12148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12149. isSuccess = ConfigurationStatus_Accepted;
  12150. }
  12151. else if(strcmp(str, "trs")== 0)
  12152. {
  12153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12154. isSuccess = ConfigurationStatus_Accepted;
  12155. }
  12156. else if(strcmp(str, "tsr")== 0)
  12157. {
  12158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12159. isSuccess = ConfigurationStatus_Accepted;
  12160. }
  12161. else
  12162. {
  12163. isSuccess = ConfigurationStatus_Rejected;
  12164. }
  12165. }
  12166. else
  12167. {
  12168. isSuccess = ConfigurationStatus_Rejected;
  12169. }
  12170. }
  12171. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12172. {
  12173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12174. {
  12175. check_ascii = value[0];
  12176. if( (check_ascii < 48) || (check_ascii > 57) )
  12177. {
  12178. isSuccess = ConfigurationStatus_Rejected;
  12179. }
  12180. else
  12181. {
  12182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12183. isSuccess = ConfigurationStatus_Accepted;
  12184. }
  12185. }
  12186. else
  12187. {
  12188. isSuccess = ConfigurationStatus_Rejected;
  12189. }
  12190. }
  12191. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12192. {
  12193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12194. {
  12195. strcpy(str, (const char*)value);
  12196. for(int i = 0; str[i]; i++)
  12197. {
  12198. str[i] = tolower(str[i]);
  12199. }
  12200. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12202. isSuccess = ConfigurationStatus_Accepted;
  12203. }
  12204. else
  12205. {
  12206. isSuccess = ConfigurationStatus_Rejected;
  12207. }
  12208. }
  12209. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12210. {
  12211. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12212. {
  12213. strcpy(str, (const char*)value);
  12214. for(int i = 0; str[i]; i++)
  12215. {
  12216. str[i] = tolower(str[i]);
  12217. }
  12218. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12220. isSuccess = ConfigurationStatus_Accepted;
  12221. }
  12222. else
  12223. {
  12224. isSuccess = ConfigurationStatus_Rejected;
  12225. }
  12226. }
  12227. if(strcmp(key, "StopTxnAlignedData") == 0)
  12228. {
  12229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12230. {
  12231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12232. isSuccess = ConfigurationStatus_Accepted;
  12233. }
  12234. else
  12235. {
  12236. isSuccess = ConfigurationStatus_Rejected;
  12237. }
  12238. }
  12239. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12240. {
  12241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12242. {
  12243. check_ascii = value[0];
  12244. if( (check_ascii < 48) || (check_ascii > 57) )
  12245. {
  12246. isSuccess = ConfigurationStatus_Rejected;
  12247. }
  12248. else
  12249. {
  12250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12251. isSuccess = ConfigurationStatus_Accepted;
  12252. }
  12253. }
  12254. else
  12255. {
  12256. isSuccess = ConfigurationStatus_Rejected;
  12257. }
  12258. }
  12259. if(strcmp(key, "StopTxnSampledData") == 0)
  12260. {
  12261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12262. {
  12263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12264. isSuccess = ConfigurationStatus_Accepted;
  12265. }
  12266. else
  12267. {
  12268. isSuccess = ConfigurationStatus_Rejected;
  12269. }
  12270. }
  12271. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12272. {
  12273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12274. {
  12275. check_ascii = value[0];
  12276. if( (check_ascii < 48) || (check_ascii > 57) )
  12277. {
  12278. isSuccess = ConfigurationStatus_Rejected;
  12279. }
  12280. else
  12281. {
  12282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12283. isSuccess = ConfigurationStatus_Accepted;
  12284. }
  12285. }
  12286. else
  12287. {
  12288. isSuccess = ConfigurationStatus_Rejected;
  12289. }
  12290. }
  12291. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12292. {
  12293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12294. {
  12295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12296. isSuccess = ConfigurationStatus_Accepted;
  12297. }
  12298. else
  12299. {
  12300. isSuccess = ConfigurationStatus_Rejected;
  12301. }
  12302. }
  12303. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12304. {
  12305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12306. {
  12307. check_ascii = value[0];
  12308. if( (check_ascii < 48) || (check_ascii > 57) )
  12309. {
  12310. isSuccess = ConfigurationStatus_Rejected;
  12311. }
  12312. else
  12313. {
  12314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12315. isSuccess = ConfigurationStatus_Accepted;
  12316. }
  12317. }
  12318. else
  12319. {
  12320. isSuccess = ConfigurationStatus_Rejected;
  12321. }
  12322. }
  12323. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12324. {
  12325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12326. {
  12327. check_ascii = value[0];
  12328. if( (check_ascii < 48) || (check_ascii > 57) )
  12329. {
  12330. isSuccess = ConfigurationStatus_Rejected;
  12331. }
  12332. else
  12333. {
  12334. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12336. TransactionMessageAttemptsValue = atoi(value);
  12337. isSuccess = ConfigurationStatus_Accepted;
  12338. }
  12339. }
  12340. else
  12341. {
  12342. isSuccess = ConfigurationStatus_Rejected;
  12343. }
  12344. }
  12345. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12346. {
  12347. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12348. {
  12349. check_ascii = value[0];
  12350. if( (check_ascii < 48) || (check_ascii > 57) )
  12351. {
  12352. isSuccess = ConfigurationStatus_Rejected;
  12353. }
  12354. else
  12355. {
  12356. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12358. TransactionMessageRetryIntervalValue = atoi(value);
  12359. isSuccess = ConfigurationStatus_Accepted;
  12360. }
  12361. }
  12362. else
  12363. {
  12364. isSuccess = ConfigurationStatus_Rejected;
  12365. }
  12366. }
  12367. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12368. {
  12369. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12370. {
  12371. strcpy(str, (const char*)value);
  12372. for(int i = 0; str[i]; i++)
  12373. {
  12374. str[i] = tolower(str[i]);
  12375. }
  12376. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12378. isSuccess = ConfigurationStatus_Accepted;
  12379. }
  12380. else
  12381. {
  12382. isSuccess = ConfigurationStatus_Rejected;
  12383. }
  12384. }
  12385. if(strcmp(key, "WebSocketPingInterval") == 0)
  12386. {
  12387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12388. {
  12389. check_ascii = value[0];
  12390. if( (check_ascii < 48) || (check_ascii > 57) )
  12391. {
  12392. isSuccess = ConfigurationStatus_Rejected;
  12393. }
  12394. else
  12395. {
  12396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12397. isSuccess = ConfigurationStatus_Accepted;
  12398. }
  12399. }
  12400. else
  12401. {
  12402. isSuccess = ConfigurationStatus_Rejected;
  12403. }
  12404. }
  12405. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12406. {
  12407. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12408. {
  12409. strcpy(str, (const char*)value);
  12410. for(int i = 0; str[i]; i++)
  12411. {
  12412. str[i] = tolower(str[i]);
  12413. }
  12414. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12416. isSuccess = ConfigurationStatus_Accepted;
  12417. }
  12418. else
  12419. {
  12420. isSuccess = ConfigurationStatus_Rejected;
  12421. }
  12422. }
  12423. if(strcmp(key, "AuthorizationKey") == 0)
  12424. {
  12425. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12426. {
  12427. strcpy(str, (const char*)value);
  12428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12429. isSuccess = ConfigurationStatus_Accepted;
  12430. }
  12431. else
  12432. {
  12433. isSuccess = ConfigurationStatus_Rejected;
  12434. }
  12435. }
  12436. if(strcmp(key, "SecurityProfile") == 0)
  12437. {
  12438. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12439. {
  12440. check_ascii = value[0];
  12441. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12442. {
  12443. isSuccess = ConfigurationStatus_Rejected;
  12444. }
  12445. else if(check_ascii == 0x33)
  12446. {
  12447. isSuccess = NotSupported;
  12448. }
  12449. else
  12450. {
  12451. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12452. {
  12453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12454. isSuccess = ConfigurationStatus_Accepted;
  12455. }
  12456. else
  12457. isSuccess = ConfigurationStatus_Rejected;
  12458. }
  12459. }
  12460. else
  12461. {
  12462. isSuccess = ConfigurationStatus_Rejected;
  12463. }
  12464. }
  12465. if(strcmp(key, "DefaultPrice") == 0)
  12466. {
  12467. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12468. {
  12469. strcpy(str, (const char*)value);
  12470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12471. isSuccess = ConfigurationStatus_Accepted;
  12472. }
  12473. else
  12474. {
  12475. isSuccess = ConfigurationStatus_Rejected;
  12476. }
  12477. }
  12478. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12479. {
  12480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12481. {
  12482. strcpy(str, (const char*)value);
  12483. for(int i = 0; str[i]; i++)
  12484. {
  12485. str[i] = tolower(str[i]);
  12486. }
  12487. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12489. isSuccess = ConfigurationStatus_Accepted;
  12490. }
  12491. else
  12492. {
  12493. isSuccess = ConfigurationStatus_Rejected;
  12494. }
  12495. }
  12496. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12497. {
  12498. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12499. {
  12500. strcpy(str, (const char*)value);
  12501. for(int i = 0; str[i]; i++)
  12502. {
  12503. str[i] = tolower(str[i]);
  12504. }
  12505. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12507. isSuccess = ConfigurationStatus_Accepted;
  12508. }
  12509. else
  12510. {
  12511. isSuccess = ConfigurationStatus_Rejected;
  12512. }
  12513. }
  12514. #if 0
  12515. //For OCPP Test Case
  12516. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12517. {
  12518. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12519. {
  12520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12521. isSuccess = ConfigurationStatus_Accepted;
  12522. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12523. }
  12524. else
  12525. {
  12526. isSuccess = ConfigurationStatus_Rejected;
  12527. }
  12528. }
  12529. #endif
  12530. #if 1
  12531. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12532. {
  12533. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12534. {
  12535. strcpy(str, (const char*)value);
  12536. for(int i = 0; str[i]; i++)
  12537. {
  12538. str[i] = tolower(str[i]);
  12539. }
  12540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12541. isSuccess = ConfigurationStatus_Accepted;
  12542. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12543. }
  12544. else
  12545. {
  12546. isSuccess = ConfigurationStatus_Rejected;
  12547. }
  12548. }
  12549. #endif
  12550. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12551. {
  12552. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12553. {
  12554. check_ascii = value[0];
  12555. if( (check_ascii < 48) || (check_ascii > 57) )
  12556. {
  12557. isSuccess = ConfigurationStatus_Rejected;
  12558. }
  12559. else
  12560. {
  12561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12562. isSuccess = ConfigurationStatus_Accepted;
  12563. }
  12564. }
  12565. else
  12566. {
  12567. isSuccess = ConfigurationStatus_Rejected;
  12568. }
  12569. }
  12570. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12571. {
  12572. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12573. {
  12574. check_ascii = value[0];
  12575. if( (check_ascii < 48) || (check_ascii > 57) )
  12576. {
  12577. isSuccess = ConfigurationStatus_Rejected;
  12578. }
  12579. else
  12580. {
  12581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12582. isSuccess = ConfigurationStatus_Accepted;
  12583. }
  12584. }
  12585. else
  12586. {
  12587. isSuccess = ConfigurationStatus_Rejected;
  12588. }
  12589. }
  12590. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12591. {
  12592. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12593. {
  12594. strcpy(str, (const char*)value);
  12595. for(int i = 0; str[i]; i++)
  12596. {
  12597. str[i] = tolower(str[i]);
  12598. }
  12599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12600. isSuccess = ConfigurationStatus_Accepted;
  12601. }
  12602. else
  12603. {
  12604. isSuccess = ConfigurationStatus_Rejected;
  12605. }
  12606. }
  12607. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12608. {
  12609. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12610. {
  12611. check_ascii = value[0];
  12612. if( (check_ascii < 48) || (check_ascii > 57) )
  12613. {
  12614. isSuccess = ConfigurationStatus_Rejected;
  12615. }
  12616. else
  12617. {
  12618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12619. isSuccess = ConfigurationStatus_Accepted;
  12620. }
  12621. }
  12622. else
  12623. {
  12624. isSuccess = ConfigurationStatus_Rejected;
  12625. }
  12626. }
  12627. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12628. {
  12629. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12630. {
  12631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12632. isSuccess = ConfigurationStatus_Accepted;
  12633. }
  12634. else
  12635. {
  12636. isSuccess = ConfigurationStatus_Rejected;
  12637. }
  12638. }
  12639. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12640. {
  12641. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12642. {
  12643. check_ascii = value[0];
  12644. if( (check_ascii < 48) || (check_ascii > 57) )
  12645. {
  12646. isSuccess = ConfigurationStatus_Rejected;
  12647. }
  12648. else
  12649. {
  12650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12651. isSuccess = ConfigurationStatus_Accepted;
  12652. }
  12653. }
  12654. else
  12655. {
  12656. isSuccess = ConfigurationStatus_Rejected;
  12657. }
  12658. }
  12659. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12660. {
  12661. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12662. {
  12663. strcpy(str, (const char*)value);
  12664. for(int i = 0; str[i]; i++)
  12665. {
  12666. str[i] = tolower(str[i]);
  12667. }
  12668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12669. isSuccess = ConfigurationStatus_Accepted;
  12670. }
  12671. else
  12672. {
  12673. isSuccess = ConfigurationStatus_Rejected;
  12674. }
  12675. }
  12676. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12677. {
  12678. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12679. {
  12680. check_ascii = value[0];
  12681. if( (check_ascii < 48) || (check_ascii > 57) )
  12682. {
  12683. isSuccess = ConfigurationStatus_Rejected;
  12684. }
  12685. else
  12686. {
  12687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12688. isSuccess = ConfigurationStatus_Accepted;
  12689. }
  12690. }
  12691. else
  12692. {
  12693. isSuccess = ConfigurationStatus_Rejected;
  12694. }
  12695. }
  12696. return isSuccess;
  12697. }
  12698. int TransactionMessageAttemptsGet(void)
  12699. {
  12700. return TransactionMessageAttemptsValue;
  12701. }
  12702. int FirstHeartBeatResponse(void)
  12703. {
  12704. return FirstHeartBeat;
  12705. }
  12706. int TransactionMessageRetryIntervalGet(void)
  12707. {
  12708. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12709. }
  12710. int ReadHttpStatus(int sock)
  12711. {
  12712. //char c;
  12713. char buff[1024]="",*ptr=buff+1;
  12714. int bytes_received, status;
  12715. DEBUG_INFO("Begin Response ..\n");
  12716. while((bytes_received = recv(sock, ptr, 1, 0))){
  12717. if(bytes_received==-1){
  12718. perror("ReadHttpStatus");
  12719. exit(1);
  12720. }
  12721. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12722. ptr++;
  12723. }
  12724. *ptr=0;
  12725. ptr=buff+1;
  12726. sscanf(ptr,"%*s %d ", &status);
  12727. DEBUG_INFO("%s\n",ptr);
  12728. DEBUG_INFO("status=%d\n",status);
  12729. DEBUG_INFO("End Response ..\n");
  12730. return (bytes_received>0)?status:0;
  12731. }
  12732. //the only filed that it parsed is 'Content-Length'
  12733. int ParseHeader(int sock)
  12734. {
  12735. //char c;
  12736. char buff[1024]="",*ptr=buff+4;
  12737. int bytes_received;
  12738. DEBUG_INFO("Begin HEADER ..\n");
  12739. while((bytes_received = recv(sock, ptr, 1, 0))){
  12740. if(bytes_received==-1){
  12741. perror("Parse Header");
  12742. exit(1);
  12743. }
  12744. if(
  12745. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12746. (ptr[-1]=='\r') && (*ptr=='\n' )
  12747. ) break;
  12748. ptr++;
  12749. }
  12750. *ptr=0;
  12751. ptr=buff+4;
  12752. //printf("%s",ptr);
  12753. if(bytes_received){
  12754. ptr=strstr(ptr,"Content-Length:");
  12755. if(ptr){
  12756. sscanf(ptr,"%*s %d",&bytes_received);
  12757. }else
  12758. bytes_received=-1; //unknown size
  12759. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12760. }
  12761. DEBUG_INFO("End HEADER ..\n");
  12762. return bytes_received ;
  12763. }
  12764. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12765. {
  12766. char rmFileCmd[100]={0};
  12767. char FilePath[100]={0};
  12768. char ftpbuf[200];
  12769. int systemresult;
  12770. //DEBUG_INFO("filename=%s\n",filename);
  12771. //DEBUG_INFO("url=%s\n",url);
  12772. sprintf(FilePath,"/mnt/%s",filename);
  12773. system("ping 8.8.8.8 &");
  12774. if((access(FilePath,F_OK))!=-1)
  12775. {
  12776. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12777. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12778. system(rmFileCmd);
  12779. }
  12780. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12781. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12782. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12783. systemresult = system(ftpbuf);
  12784. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12785. if(systemresult != 0)
  12786. {
  12787. DEBUG_INFO("http DownLoad error!\n");
  12788. return FALSE;
  12789. }
  12790. system("pkill ping");
  12791. return TRUE;
  12792. }
  12793. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12794. {
  12795. char rmFileCmd[100]={0};
  12796. char FilePath[100]={0};
  12797. char ftpbuf[200];
  12798. int systemresult;
  12799. //char temp[100];
  12800. sprintf(FilePath,"/mnt/%s",filename);
  12801. system("ping 8.8.8.8 &");
  12802. if((access(FilePath,F_OK))!=-1)
  12803. {
  12804. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12805. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12806. system(rmFileCmd);
  12807. }
  12808. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12809. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12810. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12811. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12812. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12813. systemresult = system(ftpbuf);
  12814. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12815. if(systemresult != 0)
  12816. {
  12817. printf("wget error!\n");
  12818. return FALSE;
  12819. }
  12820. system("pkill ping");
  12821. return TRUE;
  12822. }
  12823. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12824. {
  12825. char rmFileCmd[100]={0};
  12826. char FilePath[100]={0};
  12827. char ftpbuf[200];
  12828. int systemresult;
  12829. //DEBUG_INFO("filename=%s\n",filename);
  12830. //DEBUG_INFO("url=%s\n",url);
  12831. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12832. if((access(FilePath,F_OK))!=-1)
  12833. {
  12834. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12835. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12836. system(rmFileCmd);
  12837. }
  12838. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12839. if(fp == NULL)
  12840. {
  12841. DEBUG_INFO("log is NULL\n");
  12842. return FALSE;
  12843. }
  12844. else
  12845. {
  12846. fprintf(fp, "%s\n", url);
  12847. fprintf(fp, "%s\n", filename);
  12848. fclose(fp);
  12849. }
  12850. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12851. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12852. systemresult = system(ftpbuf);
  12853. DEBUG_INFO("systemresult = %d\n",systemresult);
  12854. if(systemresult != 0)
  12855. {
  12856. DEBUG_INFO("http upload error!\n");
  12857. return FALSE;
  12858. }
  12859. return TRUE;
  12860. }
  12861. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12862. {
  12863. struct hostent* server;
  12864. char *IPbuffer;
  12865. char ftpbuf[200];
  12866. int systemresult;
  12867. // To retrieve host information
  12868. server = gethostbyname(location);
  12869. // To convert an Internet network
  12870. // address into ASCII string
  12871. IPbuffer = inet_ntoa(*((struct in_addr*)
  12872. server->h_addr_list[0]));
  12873. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12874. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12875. /* format : ftpput -u username -p passwd IP target source*/
  12876. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12877. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12878. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12879. systemresult = system(ftpbuf);
  12880. DEBUG_INFO("systemresult=%d\n",systemresult);
  12881. if(systemresult != 0)
  12882. {
  12883. DEBUG_INFO("ftpput error!\n");
  12884. return FALSE;
  12885. }
  12886. return TRUE;
  12887. }
  12888. /**
  12889. * Place the contents of the specified file into a memory buffer
  12890. *
  12891. * @param[in] filename The path and name of the file to read
  12892. * @param[out] filebuffer A pointer to the contents in memory
  12893. * @return status 0 success, 1 on failure
  12894. */
  12895. int get_file_contents(const char* filename, char** outbuffer) {
  12896. FILE* file = NULL;
  12897. long filesize;
  12898. const int blocksize = 1;
  12899. size_t readsize;
  12900. char* filebuffer;
  12901. // Open the file
  12902. file = fopen(filename, "r");
  12903. if (NULL == file)
  12904. {
  12905. printf("'%s' not opened\n", filename);
  12906. exit(EXIT_FAILURE);
  12907. }
  12908. // Determine the file size
  12909. fseek(file, 0, SEEK_END);
  12910. filesize = ftell(file);
  12911. rewind (file);
  12912. // Allocate memory for the file contents
  12913. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12914. *outbuffer = filebuffer;
  12915. if (filebuffer == NULL)
  12916. {
  12917. fputs ("malloc out-of-memory", stderr);
  12918. exit(EXIT_FAILURE);
  12919. }
  12920. // Read in the file
  12921. readsize = fread(filebuffer, blocksize, filesize, file);
  12922. if (readsize != filesize)
  12923. {
  12924. fputs ("didn't read file completely",stderr);
  12925. exit(EXIT_FAILURE);
  12926. }
  12927. // Clean exit
  12928. fclose(file);
  12929. return EXIT_SUCCESS;
  12930. }
  12931. static int selectSqlCount = 0;
  12932. static int callback(void *data, int argc, char **argv, char **azColName){
  12933. int i;
  12934. //printf("%s: ", (const char*)data);
  12935. selectSqlCount = argc;
  12936. for(i = 0; i<argc; i++){
  12937. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12938. }
  12939. //printf("\n");
  12940. return 0;
  12941. }
  12942. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12943. //int i;
  12944. //printf("%s:\n", (const char*)data);
  12945. localversion = argv[5] ? atoi(argv[5]) : 0;
  12946. //printf("localversion=%d\n", localversion);
  12947. return 0;
  12948. }
  12949. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  12950. //printf("%s:\n", (const char*)data);
  12951. //idTag
  12952. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  12953. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  12954. //parentIdTag
  12955. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  12956. //expir_date
  12957. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  12958. //status
  12959. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  12960. //version
  12961. if(columenCount > 5)
  12962. idTagQuery.listVersionInt = atoi(columnValue[5]);
  12963. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12964. return 0;
  12965. }
  12966. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12967. {
  12968. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12969. // printf("localversion=%d\n", localversion);
  12970. return 0;
  12971. }
  12972. //=========================================
  12973. // Sqlite3 related function
  12974. //=========================================
  12975. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12976. {
  12977. for (int i = 0; i < n_columns; i++)
  12978. {
  12979. DEBUG_INFO("%s\t", col_values[i]);
  12980. }
  12981. DEBUG_INFO("\n");
  12982. return 0;
  12983. }
  12984. int OCPP_cleanLocalCache()
  12985. {
  12986. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  12987. char *errMsg = 0;
  12988. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12989. if (SQLITE_OK != rc)
  12990. {
  12991. DEBUG_INFO("SQL error: %s\n",errMsg);
  12992. return FALSE;
  12993. }
  12994. return TRUE;
  12995. }
  12996. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  12997. {
  12998. int isSuccess = TRUE;
  12999. int ret = 0;
  13000. //const char* data = "Callback function called";
  13001. char sql[300];
  13002. char zErrMsg[200];
  13003. memset(sql, 0, 300);
  13004. memset(zErrMsg, 0, 200);
  13005. 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);
  13006. //* Execute SQL statement */
  13007. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13008. if( ret != SQLITE_OK )
  13009. {
  13010. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13011. isSuccess = FALSE;
  13012. }
  13013. return isSuccess;
  13014. }
  13015. void OCPP_getIdTagFromLocalCache(char idTag[])
  13016. {
  13017. int rc = 0;
  13018. char sql[100];
  13019. char zErrMsg[100];
  13020. memset(sql, 0, 100);
  13021. memset(zErrMsg, 0, 100);
  13022. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13023. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13024. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  13025. /* Execute SQL statement */
  13026. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13027. if( rc != SQLITE_OK )
  13028. {
  13029. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13030. }
  13031. }
  13032. void OCPP_getListVerion()
  13033. {
  13034. int rc = 0;
  13035. // const char* data = "Callback function called";
  13036. char sql[100];
  13037. char zErrMsg[100];
  13038. memset(sql, 0, 100);
  13039. memset(zErrMsg, 0, 100);
  13040. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13041. /* Execute SQL statement */
  13042. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13043. if( rc != SQLITE_OK )
  13044. {
  13045. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13046. }
  13047. }
  13048. void OCPP_get_TableAuthlocalAllData(void)
  13049. {
  13050. int rc = 0;
  13051. char sql[100];
  13052. char zErrMsg[100];
  13053. memset(sql, 0, 100);
  13054. memset(zErrMsg, 0, 100);
  13055. sprintf(sql,"select * from ocpp_auth_local ");
  13056. /* Execute SQL statement */
  13057. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13058. if( rc != SQLITE_OK )
  13059. {
  13060. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13061. }
  13062. //return ver;
  13063. }
  13064. int OCPP_cleanLocalList()
  13065. {
  13066. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13067. char *errMsg = 0;
  13068. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13069. if (SQLITE_OK != rc)
  13070. {
  13071. DEBUG_INFO("%s\n",errMsg);
  13072. return FALSE;
  13073. }
  13074. return TRUE;
  13075. }
  13076. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13077. {
  13078. int isSuccess = FALSE;
  13079. int ret = 0;
  13080. //const char* data = "Callback function called";
  13081. char sql[300];
  13082. char zErrMsg[200];
  13083. memset(sql, 0, 300);
  13084. memset(zErrMsg, 0, 200);
  13085. 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);
  13086. //* Execute SQL statement */
  13087. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13088. if( ret != SQLITE_OK )
  13089. {
  13090. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13091. return isSuccess;
  13092. }
  13093. memset(sql, 0, 300);
  13094. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13095. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13096. if( ret != SQLITE_OK )
  13097. {
  13098. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13099. return isSuccess;
  13100. }
  13101. isSuccess = TRUE;
  13102. return isSuccess;
  13103. }
  13104. void OCPP_getIdTagFromLocalList(char idTag[])
  13105. {
  13106. int rc = 0;
  13107. // const char* data = "Callback function called";
  13108. char sql[100];
  13109. char zErrMsg[100];
  13110. memset(sql, 0, 100);
  13111. memset(zErrMsg, 0, 100);
  13112. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13113. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13114. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13115. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13116. /* Execute SQL statement */
  13117. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13118. if( rc != SQLITE_OK )
  13119. {
  13120. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13121. }
  13122. //return ver;
  13123. }
  13124. void OCPP_deleteIdTagFromLocalList(char idTag[])
  13125. {
  13126. //int ver = 0;
  13127. //int isSuccess = FALSE;
  13128. int rc = 0;
  13129. char sql[100];
  13130. char zErrMsg[100];
  13131. memset(sql, 0, 100);
  13132. memset(zErrMsg, 0, 100);
  13133. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13134. //* Execute SQL statement */
  13135. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13136. if( rc != SQLITE_OK )
  13137. {
  13138. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13139. }
  13140. }
  13141. int GetOcppServerURL()
  13142. {
  13143. int result = FALSE;
  13144. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13145. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13146. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13147. struct yuarel url;
  13148. char urlStr[512];
  13149. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13150. {
  13151. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13152. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13153. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13154. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13155. if(yuarel_parse(&url, urlStr) != -1)
  13156. {
  13157. sprintf(OcppProtocol, "%s", url.scheme);
  13158. sprintf(OcppHost, "%s", url.host);
  13159. if(url.path == NULL)
  13160. OcppTempPath[0] = '\0';
  13161. else
  13162. {
  13163. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13164. {
  13165. sprintf(OcppTempPath, "%s/", url.path);
  13166. }
  13167. else
  13168. {
  13169. sprintf(OcppTempPath, "%s", url.path);
  13170. }
  13171. }
  13172. if(url.port == 0)
  13173. {
  13174. if(strcmp(OcppProtocol, "wss") == 0)
  13175. OcppPort = 443;
  13176. else
  13177. OcppPort = 80;
  13178. }
  13179. else
  13180. OcppPort = url.port;
  13181. result = TRUE;
  13182. }
  13183. }
  13184. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13185. {
  13186. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13187. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13188. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13189. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13190. if(yuarel_parse(&url, urlStr) != -1)
  13191. {
  13192. sprintf(OcppProtocol, "%s", url.scheme);
  13193. sprintf(OcppHost, "%s", url.host);
  13194. if(url.path == NULL)
  13195. OcppTempPath[0] = '\0';
  13196. else
  13197. sprintf(OcppTempPath, "%s", url.path);
  13198. if(url.port == 0)
  13199. {
  13200. if(strcmp(OcppProtocol, "wss") == 0)
  13201. OcppPort = 443;
  13202. else
  13203. OcppPort = 80;
  13204. }
  13205. else
  13206. OcppPort = url.port;
  13207. result = TRUE;
  13208. }
  13209. }
  13210. else
  13211. {
  13212. strcpy(OcppHost,"");
  13213. }
  13214. return result;
  13215. }
  13216. int GetOcppPath()
  13217. {
  13218. int result = FALSE;
  13219. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13220. {
  13221. if(OcppTempPath == NULL)
  13222. {
  13223. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13224. }
  13225. else
  13226. {
  13227. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13228. }
  13229. result = TRUE;
  13230. goto End;
  13231. }
  13232. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13233. {
  13234. if(OcppTempPath == NULL)
  13235. {
  13236. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13237. }
  13238. else
  13239. {
  13240. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13241. }
  13242. result = TRUE;
  13243. goto End;
  13244. }
  13245. else
  13246. {
  13247. strcpy(OcppPath,"");
  13248. }
  13249. End:
  13250. return result;
  13251. }
  13252. int GetOcppPort()
  13253. {
  13254. return OcppPort;
  13255. }
  13256. int GetOcppConnStatus(void)
  13257. {
  13258. return ShmOCPP16Data->OcppConnStatus;
  13259. }
  13260. void SetOcppConnStatus(uint8_t status)
  13261. {
  13262. ShmOCPP16Data->OcppConnStatus = status;
  13263. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13264. }
  13265. int GetHeartBeatWithNOResponse(void)
  13266. {
  13267. return HeartBeatWithNOResponse;
  13268. }
  13269. void SetHeartBeatWithNOResponse(void)
  13270. {
  13271. HeartBeatWithNOResponse = 0;
  13272. }
  13273. void GetStartTransactionIdTag(int gun_index)
  13274. {
  13275. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13276. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13277. }
  13278. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13279. {
  13280. char ch;
  13281. FILE *fptr1;
  13282. int temptransactionId;
  13283. char str[100]={0};
  13284. temptransactionId = 0;
  13285. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  13286. {
  13287. DEBUG_INFO("IdTag is empty.\n");
  13288. return temptransactionId;
  13289. }
  13290. /*------ Read the file ----------------*/
  13291. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13292. if (!fptr1)
  13293. {
  13294. DEBUG_INFO("QueueTransactionId file open error.\n");
  13295. //printf(" File not found or unable to open the input file!!\n");
  13296. return temptransactionId;
  13297. }
  13298. ch=fgetc(fptr1);
  13299. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13300. rewind(fptr1);
  13301. if(ch!=EOF)
  13302. {
  13303. // printf("%c",ch);
  13304. while (fgets(str, 100, fptr1) != NULL)
  13305. {
  13306. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13307. if(str[0]=='\0')
  13308. {
  13309. break;
  13310. }
  13311. char *revbuf[8] = {0}; // Variable store string split
  13312. int num = 0;// Quantity after string split
  13313. DEBUG_INFO("Transaction queue data= %s\n", str);
  13314. splitstring(str,",",revbuf,&num); // String split
  13315. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13316. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13317. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13318. DEBUG_INFO("------------------------------\n");
  13319. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13320. {
  13321. if(isStopTransaction)
  13322. {
  13323. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13324. {
  13325. temptransactionId = atoi(revbuf[2]);
  13326. break;
  13327. }
  13328. }
  13329. else
  13330. {
  13331. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13332. {
  13333. temptransactionId = atoi(revbuf[2]);
  13334. break;
  13335. }
  13336. }
  13337. }
  13338. }
  13339. }
  13340. else
  13341. DEBUG_INFO("EOF\n");
  13342. fclose(fptr1);
  13343. /*------- End of reading ---------------*/
  13344. return temptransactionId;
  13345. }
  13346. void SetTransactionIdZero(int transactionId)
  13347. {
  13348. char ch;
  13349. FILE *fptr1, *fptr2;
  13350. int temptransactionId = 0;
  13351. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13352. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13353. if (!fptr1)
  13354. {
  13355. //printf(" File not found or unable to open the input file!!\n");
  13356. return ;
  13357. }
  13358. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13359. if (!fptr2)
  13360. {
  13361. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13362. fclose(fptr1);
  13363. return ;
  13364. }
  13365. ch=fgetc(fptr1);
  13366. rewind(fptr1);
  13367. if(ch!=EOF)
  13368. {
  13369. // copy all contents to the temporary file except the specific line
  13370. while (fgets(str, 100, fptr1) != NULL)
  13371. {
  13372. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13373. if(str[0]=='\0')
  13374. {
  13375. break;
  13376. }
  13377. char *revbuf[8] = {0};
  13378. int num = 0;
  13379. strcpy(strtemp, str);
  13380. splitstring(str,",",revbuf,&num);
  13381. if(revbuf[2][0] != '\0')
  13382. {
  13383. temptransactionId = atoi(revbuf[2]);
  13384. if(transactionId != temptransactionId)
  13385. {
  13386. fprintf(fptr2, "%s\n", strtemp);
  13387. }
  13388. }
  13389. }
  13390. }
  13391. fclose(fptr1);
  13392. fclose(fptr2);
  13393. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13394. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13395. /*------ Read the file ----------------*/
  13396. }
  13397. int InternetDisconnect(void)
  13398. {
  13399. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13400. }
  13401. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13402. void storeTempStopTransaction(int gun_index)
  13403. {
  13404. char guid[37]={0};
  13405. int tempIndex = 0;
  13406. char TempStopTransaction[256];
  13407. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13408. DEBUG_INFO("storeTempStopTransaction...\n");
  13409. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13410. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13411. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13412. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13413. if(gunType[gun_index] == 'J')
  13414. {
  13415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13416. {
  13417. tempIndex = ((gun_index==2) ? 1: 0);
  13418. }
  13419. else
  13420. {
  13421. tempIndex = gun_index;
  13422. }
  13423. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13424. {
  13425. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13426. {
  13427. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13428. }
  13429. }// END OF CHAdeMO_QUANTITY
  13430. }
  13431. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13432. {
  13433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13434. {
  13435. tempIndex = ((gun_index==2) ? 1: 0);
  13436. }
  13437. else
  13438. {
  13439. tempIndex = gun_index;
  13440. }
  13441. for (int index = 0; index < CCS_QUANTITY; index++)
  13442. {
  13443. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13444. {
  13445. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13446. }
  13447. }// END OF CCS_QUANTITY
  13448. }
  13449. else if(gunType[gun_index] == 'G')
  13450. {
  13451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13452. {
  13453. tempIndex = ((gun_index==2) ? 1: 0);
  13454. }
  13455. else
  13456. {
  13457. tempIndex = gun_index;
  13458. }
  13459. for (int index = 0; index < GB_QUANTITY; index++)
  13460. {
  13461. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13462. {
  13463. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13464. }
  13465. }// END OF GB_QUANTITY
  13466. }
  13467. else if(gunType[gun_index] == 'O')
  13468. {
  13469. tempIndex = gun_index;
  13470. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13471. {
  13472. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13473. {
  13474. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13475. }
  13476. }
  13477. }
  13478. else
  13479. {
  13480. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13481. {
  13482. tempIndex = 2;
  13483. }
  13484. else
  13485. {
  13486. tempIndex = gun_index;
  13487. }
  13488. for (int index = 0; index < AC_QUANTITY; index++)
  13489. {
  13490. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13491. {
  13492. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13493. }
  13494. }// END OF AC_QUANTITY
  13495. }
  13496. //Stop Transaction Time
  13497. struct timeval tmnow;
  13498. struct tm *tm;
  13499. char buf[28];//, usec_buf[6];
  13500. gettimeofday(&tmnow, NULL);
  13501. time_t t;
  13502. t = time(NULL);
  13503. /*UTC time and date*/
  13504. tm = gmtime(&t);
  13505. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13507. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13509. random_uuid(guid);
  13510. /***********************************transactionData******************************************************/
  13511. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13513. //=================================
  13514. //1. Transaction_Begin
  13515. //=================================
  13516. //============================== Energy.Active.Import.Interval ===========================================
  13517. //idx_sample=0;
  13518. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13521. 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*/]);
  13522. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13523. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13524. {
  13525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13526. }
  13527. else
  13528. {
  13529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13530. }
  13531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13533. //=================================
  13534. //2. Transaction_End
  13535. //=================================
  13536. //2.1====================================== Current.Import L1 ==============================================
  13537. //idx_sample=1;
  13538. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13539. if(gunType[gun_index] == 'J')
  13540. {
  13541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13542. {
  13543. tempIndex = ((gun_index==2) ? 1: 0);
  13544. }
  13545. else
  13546. {
  13547. tempIndex = gun_index;
  13548. }
  13549. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13550. {
  13551. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13552. {
  13553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13554. }
  13555. }// End of for CHAdeMO_QUANTITY
  13556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13557. }
  13558. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13559. {
  13560. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13561. {
  13562. tempIndex = ((gun_index==2) ? 1: 0);
  13563. }
  13564. else
  13565. {
  13566. tempIndex = gun_index;
  13567. }
  13568. for (int index = 0; index < CCS_QUANTITY; index++)
  13569. {
  13570. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13571. {
  13572. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13573. }
  13574. }// End of for CCS_QUANTITY
  13575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13576. }
  13577. else if(gunType[gun_index] == 'G')
  13578. {
  13579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13580. {
  13581. tempIndex = ((gun_index==2) ? 1: 0);
  13582. }
  13583. else
  13584. {
  13585. tempIndex = gun_index;
  13586. }
  13587. for (int index = 0; index < GB_QUANTITY; index++)
  13588. {
  13589. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13590. {
  13591. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13592. }
  13593. }// End of for GB_QUANTITY
  13594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13595. }
  13596. else if(gunType[gun_index] == 'O')
  13597. {
  13598. tempIndex = gun_index;
  13599. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13600. {
  13601. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13602. {
  13603. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13604. }
  13605. }
  13606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13607. }
  13608. else
  13609. {
  13610. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13611. {
  13612. tempIndex = 2;
  13613. }
  13614. else
  13615. {
  13616. tempIndex = gun_index;
  13617. }
  13618. for (int index = 0; index < AC_QUANTITY; index++)
  13619. {
  13620. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13621. {
  13622. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13623. }
  13624. }// End of for AC_QUANTITY
  13625. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13626. }
  13627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13630. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13633. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13634. //idx_sample=2;
  13635. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13636. if(gunType[gun_index] == 'J')
  13637. {
  13638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13639. {
  13640. tempIndex = ((gun_index==2) ? 1: 0);
  13641. }
  13642. else
  13643. {
  13644. tempIndex = gun_index;
  13645. }
  13646. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13647. {
  13648. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13649. {
  13650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13651. }
  13652. }// END OF CHAdeMO_QUANTITY
  13653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13654. }
  13655. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13656. {
  13657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13658. {
  13659. tempIndex = ((gun_index==2) ? 1: 0);
  13660. }
  13661. else
  13662. {
  13663. tempIndex = gun_index;
  13664. }
  13665. for (int index = 0; index < CCS_QUANTITY; index++)
  13666. {
  13667. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13668. {
  13669. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13670. }
  13671. }// END OF CCS_QUANTITY
  13672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13673. }
  13674. else if(gunType[gun_index] == 'G')
  13675. {
  13676. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13677. {
  13678. tempIndex = ((gun_index==2) ? 1: 0);
  13679. }
  13680. else
  13681. {
  13682. tempIndex = gun_index;
  13683. }
  13684. for (int index = 0; index < GB_QUANTITY; index++)
  13685. {
  13686. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13687. {
  13688. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13689. }
  13690. }// END OF GB_QUANTITY
  13691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13692. }
  13693. else if(gunType[gun_index] == 'O')
  13694. {
  13695. tempIndex = gun_index;
  13696. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13697. {
  13698. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13699. {
  13700. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13701. }
  13702. }
  13703. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13704. }
  13705. else
  13706. {
  13707. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13708. {
  13709. tempIndex = 2;
  13710. }
  13711. else
  13712. {
  13713. tempIndex = gun_index;
  13714. }
  13715. for (int index = 0; index < AC_QUANTITY; index++)
  13716. {
  13717. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13718. {
  13719. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13720. }
  13721. }// END OF AC_QUANTITY
  13722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13723. }
  13724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13727. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13728. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13730. //2.3====================================== Power.Active.Import =========================================
  13731. //idx_sample=3;
  13732. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13733. if(gunType[gun_index] == 'J')
  13734. {
  13735. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13736. {
  13737. tempIndex = ((gun_index==2) ? 1: 0);
  13738. }
  13739. else
  13740. {
  13741. tempIndex = gun_index;
  13742. }
  13743. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13744. {
  13745. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13746. {
  13747. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13748. }
  13749. } // End for CHAdeMO_QUANTITY
  13750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13751. }
  13752. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13753. {
  13754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13755. {
  13756. tempIndex = ((gun_index==2) ? 1: 0);
  13757. }
  13758. else
  13759. {
  13760. tempIndex = gun_index;
  13761. }
  13762. for (int index = 0; index < CCS_QUANTITY; index++)
  13763. {
  13764. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13765. {
  13766. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13767. }
  13768. } // END for CCS_QUANTITY
  13769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13770. }
  13771. else if(gunType[gun_index] == 'G')
  13772. {
  13773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13774. {
  13775. tempIndex = ((gun_index==2) ? 1: 0);
  13776. }
  13777. else
  13778. {
  13779. tempIndex = gun_index;
  13780. }
  13781. for (int index = 0; index < GB_QUANTITY; index++)
  13782. {
  13783. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13784. {
  13785. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13786. }
  13787. }// END for GB_QUANTITY
  13788. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13789. }
  13790. else if(gunType[gun_index] == 'O')
  13791. {
  13792. tempIndex = gun_index;
  13793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13794. {
  13795. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13796. {
  13797. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13798. }
  13799. }
  13800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13801. }
  13802. else
  13803. {
  13804. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13805. {
  13806. tempIndex = 2;
  13807. }
  13808. else
  13809. {
  13810. tempIndex = gun_index;
  13811. }
  13812. for (int index = 0; index < AC_QUANTITY; index++)
  13813. {
  13814. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13815. {
  13816. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13817. }
  13818. } // END for AC_QUANTITY
  13819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13820. }
  13821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13823. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13824. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13827. //2.4====================================== Voltage L1 ====================================================
  13828. //idx_sample=4;
  13829. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13830. if(gunType[gun_index] == 'J')
  13831. {
  13832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13833. {
  13834. tempIndex = ((gun_index==2) ? 1: 0);
  13835. }
  13836. else
  13837. {
  13838. tempIndex = gun_index;
  13839. }
  13840. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13841. {
  13842. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13843. {
  13844. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13845. }
  13846. } // END OF FOR CHAdeMO_QUANTITY
  13847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13848. }
  13849. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13850. {
  13851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13852. {
  13853. tempIndex = ((gun_index==2) ? 1: 0);
  13854. }
  13855. else
  13856. {
  13857. tempIndex = gun_index;
  13858. }
  13859. for (int index = 0; index < CCS_QUANTITY; index++)
  13860. {
  13861. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13862. {
  13863. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13864. }
  13865. } // END OF FOR CCS_QUANTITY
  13866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13867. }
  13868. else if(gunType[gun_index] == 'G')
  13869. {
  13870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13871. {
  13872. tempIndex = ((gun_index==2) ? 1: 0);
  13873. }
  13874. else
  13875. {
  13876. tempIndex = gun_index;
  13877. }
  13878. for (int index = 0; index < GB_QUANTITY; index++)
  13879. {
  13880. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13881. {
  13882. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13883. }
  13884. } // END OF FOR GB_QUANTITY
  13885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13886. }
  13887. else if(gunType[gun_index] == 'O')
  13888. {
  13889. tempIndex = gun_index;
  13890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13891. {
  13892. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13893. {
  13894. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13895. }
  13896. }
  13897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13898. }
  13899. else
  13900. {
  13901. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13902. {
  13903. tempIndex = 2;
  13904. }
  13905. else
  13906. {
  13907. tempIndex = gun_index;
  13908. }
  13909. for (int index = 0; index < AC_QUANTITY; index++)
  13910. {
  13911. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13912. {
  13913. 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
  13914. }
  13915. } // END OF FOR AC_QUANTITY
  13916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13917. }
  13918. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13921. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13922. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13924. //2.5============================================== End SoC =========================================================
  13925. //idx_sample=5;
  13926. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13927. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  13928. {
  13929. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  13930. {
  13931. tempIndex = ((gun_index==2) ? 1: 0);
  13932. }
  13933. else
  13934. {
  13935. tempIndex = gun_index;
  13936. }
  13937. if(gunType[gun_index] == 'J')
  13938. {
  13939. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13940. {
  13941. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13942. {
  13943. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13944. }
  13945. }
  13946. }
  13947. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13948. {
  13949. for (int index = 0; index < CCS_QUANTITY; index++)
  13950. {
  13951. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13952. {
  13953. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13954. }
  13955. }
  13956. }
  13957. else if(gunType[gun_index] == 'G')
  13958. {
  13959. for (int index = 0; index < GB_QUANTITY; index++)
  13960. {
  13961. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13962. {
  13963. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13964. }
  13965. }
  13966. }
  13967. else if(gunType[gun_index] == 'O')
  13968. {
  13969. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13970. {
  13971. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13972. {
  13973. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  13974. }
  13975. }
  13976. }
  13977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  13982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13983. } // END FOR DC CASE
  13984. //2.6====================================== Current.Import L2 ==============================================
  13985. // idx_sample=6;
  13986. // AC 3 phase L2 current
  13987. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13988. {
  13989. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13990. {
  13991. tempIndex = 2;
  13992. }
  13993. else
  13994. {
  13995. tempIndex = gun_index;
  13996. }
  13997. for (int index = 0; index < AC_QUANTITY; index++)
  13998. {
  13999. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14000. {
  14001. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14002. }
  14003. }// End of for AC_QUANTITY
  14004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14005. }
  14006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14011. //2.7====================================== Current.Import L3 ==============================================
  14012. // idx_sample=7;
  14013. // AC 3 phase L3 current
  14014. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14015. {
  14016. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14017. {
  14018. tempIndex = 2;
  14019. }
  14020. else
  14021. {
  14022. tempIndex = gun_index;
  14023. }
  14024. for (int index = 0; index < AC_QUANTITY; index++)
  14025. {
  14026. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14027. {
  14028. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14029. }
  14030. }// End of for AC_QUANTITY
  14031. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14032. }
  14033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14038. //2.9====================================== Voltage L2 ====================================================
  14039. //idx_sample=8;
  14040. // AC 3 phase L2 volatge
  14041. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14042. {
  14043. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14044. {
  14045. tempIndex = 2;
  14046. }
  14047. else
  14048. {
  14049. tempIndex = gun_index;
  14050. }
  14051. for (int index = 0; index < AC_QUANTITY; index++)
  14052. {
  14053. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14054. {
  14055. 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
  14056. }
  14057. } // END OF FOR AC_QUANTITY
  14058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14059. }
  14060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14065. //2.10====================================== Voltage L3 ====================================================
  14066. //idx_sample=9;
  14067. // AC 3 phase L3 volatge
  14068. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14069. {
  14070. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14071. {
  14072. tempIndex = 2;
  14073. }
  14074. else
  14075. {
  14076. tempIndex = gun_index;
  14077. }
  14078. for (int index = 0; index < AC_QUANTITY; index++)
  14079. {
  14080. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14081. {
  14082. 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
  14083. }
  14084. } // END OF FOR AC_QUANTITY
  14085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14086. }
  14087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14092. //====================== Start SoC ================================
  14093. //idx_sample=10;
  14094. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14095. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  14096. {
  14097. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  14098. {
  14099. tempIndex = ((gun_index==2) ? 1: 0);
  14100. }
  14101. else
  14102. {
  14103. tempIndex = gun_index;
  14104. }
  14105. if(gunType[gun_index] == 'J')
  14106. {
  14107. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14108. {
  14109. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14110. {
  14111. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14112. }
  14113. }
  14114. }
  14115. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  14116. {
  14117. for (int index = 0; index < CCS_QUANTITY; index++)
  14118. {
  14119. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14120. {
  14121. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14122. }
  14123. }
  14124. }
  14125. else if(gunType[gun_index] == 'G')
  14126. {
  14127. for (int index = 0; index < GB_QUANTITY; index++)
  14128. {
  14129. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14130. {
  14131. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14132. }
  14133. }
  14134. }
  14135. else if(gunType[gun_index] == 'O')
  14136. {
  14137. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14138. {
  14139. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14140. {
  14141. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14142. }
  14143. }
  14144. }
  14145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14151. } // END FOR DC CASE
  14152. //======================================== Message create ==============================================
  14153. json_object *StopTransaction = json_object_new_object();
  14154. json_object *transactionDatas = json_object_new_array();
  14155. json_object *sampledValues = json_object_new_array();
  14156. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14157. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14158. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14159. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14160. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14161. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  14162. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14163. {
  14164. json_object *transactionData = json_object_new_object();
  14165. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14166. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14167. {
  14168. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14169. {
  14170. json_object *sampledValue = json_object_new_object();
  14171. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14172. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14173. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14174. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14175. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14176. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14177. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14178. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14179. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14180. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14181. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14182. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14183. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14184. json_object_array_add(sampledValues, sampledValue);
  14185. }
  14186. }
  14187. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14188. json_object_array_add(transactionDatas, transactionData);
  14189. }
  14190. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14191. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14192. ,MESSAGE_TYPE_CALL
  14193. ,guid
  14194. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14195. json_object_put(StopTransaction);
  14196. // Check File "TempStopTransaction" Exist
  14197. if((access(TempStopTransaction,F_OK))!=-1)
  14198. {
  14199. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14200. fclose(fopen(TempStopTransaction, "w"));
  14201. }
  14202. else
  14203. {
  14204. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14205. FILE *log = fopen(TempStopTransaction, "w+");
  14206. if(log == NULL)
  14207. {
  14208. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14209. return ;
  14210. }
  14211. else
  14212. {
  14213. fclose(log);
  14214. }
  14215. }
  14216. //Add TempStopTransaction | Update TempStopTransaction
  14217. // open file for writing
  14218. FILE *outfile;
  14219. outfile = fopen (TempStopTransaction, "a");
  14220. //DEBUG_INFO("data = %s\n", queuedata);
  14221. fputs(queuedata, outfile);
  14222. fputs("\n", outfile);
  14223. fclose (outfile);
  14224. }
  14225. void checkTempStopTransaction(int gun_index)
  14226. {
  14227. FILE *fptr1;
  14228. char ch;
  14229. char str[QUEUE_MESSAGE_LENGTH]={0};
  14230. char guid[37]={0};
  14231. char tempdata[65]={0};
  14232. char connectorStr[2]={0};
  14233. char TempStopTransaction[256];
  14234. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14235. fptr1 = fopen(TempStopTransaction, "r");
  14236. //TempStopTransaction格式: 槍號,StopTransaction封包
  14237. if (!fptr1)
  14238. {
  14239. //printf(" File not found or unable to open the input file!!\n");
  14240. return ;
  14241. }
  14242. ch=fgetc(fptr1);
  14243. //printf(" Now the content of the file %s is : \n",fname);
  14244. rewind(fptr1);
  14245. if(ch!=EOF)
  14246. {
  14247. // copy all contents to the temporary file except the specific line
  14248. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14249. {
  14250. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14251. if(str[0]=='\0')
  14252. {
  14253. break;
  14254. }
  14255. //TempStopTransaction格式: 槍號,StopTransaction封包
  14256. strncpy(connectorStr, str, 1);
  14257. if(atoi(connectorStr) != (gun_index+1))
  14258. {
  14259. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14260. fclose(fptr1);
  14261. return ;
  14262. }
  14263. //random_uuid(guid);
  14264. strncpy(guid, str+6, 36); //copy guid
  14265. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14266. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14267. {
  14268. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14269. }
  14270. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14271. memset(str,0,ARRAY_SIZE(str));
  14272. }
  14273. }
  14274. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14275. fclose(fptr1);
  14276. remove(TempStopTransaction); // remove the original file
  14277. }
  14278. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14279. {
  14280. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14281. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14282. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14283. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14284. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14285. }
  14286. int GetWebSocketPingInterval(void)
  14287. {
  14288. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14289. }
  14290. int GetServerSign(void)
  14291. {
  14292. return server_sign;
  14293. }
  14294. uint8_t GetOcppSecurityProfile()
  14295. {
  14296. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14297. }
  14298. void GetOcppChargerBoxId(uint8_t *data)
  14299. {
  14300. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14301. }
  14302. void GetOcppSecurityPassword(uint8_t *data)
  14303. {
  14304. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14305. }
  14306. void SetOcppVersion(uint8_t *version)
  14307. {
  14308. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  14309. DEBUG_INFO("ocpp version: %s\n", version);
  14310. if(strstr((char*)version, "ocpp1.6") != NULL)
  14311. {
  14312. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  14313. }
  14314. else if(strstr((char*)version, "ocpp2.0") != NULL)
  14315. {
  14316. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  14317. system("pkill OcppBackend");
  14318. }
  14319. }
  14320. void SetServerSign(int value)
  14321. {
  14322. server_sign = value;
  14323. }
  14324. int GetBootNotificationInterval(void)
  14325. {
  14326. return BootNotificationInterval;
  14327. }
  14328. int GetInternetConn(void)
  14329. {
  14330. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14331. }
  14332. void InitialSystemValue(void)
  14333. {
  14334. int connectorIndex = 0;
  14335. //int valueASCII = 0;
  14336. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14337. gunTotalNumber=0;
  14338. SystemInitial = 0;
  14339. localversion=0;
  14340. BootNotificationInterval = 0;
  14341. authorizeRetryTimes = 0;
  14342. GunStatusInterval = 10;
  14343. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14344. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14345. //Hear Beat
  14346. HeartBeatWithNOResponse = 0;
  14347. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14348. FirstHeartBeat = 0;
  14349. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14350. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14351. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14352. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14353. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14354. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14355. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14356. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14357. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14358. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14359. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14360. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14361. memset(gunType, 0, ARRAY_SIZE(gunType));
  14362. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14363. {
  14364. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14365. {
  14366. // DO series
  14367. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14368. {
  14369. SystemInitial = SystemInitial + 1;
  14370. gunTotalNumber = gunTotalNumber + 1;
  14371. gunType[connectorIndex] = 'O';
  14372. connectorIndex = connectorIndex + 1;
  14373. }
  14374. }
  14375. else
  14376. {
  14377. // DM, DW, DS series
  14378. //check connector / socket type (index: 8, 9, 10)
  14379. for(int index=7; index <10 ; index++)
  14380. {
  14381. if(index != 8)
  14382. {
  14383. // DC Connector
  14384. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14385. {
  14386. SystemInitial = SystemInitial + 1;
  14387. gunTotalNumber = gunTotalNumber + 1;
  14388. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14389. connectorIndex = connectorIndex + 1;
  14390. }
  14391. }
  14392. else
  14393. {
  14394. // AC Connector
  14395. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14396. {
  14397. SystemInitial = SystemInitial + 1;
  14398. gunTotalNumber = gunTotalNumber + 1;
  14399. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14400. connectorIndex = connectorIndex + 1;
  14401. }
  14402. }
  14403. }
  14404. }
  14405. //DEBUG_INFO("DC ...\n");
  14406. }
  14407. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14408. {
  14409. //check connector / socket type (index: 8, 9, 10)
  14410. for(int index=7; index <10 ; index++)
  14411. {
  14412. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14413. {
  14414. SystemInitial = SystemInitial + 1;
  14415. gunTotalNumber = gunTotalNumber + 1;
  14416. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14417. connectorIndex = connectorIndex + 1;
  14418. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14419. }
  14420. }
  14421. }
  14422. //Status && ConnectorPlugIn Setting
  14423. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14424. {
  14425. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14426. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14427. }
  14428. for (int index = 0; index < CCS_QUANTITY; index++)
  14429. {
  14430. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14431. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14432. }
  14433. for (int index = 0; index < GB_QUANTITY; index++)
  14434. {
  14435. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14436. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14437. }
  14438. for (int index = 0; index < AC_QUANTITY; index++)
  14439. {
  14440. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14441. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14442. }
  14443. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14444. {
  14445. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14446. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14447. }
  14448. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14449. {
  14450. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14451. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14452. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14453. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14454. }
  14455. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14456. clientTime.Heartbeat=time((time_t*)NULL);
  14457. sleep(1);
  14458. }
  14459. void LWS_Send(char * str)
  14460. {
  14461. //=====================================================
  14462. // Check InternetConn 0: disconnected, 1: connected
  14463. //====================================================
  14464. if(GetOcppConnStatus() == 0)
  14465. {
  14466. DEBUG_INFO("offline now !!!\n");
  14467. return;
  14468. }
  14469. pthread_mutex_lock(&lock_send);
  14470. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14471. sprintf((char *)SendBuffer, "%s", str);
  14472. SendBufLen = strlen(str);
  14473. pthread_mutex_unlock(&lock_send);
  14474. lws_callback_on_writable(wsi_client);
  14475. //lws_service(context, 0);
  14476. //sleep(1);
  14477. }
  14478. void LWS_SendNow(char * str)
  14479. {
  14480. //=====================================================
  14481. // Check InternetConn 0: disconnected, 1: connected
  14482. //====================================================
  14483. if(GetOcppConnStatus() == 0)
  14484. {
  14485. DEBUG_INFO("offline now !!!\n");
  14486. return;
  14487. }
  14488. pthread_mutex_lock(&lock_send);
  14489. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14490. sprintf((char *)SendBuffer, "%s", str);
  14491. SendBufLen = strlen(str);
  14492. pthread_mutex_unlock(&lock_send);
  14493. lws_callback_on_writable(wsi_client);
  14494. lws_service(context, 0);
  14495. //sleep(1);
  14496. }