MessageHandler.c 697 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655
  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 = YES;
  446. struct tm tmStart;
  447. struct timeb tbStart;
  448. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  449. {
  450. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  451. tmStart.tm_year -= 1900;
  452. tmStart.tm_mon -= 1;
  453. tbStart.time = mktime(&tmStart);
  454. tbStart.millitm = 0;
  455. if(DiffTimebWithNowSec(tbStart) <= 0)
  456. result = NO;
  457. }
  458. else
  459. {
  460. DEBUG_WARN("Start date parsing error.\r\n");
  461. }
  462. return result;
  463. }
  464. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  465. {
  466. int result = -1;
  467. struct tm tmStart;
  468. struct timeb tbStart;
  469. struct tm tmStop;
  470. struct timeb tbStop;
  471. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  472. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  473. {
  474. tmStart.tm_year -= 1900;
  475. tmStart.tm_mon -= 1;
  476. tbStart.time = mktime(&tmStart);
  477. tbStart.millitm = 0;
  478. tmStop.tm_year -= 1900;
  479. tmStop.tm_mon -= 1;
  480. tbStop.time = mktime(&tmStop);
  481. tbStop.millitm = 0;
  482. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  483. }
  484. return result;
  485. }
  486. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  487. {
  488. FILE *fp;
  489. char profileFileName[128];
  490. char *line = NULL;
  491. size_t len = 0;
  492. time_t CurrentTime;
  493. struct tm *tmComposite;
  494. struct StructChargingProfile maxProfile;
  495. struct StructChargingProfile defaultTxProfile;
  496. struct StructChargingProfile txProfile;
  497. struct StructChargingSchedulePeriod tmpPeriod;
  498. uint8_t limitMax=0;
  499. uint8_t limitDef=0;
  500. uint8_t limitTx=0;
  501. int compositePeriodIdx = 0;
  502. CurrentTime = time(NULL);
  503. tmComposite=localtime(&CurrentTime);
  504. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  505. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  506. compositeProfile->ChargingSchedule.Duration = durationReq;
  507. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  508. {
  509. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  510. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  511. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  512. }
  513. compositeProfile->ChargingProfileId = 0;
  514. compositeProfile->StackLevel = 99 ;
  515. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  516. maxProfile.ChargingProfileId = -1;
  517. defaultTxProfile.ChargingProfileId = -1;
  518. txProfile.ChargingProfileId = -1;
  519. maxProfile.ChargingSchedule.Duration = -1;
  520. defaultTxProfile.ChargingSchedule.Duration = -1;
  521. txProfile.ChargingSchedule.Duration = -1;
  522. system("yes|rm /tmp/*.json");
  523. system("cp /Storage/OCPP/*.json /tmp");
  524. /*
  525. * Search valid charging profile
  526. */
  527. //DEBUG_INFO("====================================\n");
  528. // Search tx profile
  529. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  530. if((access(profileFileName, F_OK))!=-1)
  531. {
  532. fp = fopen(profileFileName, "r");
  533. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  534. {
  535. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  536. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  538. }
  539. txProfile.ChargingProfileId = -1;
  540. txProfile.StackLevel = -1;
  541. while(getline(&line, &len, fp) != -1)
  542. {
  543. json_object *obj = NULL;
  544. obj = json_tokener_parse(line);
  545. if(is_error(obj))
  546. {
  547. DEBUG_ERROR("Parse txProfile from file error.\n");
  548. }
  549. else
  550. {
  551. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  552. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  553. )
  554. {
  555. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  556. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  557. )
  558. {
  559. struct tm tmFrom, tmTo;
  560. struct timeb tbFrom, tbTo;
  561. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  562. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  563. {
  564. tmFrom.tm_year -= 1900;
  565. tmFrom.tm_mon -= 1;
  566. tbFrom.time = mktime(&tmFrom);
  567. tmTo.tm_year -= 1900;
  568. tmTo.tm_mon -= 1;
  569. tbTo.time = mktime(&tmTo);
  570. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  571. {
  572. if(txProfile.ChargingProfileId == -1)
  573. DEBUG_INFO("TxProfile found.\n");
  574. else
  575. DEBUG_INFO("TxProfile updated.\n");
  576. // Required item
  577. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  578. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  579. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  580. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  581. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  582. {
  583. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  584. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  585. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  586. 3:
  587. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  588. }
  589. // Optional item
  590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  591. {
  592. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  593. }
  594. else
  595. {
  596. sprintf((char*)txProfile.ValidFrom, " ");
  597. }
  598. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  599. {
  600. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  601. }
  602. else
  603. {
  604. sprintf((char*)txProfile.ValidTo, " ");
  605. }
  606. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  607. {
  608. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  609. }
  610. else
  611. {
  612. sprintf((char*)txProfile.RecurrencyKind, " ");
  613. }
  614. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  615. {
  616. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  617. }
  618. else
  619. {
  620. txProfile.TransactionId = -1;
  621. }
  622. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  623. {
  624. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  625. }
  626. else
  627. {
  628. txProfile.ChargingSchedule.Duration = 86400;
  629. }
  630. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  631. {
  632. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  633. }
  634. else
  635. {
  636. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  637. }
  638. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  639. {
  640. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  641. }
  642. else
  643. {
  644. txProfile.ChargingSchedule.MinChargingRate = -1;
  645. }
  646. }
  647. }
  648. }
  649. else
  650. {
  651. if(txProfile.ChargingProfileId == -1)
  652. DEBUG_INFO("TxProfile found.\n");
  653. else
  654. DEBUG_INFO("TxProfile updated.\n");
  655. // Required item
  656. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  657. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  658. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  659. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  660. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  661. {
  662. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  663. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  664. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  665. 3:
  666. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  667. }
  668. // Optional item
  669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  670. {
  671. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  672. }
  673. else
  674. {
  675. sprintf((char*)txProfile.ValidFrom, " ");
  676. }
  677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  678. {
  679. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  680. }
  681. else
  682. {
  683. sprintf((char*)txProfile.ValidTo, " ");
  684. }
  685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  686. {
  687. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  688. }
  689. else
  690. {
  691. sprintf((char*)txProfile.RecurrencyKind, " ");
  692. }
  693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  694. {
  695. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  696. }
  697. else
  698. {
  699. txProfile.TransactionId = -1;
  700. }
  701. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  702. {
  703. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  704. }
  705. else
  706. {
  707. txProfile.ChargingSchedule.Duration = 86400;
  708. }
  709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  710. {
  711. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  712. }
  713. else
  714. {
  715. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  716. }
  717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  718. {
  719. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  720. }
  721. else
  722. {
  723. txProfile.ChargingSchedule.MinChargingRate = -1;
  724. }
  725. }
  726. }
  727. }
  728. json_object_put(obj);
  729. }
  730. fclose(fp);
  731. /*
  732. if(txProfile.ChargingProfileId != -1)
  733. {
  734. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  735. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  736. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  737. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  738. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  739. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  740. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  741. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  742. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  743. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  744. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  745. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  746. {
  747. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  748. {
  749. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  750. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  751. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  752. }
  753. }
  754. }
  755. else
  756. DEBUG_INFO("TxProfile not found.\n");*/
  757. }
  758. // Search default tx profile
  759. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  760. if((access(profileFileName, F_OK))==-1)
  761. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  762. if((access(profileFileName, F_OK))!=-1)
  763. {
  764. fp = fopen(profileFileName, "r");
  765. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  766. {
  767. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  768. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  769. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  770. }
  771. defaultTxProfile.ChargingProfileId = -1;
  772. defaultTxProfile.StackLevel = -1;
  773. while(getline(&line, &len, fp) != -1)
  774. {
  775. json_object *obj = NULL;
  776. obj = json_tokener_parse(line);
  777. if(is_error(obj))
  778. {
  779. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  780. }
  781. else
  782. {
  783. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  784. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  785. )
  786. {
  787. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  788. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  789. )
  790. {
  791. struct tm tmFrom, tmTo;
  792. struct timeb tbFrom, tbTo;
  793. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  794. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  795. {
  796. tmFrom.tm_year -= 1900;
  797. tmFrom.tm_mon -= 1;
  798. tbFrom.time = mktime(&tmFrom);
  799. tmTo.tm_year -= 1900;
  800. tmTo.tm_mon -= 1;
  801. tbTo.time = mktime(&tmTo);
  802. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  803. {
  804. if(defaultTxProfile.ChargingProfileId == -1)
  805. DEBUG_INFO("TxDefaultProfile found.\n");
  806. else
  807. DEBUG_INFO("TxDefaultProfile updated.\n");
  808. // Required item
  809. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  810. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  811. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  812. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  813. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  814. {
  815. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  816. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  817. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  818. 3:
  819. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  820. }
  821. // Optional item
  822. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  823. {
  824. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  825. }
  826. else
  827. {
  828. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  829. }
  830. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  831. {
  832. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  833. }
  834. else
  835. {
  836. sprintf((char*)defaultTxProfile.ValidTo, " ");
  837. }
  838. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  839. {
  840. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  841. }
  842. else
  843. {
  844. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  845. }
  846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  847. {
  848. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  849. }
  850. else
  851. {
  852. defaultTxProfile.TransactionId = -1;
  853. }
  854. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  855. {
  856. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  857. }
  858. else
  859. {
  860. defaultTxProfile.ChargingSchedule.Duration = 86400;
  861. }
  862. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  863. {
  864. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  865. }
  866. else
  867. {
  868. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  869. }
  870. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  871. {
  872. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  873. }
  874. else
  875. {
  876. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  877. }
  878. }
  879. }
  880. }
  881. else
  882. {
  883. if(defaultTxProfile.ChargingProfileId == -1)
  884. DEBUG_INFO("TxDefaultProfile found.\n");
  885. else
  886. DEBUG_INFO("TxDefaultProfile updated.\n");
  887. // Required item
  888. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  889. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  890. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  891. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  892. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  893. {
  894. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  895. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  896. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  897. 3:
  898. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  899. }
  900. // Optional item
  901. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  902. {
  903. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  904. }
  905. else
  906. {
  907. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  908. }
  909. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  910. {
  911. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  912. }
  913. else
  914. {
  915. sprintf((char*)defaultTxProfile.ValidTo, " ");
  916. }
  917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  918. {
  919. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  920. }
  921. else
  922. {
  923. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  924. }
  925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  926. {
  927. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  928. }
  929. else
  930. {
  931. defaultTxProfile.TransactionId = -1;
  932. }
  933. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  934. {
  935. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  936. }
  937. else
  938. {
  939. defaultTxProfile.ChargingSchedule.Duration = 86400;
  940. }
  941. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  942. {
  943. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  944. }
  945. else
  946. {
  947. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  948. }
  949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  950. {
  951. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  952. }
  953. else
  954. {
  955. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  956. }
  957. }
  958. }
  959. }
  960. json_object_put(obj);
  961. }
  962. fclose(fp);
  963. /*
  964. if(defaultTxProfile.ChargingProfileId != -1)
  965. {
  966. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  967. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  968. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  969. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  970. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  971. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  972. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  973. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  974. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  975. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  976. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  977. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  978. {
  979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  980. {
  981. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  982. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  983. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  984. }
  985. }
  986. }
  987. else
  988. DEBUG_INFO("TxDefaultProfile not found.\n");
  989. DEBUG_INFO("------------------------------------\n");*/
  990. }
  991. // Search max profile
  992. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  993. if((access(profileFileName, F_OK))!=-1)
  994. {
  995. fp = fopen(profileFileName, "r");
  996. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  997. {
  998. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  999. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1001. }
  1002. maxProfile.ChargingProfileId = -1;
  1003. maxProfile.StackLevel = -1;
  1004. while(getline(&line, &len, fp) != -1)
  1005. {
  1006. json_object *obj = NULL;
  1007. obj = json_tokener_parse(line);
  1008. if(is_error(obj))
  1009. {
  1010. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1011. }
  1012. else
  1013. {
  1014. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1015. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1016. )
  1017. {
  1018. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1019. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1020. )
  1021. {
  1022. struct tm tmFrom, tmTo;
  1023. struct timeb tbFrom, tbTo;
  1024. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1025. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1026. {
  1027. tmFrom.tm_year -= 1900;
  1028. tmFrom.tm_mon -= 1;
  1029. tbFrom.time = mktime(&tmFrom);
  1030. tmTo.tm_year -= 1900;
  1031. tmTo.tm_mon -= 1;
  1032. tbTo.time = mktime(&tmTo);
  1033. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1034. {
  1035. if(maxProfile.ChargingProfileId == -1)
  1036. DEBUG_INFO("MaxProfile found.\n");
  1037. else
  1038. DEBUG_INFO("MaxProfile updated.\n");
  1039. // Required item
  1040. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1041. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1042. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1043. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1044. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1045. {
  1046. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1047. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1048. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1049. 3:
  1050. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1051. }
  1052. // Optional item
  1053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1054. {
  1055. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1056. }
  1057. else
  1058. {
  1059. sprintf((char*)maxProfile.ValidFrom, " ");
  1060. }
  1061. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1062. {
  1063. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1064. }
  1065. else
  1066. {
  1067. sprintf((char*)maxProfile.ValidTo, " ");
  1068. }
  1069. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1070. {
  1071. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1072. }
  1073. else
  1074. {
  1075. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1076. }
  1077. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1078. {
  1079. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1080. }
  1081. else
  1082. {
  1083. maxProfile.TransactionId = -1;
  1084. }
  1085. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1086. {
  1087. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1088. }
  1089. else
  1090. {
  1091. maxProfile.ChargingSchedule.Duration = 86400;
  1092. }
  1093. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1094. {
  1095. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1096. }
  1097. else
  1098. {
  1099. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1100. }
  1101. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1102. {
  1103. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1104. }
  1105. else
  1106. {
  1107. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1108. }
  1109. }
  1110. }
  1111. }
  1112. else
  1113. {
  1114. if(maxProfile.ChargingProfileId == -1)
  1115. DEBUG_INFO("MaxProfile found.\n");
  1116. else
  1117. DEBUG_INFO("MaxProfile updated.\n");
  1118. // Required item
  1119. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1120. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1121. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1122. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1123. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1124. {
  1125. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1126. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1127. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1128. 3:
  1129. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1130. }
  1131. // Optional item
  1132. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1133. {
  1134. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1135. }
  1136. else
  1137. {
  1138. sprintf((char*)maxProfile.ValidFrom, " ");
  1139. }
  1140. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1141. {
  1142. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1143. }
  1144. else
  1145. {
  1146. sprintf((char*)maxProfile.ValidTo, " ");
  1147. }
  1148. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1149. {
  1150. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1151. }
  1152. else
  1153. {
  1154. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1155. }
  1156. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1157. {
  1158. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1159. }
  1160. else
  1161. {
  1162. maxProfile.TransactionId = -1;
  1163. }
  1164. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1165. {
  1166. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1167. }
  1168. else
  1169. {
  1170. maxProfile.ChargingSchedule.Duration = 86400;
  1171. }
  1172. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1173. {
  1174. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1175. }
  1176. else
  1177. {
  1178. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1179. }
  1180. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1181. {
  1182. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1183. }
  1184. else
  1185. {
  1186. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1187. }
  1188. }
  1189. }
  1190. }
  1191. json_object_put(obj);
  1192. }
  1193. fclose(fp);
  1194. /*
  1195. if(maxProfile.ChargingProfileId !=-1)
  1196. {
  1197. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1198. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1199. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1200. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1201. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1202. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1203. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1204. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1205. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1206. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1207. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1208. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1209. {
  1210. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1211. {
  1212. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1213. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1214. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1215. }
  1216. }
  1217. }
  1218. else
  1219. DEBUG_INFO("MaxProfile not found.\n");
  1220. DEBUG_INFO("------------------------------------\n");*/
  1221. }
  1222. /*
  1223. * Align found profile start schedule & periods
  1224. */
  1225. //DEBUG_INFO("====================================\n");
  1226. /*
  1227. // For local test usage, force modify found profile start schedule info
  1228. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1229. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1230. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1231. */
  1232. if(txProfile.ChargingProfileId != -1)
  1233. {
  1234. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1235. {
  1236. if(txProfile.ChargingSchedule.Duration != -1)
  1237. {
  1238. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1239. 0:
  1240. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1241. }
  1242. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1243. {
  1244. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1245. {
  1246. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1247. 0:
  1248. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1249. if(idxPeriod > 0)
  1250. {
  1251. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1252. {
  1253. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1260. {
  1261. if(txProfile.ChargingSchedule.Duration != -1)
  1262. {
  1263. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1264. 0:
  1265. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1266. }
  1267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1268. {
  1269. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1270. {
  1271. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1272. 0:
  1273. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1274. if(idxPeriod > 0)
  1275. {
  1276. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1277. {
  1278. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1279. }
  1280. }
  1281. }
  1282. }
  1283. }
  1284. else
  1285. {
  1286. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1287. {
  1288. if(txProfile.ChargingSchedule.Duration != -1)
  1289. {
  1290. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1291. 0:
  1292. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1293. }
  1294. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1295. {
  1296. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1297. {
  1298. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1299. 0:
  1300. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1301. if(idxPeriod > 0)
  1302. {
  1303. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1304. {
  1305. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. else
  1312. {
  1313. if(txProfile.ChargingSchedule.Duration != -1)
  1314. {
  1315. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1316. 0:
  1317. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1318. }
  1319. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1320. {
  1321. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1322. {
  1323. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1324. 0:
  1325. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1326. if(idxPeriod > 0)
  1327. {
  1328. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1329. {
  1330. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. /*
  1338. DEBUG_INFO("txProfile after align.\n");
  1339. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1340. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1341. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1342. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1343. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1344. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1345. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1346. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1347. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1348. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1349. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1350. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1351. {
  1352. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1353. {
  1354. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1355. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1356. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1357. }
  1358. }*/
  1359. }
  1360. if(defaultTxProfile.ChargingProfileId != -1)
  1361. {
  1362. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1363. {
  1364. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1365. {
  1366. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1367. 0:
  1368. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1369. }
  1370. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1371. {
  1372. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1373. {
  1374. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1375. 0:
  1376. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1378. {
  1379. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1380. }
  1381. if(idxPeriod > 0)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1384. {
  1385. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1386. }
  1387. }
  1388. }
  1389. }
  1390. }
  1391. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1392. {
  1393. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1394. {
  1395. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1396. 0:
  1397. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1398. }
  1399. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1400. {
  1401. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1402. {
  1403. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1404. 0:
  1405. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1406. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1407. {
  1408. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1409. }
  1410. if(idxPeriod > 0)
  1411. {
  1412. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1413. {
  1414. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1415. }
  1416. }
  1417. }
  1418. }
  1419. }
  1420. else
  1421. {
  1422. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1423. {
  1424. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1425. {
  1426. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1427. 0:
  1428. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1429. }
  1430. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1431. {
  1432. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1433. {
  1434. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1435. 0:
  1436. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1437. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1438. {
  1439. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1440. }
  1441. if(idxPeriod > 0)
  1442. {
  1443. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1444. {
  1445. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1446. }
  1447. }
  1448. }
  1449. }
  1450. }
  1451. else
  1452. {
  1453. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1454. {
  1455. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1456. 0:
  1457. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1458. }
  1459. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1460. {
  1461. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1462. {
  1463. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1464. 0:
  1465. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1466. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1467. {
  1468. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1469. }
  1470. if(idxPeriod > 0)
  1471. {
  1472. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1473. {
  1474. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1475. }
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. /*
  1482. DEBUG_INFO("defaultTxProfile after align.\n");
  1483. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1484. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1485. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1486. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1487. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1488. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1489. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1490. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1491. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1492. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1493. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1495. {
  1496. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1497. {
  1498. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1499. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1500. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1501. }
  1502. }
  1503. DEBUG_INFO("------------------------------------\n");*/
  1504. }
  1505. if(maxProfile.ChargingProfileId != -1)
  1506. {
  1507. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1508. {
  1509. if(maxProfile.ChargingSchedule.Duration != -1)
  1510. {
  1511. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1512. 0:
  1513. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1514. }
  1515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1516. {
  1517. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1518. {
  1519. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1520. 0:
  1521. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1522. if(idxPeriod > 0)
  1523. {
  1524. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1525. {
  1526. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. }
  1532. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1533. {
  1534. if(maxProfile.ChargingSchedule.Duration != -1)
  1535. {
  1536. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1537. 0:
  1538. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1539. }
  1540. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1541. {
  1542. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1543. {
  1544. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1545. 0:
  1546. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1547. if(idxPeriod > 0)
  1548. {
  1549. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1550. {
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1552. }
  1553. }
  1554. }
  1555. }
  1556. }
  1557. else
  1558. {
  1559. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1560. {
  1561. if(maxProfile.ChargingSchedule.Duration != -1)
  1562. {
  1563. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1564. 0:
  1565. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1566. }
  1567. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1568. {
  1569. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1570. {
  1571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1572. 0:
  1573. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1574. if(idxPeriod > 0)
  1575. {
  1576. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1577. {
  1578. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1579. }
  1580. }
  1581. }
  1582. }
  1583. }
  1584. else
  1585. {
  1586. if(maxProfile.ChargingSchedule.Duration != -1)
  1587. {
  1588. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1589. 0:
  1590. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1591. }
  1592. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1593. {
  1594. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1595. {
  1596. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1597. 0:
  1598. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1599. if(idxPeriod > 0)
  1600. {
  1601. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1602. {
  1603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1604. }
  1605. }
  1606. }
  1607. }
  1608. }
  1609. }
  1610. /*
  1611. DEBUG_INFO("MaxProfile after align.\n");
  1612. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1613. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1614. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1615. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1616. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1617. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1618. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1619. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1620. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1621. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1622. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1623. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1624. {
  1625. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1626. {
  1627. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1628. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1629. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1630. }
  1631. }
  1632. DEBUG_INFO("------------------------------------\n");*/
  1633. }
  1634. /*
  1635. * Merge to conposite schedule
  1636. */
  1637. //DEBUG_INFO("====================================\n");
  1638. // Find each profile period quantity
  1639. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1640. {
  1641. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1642. limitMax = idx+1;
  1643. }
  1644. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1645. {
  1646. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1647. limitDef = idx+1;
  1648. }
  1649. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1650. {
  1651. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1652. limitTx = idx+1;
  1653. }
  1654. // TxProfile found, composite schedule based on it
  1655. if(txProfile.ChargingProfileId != -1)
  1656. {
  1657. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1658. {
  1659. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1660. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1661. (txProfile.ChargingSchedule.Duration > 0))
  1662. {
  1663. if(maxProfile.ChargingProfileId != -1)
  1664. {
  1665. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1666. {
  1667. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1668. {
  1669. if((maxProfile.ChargingSchedule.Duration > 0))
  1670. {
  1671. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1672. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1673. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1674. }
  1675. else
  1676. {
  1677. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1678. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1679. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1680. }
  1681. }
  1682. if(idxMaxPeriod == (limitMax-1))
  1683. {
  1684. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1685. {
  1686. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1687. {
  1688. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1689. compositePeriodIdx++;
  1690. }
  1691. else
  1692. {
  1693. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1694. }
  1695. }
  1696. }
  1697. }
  1698. }
  1699. else
  1700. {
  1701. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1702. {
  1703. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1704. compositePeriodIdx++;
  1705. }
  1706. else
  1707. {
  1708. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1709. }
  1710. }
  1711. }
  1712. if(idxTxPeriod == (limitTx-1))
  1713. {
  1714. if(defaultTxProfile.ChargingProfileId != -1)
  1715. {
  1716. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1717. {
  1718. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1719. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1720. (defaultTxProfile.ChargingSchedule.Duration>0))
  1721. {
  1722. if(maxProfile.ChargingProfileId != -1)
  1723. {
  1724. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1725. {
  1726. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1727. {
  1728. if((maxProfile.ChargingSchedule.Duration > 0))
  1729. {
  1730. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1731. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1732. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1733. }
  1734. else
  1735. {
  1736. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1737. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1738. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1739. }
  1740. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1741. {
  1742. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1743. {
  1744. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1745. compositePeriodIdx++;
  1746. }
  1747. else
  1748. {
  1749. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1750. }
  1751. }
  1752. break;
  1753. }
  1754. }
  1755. }
  1756. else
  1757. {
  1758. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1759. {
  1760. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1761. compositePeriodIdx++;
  1762. }
  1763. else
  1764. {
  1765. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. }
  1772. }
  1773. }
  1774. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1775. else if(defaultTxProfile.ChargingProfileId != -1)
  1776. {
  1777. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1778. {
  1779. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1780. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1781. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1782. {
  1783. if(maxProfile.ChargingProfileId != -1)
  1784. {
  1785. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1786. {
  1787. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1788. {
  1789. if((maxProfile.ChargingSchedule.Duration > 0))
  1790. {
  1791. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1792. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1793. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1794. }
  1795. else
  1796. {
  1797. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1798. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1799. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1800. }
  1801. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1802. {
  1803. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1804. {
  1805. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1806. compositePeriodIdx++;
  1807. }
  1808. else
  1809. {
  1810. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1811. }
  1812. }
  1813. break;
  1814. }
  1815. }
  1816. }
  1817. else
  1818. {
  1819. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1820. {
  1821. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1822. compositePeriodIdx++;
  1823. }
  1824. else
  1825. {
  1826. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. // Fill other period by MaxProfile
  1833. if(maxProfile.ChargingProfileId != -1)
  1834. {
  1835. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1836. {
  1837. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1838. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1839. (maxProfile.ChargingSchedule.Duration > 0))
  1840. {
  1841. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1842. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1843. {
  1844. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1845. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1846. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1847. }
  1848. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1849. {
  1850. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1851. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1852. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1853. }
  1854. if(tmpPeriod.Limit != -1)
  1855. {
  1856. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1857. {
  1858. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1859. {
  1860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1861. compositePeriodIdx++;
  1862. }
  1863. else
  1864. {
  1865. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  1873. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1874. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1875. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1876. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1877. {
  1878. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1879. {
  1880. compositeProfile->ChargingProfileId = 1;
  1881. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1882. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1883. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1884. }
  1885. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1886. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1887. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1888. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1889. }
  1890. if(line)
  1891. free(line);
  1892. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  1893. }
  1894. //==========================================
  1895. // Init all share memory
  1896. //==========================================
  1897. int InitShareMemory()
  1898. {
  1899. int result = PASS;
  1900. int MeterSMId;
  1901. //creat ShmSysConfigAndInfo
  1902. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1903. {
  1904. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1905. result = FAIL;
  1906. }
  1907. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1908. {
  1909. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1910. result = FAIL;
  1911. }
  1912. else
  1913. {}
  1914. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1915. {
  1916. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1917. result = FAIL;
  1918. }
  1919. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1920. {
  1921. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1922. result = FAIL;
  1923. }
  1924. else
  1925. {}
  1926. //creat ShmPsuData
  1927. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1928. {
  1929. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1930. result = FAIL;
  1931. }
  1932. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1933. {
  1934. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1935. result = FAIL;
  1936. }
  1937. else
  1938. {}
  1939. //creat ShmOCPP16Data
  1940. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1941. {
  1942. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1943. result = FAIL;
  1944. }
  1945. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1946. {
  1947. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1948. result = FAIL;
  1949. }
  1950. else
  1951. {}
  1952. /****************************** For Initial Settings************************************************/
  1953. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1954. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1955. // allocate Configuration memory address
  1956. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1957. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1958. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1959. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1960. //offline MeterValue Interval
  1961. TempMeterValueInterval = 0;
  1962. return result;
  1963. }
  1964. int ProcessShareMemory()
  1965. {
  1966. if(InitShareMemory() == FAIL)
  1967. {
  1968. DEBUG_ERROR("InitShareMemory NG\n");
  1969. if(ShmStatusCodeData!=NULL)
  1970. {
  1971. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1972. }
  1973. sleep(5);
  1974. return FAIL;
  1975. }
  1976. return PASS;
  1977. }
  1978. //---------------------common routine---------------------------//
  1979. //---------------------------------------------
  1980. // new:
  1981. // enum SYSTEM_STATUS
  1982. // {
  1983. // SYS_MODE_BOOTING = 0,
  1984. // SYS_MODE_IDLE = 1,
  1985. // SYS_MODE_AUTHORIZING = 2,
  1986. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1987. // SYS_MODE_REASSIGN = 4,
  1988. // SYS_MODE_PREPARING = 5,
  1989. // SYS_MODE_PREPARE_FOR_EV = 6,
  1990. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1991. // SYS_MODE_CHARGING = 8,
  1992. // SYS_MODE_TERMINATING = 9,
  1993. // SYS_MODE_COMPLETE = 10,
  1994. // SYS_MODE_ALARM = 11,
  1995. // SYS_MODE_FAULT = 12,
  1996. // SYS_MODE_RESERVATION = 13,
  1997. // SYS_MODE_BOOKING = 14,
  1998. // SYS_MODE_MAINTAIN = 15,
  1999. // SYS_MODE_DEBUG = 16,
  2000. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2001. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2002. // SYS_MODE_UPDATE = 19
  2003. // };
  2004. //
  2005. //
  2006. //-----------------------------------------
  2007. void CheckSystemValue(void)
  2008. {
  2009. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2010. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2011. char filenmae[100]={0};
  2012. char str[100]={0};
  2013. int tempIndex = 0;
  2014. //===============================
  2015. // send Heartbeat
  2016. //===============================
  2017. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2018. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2019. {
  2020. clientTime.Heartbeat=time((time_t*)NULL);
  2021. if(server_sign == TRUE)
  2022. {
  2023. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2024. }
  2025. else
  2026. {
  2027. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2028. }
  2029. }
  2030. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2031. {
  2032. //parameter for test
  2033. sendHeartbeatRequest(0);
  2034. //==============================================
  2035. // Reset Waiting Time
  2036. //==============================================
  2037. HeartBeatWithNOResponse += 1;
  2038. }
  2039. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2040. {
  2041. //==========================================
  2042. // csu trigger DataTransferReq
  2043. //==========================================
  2044. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2045. {
  2046. sendDataTransferRequest(gun_index);
  2047. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2048. }
  2049. //===============================
  2050. // CSU Trigger Reset Conf
  2051. //===============================
  2052. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2053. {
  2054. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2055. }
  2056. //===============================
  2057. // CSU Trigger Authorize Request
  2058. //===============================
  2059. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2060. {
  2061. sendAuthorizeRequest(0);
  2062. authorizeRetryTimes = authorizeRetryTimes + 1;
  2063. if(authorizeRetryTimes < 3)
  2064. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2065. }
  2066. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2067. {
  2068. authorizeRetryTimes = 0;
  2069. SetOcppConnStatus(FALSE);
  2070. server_sign = FALSE;
  2071. }
  2072. 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))
  2073. {
  2074. sendAuthorizeRequest(0);
  2075. }
  2076. //===============================
  2077. // CSU Trigger Smart Charging Profilw
  2078. //===============================
  2079. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2080. {
  2081. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2082. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2083. }
  2084. //==============================================
  2085. // Charger start transaction
  2086. //==============================================
  2087. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2088. {
  2089. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2090. sendStartTransactionRequest(gun_index);
  2091. clientTime.StartTransaction = time((time_t*)NULL);
  2092. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2093. storeTempStopTransaction(gun_index);
  2094. }
  2095. //==============================================
  2096. // Charger stop transaction
  2097. //==============================================
  2098. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2099. {
  2100. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2101. sendStopTransactionRequest(gun_index);
  2102. clientTime.StopTransaction = time((time_t*)NULL);
  2103. }
  2104. //==============================================
  2105. // Charger status report
  2106. //==============================================
  2107. //--- Check Mode Change ---//
  2108. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2109. if(gunType[gun_index] == 'J')
  2110. {
  2111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2112. {
  2113. tempIndex = ((gun_index==2) ? 1: 0);
  2114. }
  2115. else
  2116. {
  2117. tempIndex = gun_index;
  2118. }
  2119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2120. {
  2121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2122. {
  2123. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2124. {
  2125. // Sent unplug message for California pricing logic
  2126. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2127. {
  2128. uint8_t ts[20];
  2129. getNowDatetime(ts);
  2130. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2131. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2132. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2133. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2134. }
  2135. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2136. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2137. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2138. statusModeChage[gun_index] = TRUE;
  2139. }
  2140. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2141. {
  2142. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2143. if((access(filenmae,F_OK))!=-1)
  2144. {
  2145. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2146. sprintf(str,"rm -f %s",filenmae);
  2147. system(str);
  2148. }
  2149. }
  2150. #if 1 // for TempStopTransaction
  2151. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2152. {
  2153. checkTempStopTransaction(gun_index);
  2154. }
  2155. #endif
  2156. }
  2157. }
  2158. }
  2159. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2160. {
  2161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2162. {
  2163. tempIndex = ((gun_index==2) ? 1: 0);
  2164. }
  2165. else
  2166. {
  2167. tempIndex = gun_index;
  2168. }
  2169. for (int index = 0; index < CCS_QUANTITY; index++)
  2170. {
  2171. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2172. {
  2173. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2174. {
  2175. // Sent unplug message for California pricing logic
  2176. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2177. {
  2178. uint8_t ts[20];
  2179. getNowDatetime(ts);
  2180. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2181. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2182. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2183. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2184. }
  2185. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2186. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2187. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2188. statusModeChage[gun_index] = TRUE;
  2189. }
  2190. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2191. {
  2192. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2193. if((access(filenmae,F_OK))!=-1)
  2194. {
  2195. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2196. sprintf(str,"rm -f %s",filenmae);
  2197. system(str);
  2198. }
  2199. }
  2200. #if 1 // for TempStopTransaction
  2201. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2202. {
  2203. checkTempStopTransaction(gun_index);
  2204. }
  2205. #endif
  2206. }
  2207. }
  2208. }
  2209. else if(gunType[gun_index] == 'G')
  2210. {
  2211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2212. {
  2213. tempIndex = ((gun_index==2) ? 1: 0);
  2214. }
  2215. else
  2216. {
  2217. tempIndex = gun_index;
  2218. }
  2219. for (int index = 0; index < GB_QUANTITY; index++)
  2220. {
  2221. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2222. {
  2223. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2224. {
  2225. // Sent unplug message for California pricing logic
  2226. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2227. {
  2228. uint8_t ts[20];
  2229. getNowDatetime(ts);
  2230. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2231. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2232. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2233. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2234. }
  2235. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2236. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2237. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2238. statusModeChage[gun_index] = TRUE;
  2239. }
  2240. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2241. {
  2242. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2243. if((access(filenmae,F_OK))!=-1)
  2244. {
  2245. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2246. sprintf(str,"rm -f %s",filenmae);
  2247. system(str);
  2248. }
  2249. }
  2250. #if 1 // for TempStopTransaction
  2251. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2252. {
  2253. checkTempStopTransaction(gun_index);
  2254. }
  2255. #endif
  2256. }
  2257. }
  2258. }
  2259. else if(gunType[gun_index] == 'O')
  2260. {
  2261. tempIndex = gun_index;
  2262. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2263. {
  2264. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2265. {
  2266. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2267. {
  2268. // Sent unplug message for California pricing logic
  2269. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2270. {
  2271. uint8_t ts[20];
  2272. getNowDatetime(ts);
  2273. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2274. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2275. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2276. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2277. }
  2278. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2279. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2280. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2281. statusModeChage[gun_index] = TRUE;
  2282. }
  2283. 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
  2284. {
  2285. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2286. if((access(filenmae,F_OK))!=-1)
  2287. {
  2288. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2289. sprintf(str,"rm -f %s",filenmae);
  2290. system(str);
  2291. }
  2292. }
  2293. #if 1 // for TempStopTransaction
  2294. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2295. {
  2296. checkTempStopTransaction(gun_index);
  2297. }
  2298. #endif
  2299. }
  2300. }
  2301. }
  2302. else
  2303. {
  2304. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2305. {
  2306. tempIndex = 2;
  2307. }
  2308. else
  2309. {
  2310. tempIndex = gun_index;
  2311. }
  2312. for (int index = 0; index < AC_QUANTITY; index++)
  2313. {
  2314. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2315. {
  2316. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2317. {
  2318. // Sent unplug message for California pricing logic
  2319. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2320. {
  2321. uint8_t ts[20];
  2322. getNowDatetime(ts);
  2323. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2324. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2325. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2326. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2327. }
  2328. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2329. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2330. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2331. statusModeChage[gun_index] = TRUE;
  2332. }
  2333. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2334. {
  2335. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2336. if((access(filenmae,F_OK))!=-1)
  2337. {
  2338. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2339. sprintf(str,"rm -f %s",filenmae);
  2340. system(str);
  2341. }
  2342. }
  2343. #if 1 // for TempStopTransaction
  2344. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2345. {
  2346. checkTempStopTransaction(gun_index);
  2347. }
  2348. #endif
  2349. }
  2350. }// END
  2351. }
  2352. if(isWebsocketSendable &&
  2353. (
  2354. (statusModeChage[gun_index] == TRUE) ||
  2355. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2356. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2357. )
  2358. )
  2359. {
  2360. if(SystemInitial > 0)
  2361. SystemInitial -= 1;
  2362. sendStatusNotificationRequest(gun_index);
  2363. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2364. statusModeChage[gun_index] = FALSE;
  2365. }
  2366. //==============================================
  2367. // Meter report
  2368. //==============================================
  2369. // Trigger MeterValue
  2370. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2371. {
  2372. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2373. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2374. }
  2375. // ClockAlign MeterValue
  2376. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2377. {
  2378. if(gunType[gun_index] == 'J')
  2379. {
  2380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2381. {
  2382. tempIndex = ((gun_index==2) ? 1: 0);
  2383. }
  2384. else
  2385. {
  2386. tempIndex = gun_index;
  2387. }
  2388. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2389. {
  2390. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2391. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2392. {
  2393. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2394. {
  2395. reqClockAlignMeter[gun_index] = 1;
  2396. }
  2397. }
  2398. }// End for CHAdeMO
  2399. }
  2400. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2401. {
  2402. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2403. {
  2404. tempIndex = ((gun_index==2) ? 1: 0);
  2405. }
  2406. else
  2407. {
  2408. tempIndex = gun_index;
  2409. }
  2410. for (int index = 0; index < CCS_QUANTITY; index++)
  2411. {
  2412. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2413. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2414. {
  2415. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2416. {
  2417. reqClockAlignMeter[gun_index] = 1;
  2418. }
  2419. }
  2420. } // End for CCS
  2421. }
  2422. else if(gunType[gun_index] == 'G')
  2423. {
  2424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2425. {
  2426. tempIndex = ((gun_index==2) ? 1: 0);
  2427. }
  2428. else
  2429. {
  2430. tempIndex = gun_index;
  2431. }
  2432. for (int index = 0; index < GB_QUANTITY; index++)
  2433. {
  2434. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2435. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2436. {
  2437. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2438. {
  2439. reqClockAlignMeter[gun_index] = 1;
  2440. }
  2441. }
  2442. }// End for GB
  2443. }
  2444. else if(gunType[gun_index] == 'O')
  2445. {
  2446. tempIndex = gun_index;
  2447. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2448. {
  2449. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2450. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2451. {
  2452. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2453. {
  2454. reqClockAlignMeter[gun_index] = 1;
  2455. }
  2456. }
  2457. }
  2458. }
  2459. else
  2460. {
  2461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2462. {
  2463. tempIndex = 2;
  2464. }
  2465. else
  2466. {
  2467. tempIndex = gun_index;
  2468. }
  2469. for (int index = 0; index < AC_QUANTITY; index++)
  2470. {
  2471. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2472. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2473. {
  2474. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2475. {
  2476. reqClockAlignMeter[gun_index] = 1;
  2477. }
  2478. }
  2479. }//End for AC
  2480. }
  2481. if(reqClockAlignMeter[gun_index] == 1)
  2482. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2483. }
  2484. // Sample period MeterValue
  2485. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2486. {
  2487. //check Transaction active
  2488. if(gunType[gun_index] == 'J')
  2489. {
  2490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2491. {
  2492. tempIndex = ((gun_index==2) ? 1: 0);
  2493. }
  2494. else
  2495. {
  2496. tempIndex = gun_index;
  2497. }
  2498. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2499. {
  2500. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2501. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2502. {
  2503. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2504. {
  2505. reqSampleMeter[gun_index] = 1;
  2506. }
  2507. }
  2508. }// End for CHAdeMO
  2509. }
  2510. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2511. {
  2512. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2513. {
  2514. tempIndex = ((gun_index==2) ? 1: 0);
  2515. }
  2516. else
  2517. {
  2518. tempIndex = gun_index;
  2519. }
  2520. for (int index = 0; index < CCS_QUANTITY; index++)
  2521. {
  2522. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2523. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2524. {
  2525. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2526. {
  2527. reqSampleMeter[gun_index] = 1;
  2528. }
  2529. }
  2530. } // End for CCS
  2531. }
  2532. else if(gunType[gun_index] == 'G')
  2533. {
  2534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2535. {
  2536. tempIndex = ((gun_index==2) ? 1: 0);
  2537. }
  2538. else
  2539. {
  2540. tempIndex = gun_index;
  2541. }
  2542. for (int index = 0; index < GB_QUANTITY; index++)
  2543. {
  2544. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2545. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2546. {
  2547. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2548. {
  2549. reqSampleMeter[gun_index] = 1;
  2550. }
  2551. }
  2552. }// End for GB
  2553. }
  2554. else if(gunType[gun_index] == 'O')
  2555. {
  2556. tempIndex = gun_index;
  2557. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2558. {
  2559. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2560. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2561. {
  2562. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2563. {
  2564. reqSampleMeter[gun_index] = 1;
  2565. }
  2566. }
  2567. }
  2568. }
  2569. else
  2570. {
  2571. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2572. {
  2573. tempIndex = 2;
  2574. }
  2575. else
  2576. {
  2577. tempIndex = gun_index;
  2578. }
  2579. for (int index = 0; index < AC_QUANTITY; index++)
  2580. {
  2581. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2582. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2583. {
  2584. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2585. {
  2586. reqSampleMeter[gun_index] = 1;
  2587. }
  2588. }
  2589. }//End for AC
  2590. }
  2591. if(reqSampleMeter[gun_index] == 1)
  2592. {
  2593. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2594. storeTempStopTransaction(gun_index);
  2595. }
  2596. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2597. }
  2598. //==============================================
  2599. // Check Connector reserved
  2600. //==============================================
  2601. //===============================
  2602. // Check if Reserve is expired
  2603. //===============================
  2604. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2605. {
  2606. double diff_t;
  2607. struct tm tp;
  2608. // current time
  2609. time_t t = time(NULL);
  2610. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2611. tp.tm_isdst = -1;
  2612. time_t utc = mktime(&tp);
  2613. diff_t = difftime(utc, t);
  2614. if(diff_t <= 0)
  2615. {
  2616. DEBUG_INFO("reserve expired.\n");
  2617. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2618. }
  2619. }//END OF Check if Reserve is expired
  2620. //==========================================
  2621. // csu trigger FirmwareStatusNotificationReq
  2622. //==========================================
  2623. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2624. {
  2625. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2626. }
  2627. //==========================================
  2628. // csu trigger CancelReservationConf
  2629. //==========================================
  2630. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2631. {
  2632. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2633. }
  2634. //==========================================
  2635. // csu trigger ChangeAvailabilityConf
  2636. //==========================================
  2637. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2638. {
  2639. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2640. }
  2641. //==========================================
  2642. // csu trigger UnlockConnectorConf
  2643. //==========================================
  2644. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2645. {
  2646. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2647. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2648. }
  2649. //==========================================
  2650. // csu trigger ReserveNowConf
  2651. //==========================================
  2652. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2653. {
  2654. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2655. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2656. }
  2657. }
  2658. }
  2659. //==========================================
  2660. // send request routine
  2661. //==========================================
  2662. int sendAuthorizeRequest(int gun_index)
  2663. {
  2664. mtrace();
  2665. int result = FAIL;
  2666. char message[100]={0};
  2667. char guid[37];
  2668. char tempdata[65]={0};
  2669. DEBUG_INFO("sendAuthorizeRequest...\n");
  2670. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2671. //Local Authorize
  2672. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2673. {
  2674. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2675. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2676. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2677. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2678. result = PASS;
  2679. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2680. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2681. authorizeRetryTimes = 0;
  2682. return result;
  2683. }
  2684. 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))||
  2685. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2686. {
  2687. // Query from cache
  2688. DEBUG_INFO("Authorize from cache.\n");
  2689. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2690. // Query from list
  2691. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2692. {
  2693. DEBUG_INFO("Authorize from list.\n");
  2694. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2695. }
  2696. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2697. {
  2698. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2699. {
  2700. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2701. }
  2702. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2703. {
  2704. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2705. }
  2706. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  2707. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2708. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2709. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2710. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2711. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2712. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2713. authorizeRetryTimes = 0;
  2714. return result;
  2715. }
  2716. else
  2717. {
  2718. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  2719. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2720. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2721. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2722. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2723. else
  2724. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2725. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2726. result = PASS;
  2727. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2728. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2729. authorizeRetryTimes = 0;
  2730. return result;
  2731. }
  2732. }
  2733. //initialize struct Authorize
  2734. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2735. //get data from shared memory
  2736. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2737. random_uuid(guid);
  2738. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2739. LWS_Send(message);
  2740. sprintf(tempdata, "Authorize,%d", gun_index);
  2741. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2742. {
  2743. result = PASS;
  2744. DEBUG_INFO("Authorize mapItem pass\n");
  2745. }
  2746. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2747. return result;
  2748. }
  2749. int sendBootNotificationRequest(void)
  2750. {
  2751. mtrace();
  2752. int result = FAIL;
  2753. char message[500]={0}, payload[700]={0};
  2754. char guid[37]={0};
  2755. char tempdata[65]={0};
  2756. // Fill BootNotification fields
  2757. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2758. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2759. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2760. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2761. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2762. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2763. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2764. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2765. ShmOCPP16Data->ChargeBoxId
  2766. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2767. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2768. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2769. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2770. ,ShmOCPP16Data->BootNotification.CpIccid
  2771. ,ShmOCPP16Data->BootNotification.CpImsi);
  2772. random_uuid(guid);
  2773. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2774. LWS_Send(message);
  2775. sprintf(tempdata, "BootNotification,0");
  2776. 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*/)
  2777. {
  2778. result = PASS;
  2779. }
  2780. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2781. strcpy(queuedata,message);
  2782. return result;
  2783. }
  2784. int sendDataTransferRequest(int gun_index)
  2785. {
  2786. mtrace();
  2787. char message[1000]={0};
  2788. char guid[37]={0};
  2789. char tempdata[65]={0};
  2790. int result = FAIL;
  2791. random_uuid(guid);
  2792. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2793. MESSAGE_TYPE_CALL,
  2794. guid,
  2795. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2796. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2797. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2798. LWS_Send(message);
  2799. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2800. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2801. {
  2802. result = PASS;
  2803. DEBUG_INFO("DataTransfer mapItem pass\n");
  2804. }
  2805. return result;
  2806. }
  2807. int sendDiagnosticsStatusNotificationRequest(char *status)
  2808. {
  2809. mtrace();
  2810. int result = FAIL;
  2811. char message[110]={0};
  2812. char guid[37]={0};
  2813. char tempdata[65]={0};
  2814. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2815. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2816. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2817. random_uuid(guid);
  2818. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2819. LWS_SendNow(message);
  2820. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2821. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2822. {
  2823. result = PASS;
  2824. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2825. }
  2826. //#ifdef SystemLogMessage
  2827. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2828. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2829. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2830. //#endif
  2831. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2832. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2833. //record status
  2834. if(strcmp(status,"Idle")==0)
  2835. {
  2836. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2837. }
  2838. else if(strcmp(status,"Uploaded")==0)
  2839. {
  2840. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2841. }
  2842. else if(strcmp(status,"UploadFailed")==0)
  2843. {
  2844. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2845. }
  2846. else if(strcmp(status,"Uploading")==0)
  2847. {
  2848. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2849. }
  2850. return result;
  2851. }
  2852. int sendFirmwareStatusNotificationRequest(char *status)
  2853. {
  2854. mtrace();
  2855. int result = FAIL;
  2856. char message[110]={0};
  2857. char guid[37]={0};
  2858. char tempdata[65]={0};
  2859. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2860. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2861. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2862. random_uuid(guid);
  2863. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2864. LWS_SendNow(message);
  2865. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2866. 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*/)
  2867. {
  2868. result = PASS;
  2869. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2870. }
  2871. //#ifdef SystemLogMessage
  2872. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2873. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2874. //#endif
  2875. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2876. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2877. //record status
  2878. if(strcmp(status,"Downloaded")==0)
  2879. {
  2880. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2881. }
  2882. else if(strcmp(status,"DownloadFailed")==0)
  2883. {
  2884. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2885. }
  2886. else if(strcmp(status,"Downloading")==0)
  2887. {
  2888. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2889. }
  2890. else if(strcmp(status,"Idle")==0)
  2891. {
  2892. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2893. }
  2894. else if(strcmp(status,"InstallationFailed")==0)
  2895. {
  2896. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2897. }
  2898. else if(strcmp(status,"Installing")==0)
  2899. {
  2900. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2901. }
  2902. else if(strcmp(status,"Installed")==0)
  2903. {
  2904. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2905. }
  2906. return result;
  2907. }
  2908. int sendHeartbeatRequest(int gun_index)
  2909. {
  2910. mtrace();
  2911. int result = FAIL;
  2912. char message[80]={0};
  2913. char guid[37]={0};
  2914. char tempdata[65]={0};
  2915. random_uuid(guid);
  2916. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2917. , MESSAGE_TYPE_CALL
  2918. , guid );
  2919. LWS_Send(message);
  2920. sprintf(tempdata, "Heartbeat,%d", 0);
  2921. 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*/)
  2922. {
  2923. result = PASS;
  2924. }
  2925. return result;
  2926. }
  2927. int sendStartTransactionRequest(int gun_index)
  2928. {
  2929. mtrace();
  2930. int result = FAIL;
  2931. char message[250]={0};
  2932. char guid[37]={0};
  2933. struct timeval tmnow;
  2934. struct tm *tm;
  2935. char buf[28];//, usec_buf[6];
  2936. char tempdata[65]={0};
  2937. int tempIndex = 0;
  2938. DEBUG_INFO("sendStartTransactionRequest...\n");
  2939. gettimeofday(&tmnow, NULL);
  2940. time_t t;
  2941. t = time(NULL);
  2942. /*UTC time and date*/
  2943. tm = gmtime(&t);
  2944. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2945. #if 0 // remove temporally
  2946. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2947. strcat(buf,".");
  2948. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2949. strcat(buf,usec_buf);
  2950. #endif
  2951. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2952. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2953. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2954. // clear StartTransaction Response
  2955. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2956. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2957. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2958. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2959. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2960. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2961. if(gunType[gun_index] == 'J')
  2962. {
  2963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2964. {
  2965. tempIndex = ((gun_index==2) ? 1: 0);
  2966. }
  2967. else
  2968. {
  2969. tempIndex = gun_index;
  2970. }
  2971. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2972. {
  2973. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2974. {
  2975. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2976. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2977. }
  2978. }
  2979. }
  2980. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2981. {
  2982. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2983. {
  2984. tempIndex = ((gun_index==2) ? 1: 0);
  2985. }
  2986. else
  2987. {
  2988. tempIndex = gun_index;
  2989. }
  2990. for (int index = 0; index < CCS_QUANTITY; index++)
  2991. {
  2992. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2993. {
  2994. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2995. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2996. }
  2997. }
  2998. }
  2999. else if(gunType[gun_index] == 'G')
  3000. {
  3001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3002. {
  3003. tempIndex = ((gun_index==2) ? 1: 0);
  3004. }
  3005. else
  3006. {
  3007. tempIndex = gun_index;
  3008. }
  3009. for (int index = 0; index < GB_QUANTITY; index++)
  3010. {
  3011. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3012. {
  3013. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3014. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3015. }
  3016. }
  3017. }
  3018. else if(gunType[gun_index] == 'O')
  3019. {
  3020. tempIndex = gun_index;
  3021. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3022. {
  3023. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3024. {
  3025. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3026. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3027. }
  3028. }
  3029. }
  3030. else
  3031. {
  3032. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3033. {
  3034. tempIndex = 2;
  3035. }
  3036. else
  3037. {
  3038. tempIndex = gun_index;
  3039. }
  3040. for (int index = 0; index < AC_QUANTITY; index++)
  3041. {
  3042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3043. {
  3044. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3045. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3046. }
  3047. }
  3048. }
  3049. random_uuid(guid);
  3050. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3051. {
  3052. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3053. , gun_index +1
  3054. , MESSAGE_TYPE_CALL
  3055. , guid
  3056. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3057. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3058. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3059. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3060. }
  3061. else
  3062. {
  3063. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3064. , gun_index +1
  3065. , MESSAGE_TYPE_CALL
  3066. , guid
  3067. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3068. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3069. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3070. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3071. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3072. }
  3073. #if 1
  3074. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3075. 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*/)
  3076. {
  3077. result = PASS;
  3078. }
  3079. #endif
  3080. strcpy(queuedata, message);
  3081. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3082. return result;
  3083. }
  3084. int sendStatusNotificationRequest(int gun_index)
  3085. {
  3086. mtrace();
  3087. int result = FAIL;
  3088. char message[600]={0};
  3089. char guid[37];
  3090. int currentStatus = 0;
  3091. struct timeval tmnow;
  3092. struct tm *tm;
  3093. char buf[28];//, usec_buf[6];
  3094. char tempdata[65]={0};
  3095. int tempIndex = 0;
  3096. gettimeofday(&tmnow, NULL);
  3097. time_t t;
  3098. t = time(NULL);
  3099. /*UTC time and date*/
  3100. tm = gmtime(&t);
  3101. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3102. #if 0 // remove temporally
  3103. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3104. strcat(buf,".");
  3105. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3106. strcat(buf,usec_buf);
  3107. #endif
  3108. printf("%s",buf);
  3109. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3110. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3111. // it's option
  3112. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3113. /*
  3114. enum _SYSTEM_STATUS
  3115. {
  3116. S_BOOTING = 0,
  3117. S_IDLE, = 1
  3118. S_AUTHORIZING, =2
  3119. S_REASSIGN_CHECK, =3
  3120. S_REASSIGN, =4
  3121. S_PRECHARGE, =5
  3122. S_PREPARING_FOR_EV, =6
  3123. S_PREPARING_FOR_EVSE, =7
  3124. S_CHARGING, =8
  3125. S_TERMINATING, =9
  3126. S_COMPLETE, =10
  3127. S_ALARM, =11
  3128. S_FAULT =12
  3129. }
  3130. */
  3131. //check Transaction active
  3132. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3133. if(gunType[gun_index] == 'J')
  3134. {
  3135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3136. {
  3137. tempIndex = ((gun_index==2) ? 1: 0);
  3138. }
  3139. else
  3140. {
  3141. tempIndex = gun_index;
  3142. }
  3143. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3144. {
  3145. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3146. {
  3147. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3148. {
  3149. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3150. {
  3151. currentStatus = 1; //OCPP Status: Preparing
  3152. }
  3153. else
  3154. {
  3155. currentStatus = 0; //OCPP Status: Available
  3156. }
  3157. }
  3158. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3159. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3160. ) //S_PRECHARGE
  3161. {
  3162. currentStatus = 1; //OCPP Status: Preparing
  3163. }
  3164. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3165. {
  3166. currentStatus = 2; //OCPP Status: Charging
  3167. }
  3168. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3169. {
  3170. currentStatus = 5; //OCPP Status: Finishing
  3171. }
  3172. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3173. {
  3174. currentStatus = 4; //OCPP Status: SuspendedEV
  3175. }
  3176. 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
  3177. {
  3178. currentStatus = 7; //OCPP Status: Unavailable
  3179. }
  3180. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3181. {
  3182. currentStatus = 8; //OCPP Status: Faulted
  3183. }
  3184. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3185. {
  3186. currentStatus = 6; //OCPP Status: Reserved
  3187. }
  3188. } //end of the same index
  3189. }//end of for CHAdeMO_QUANTITY
  3190. }
  3191. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3192. {
  3193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3194. {
  3195. tempIndex = ((gun_index==2) ? 1: 0);
  3196. }
  3197. else
  3198. {
  3199. tempIndex = gun_index;
  3200. }
  3201. for (int index = 0; index < CCS_QUANTITY; index++)
  3202. {
  3203. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3204. {
  3205. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3206. {
  3207. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3208. {
  3209. currentStatus = 1; //OCPP Status: Preparing
  3210. }
  3211. else
  3212. {
  3213. currentStatus = 0; //OCPP Status: Available
  3214. }
  3215. }
  3216. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3217. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3218. ) //S_PRECHARGE
  3219. {
  3220. currentStatus = 1; //OCPP Status: Preparing
  3221. }
  3222. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3223. {
  3224. currentStatus = 2; //OCPP Status: Charging
  3225. }
  3226. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3227. {
  3228. currentStatus = 5; //OCPP Status: Finishing
  3229. }
  3230. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3231. {
  3232. currentStatus = 4; //OCPP Status: SuspendedEV
  3233. }
  3234. 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
  3235. {
  3236. currentStatus = 7; //OCPP Status : Unavailable
  3237. }
  3238. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3239. {
  3240. currentStatus = 8; //OCPP Status: Faulted
  3241. }
  3242. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3243. {
  3244. currentStatus = 6; //OCPP Status: Reserved
  3245. }
  3246. } //end of the same index
  3247. } // end of for CCS_QUANTITY
  3248. }
  3249. else if(gunType[gun_index] == 'G')
  3250. {
  3251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3252. {
  3253. tempIndex = ((gun_index==2) ? 1: 0);
  3254. }
  3255. else
  3256. {
  3257. tempIndex = gun_index;
  3258. }
  3259. for (int index = 0; index < GB_QUANTITY; index++)
  3260. {
  3261. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3262. {
  3263. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3264. {
  3265. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3266. {
  3267. currentStatus = 1; //OCPP Status: Preparing
  3268. }
  3269. else
  3270. {
  3271. currentStatus = 0; //OCPP Status: Available
  3272. }
  3273. }
  3274. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3275. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3276. ) //S_PRECHARGE
  3277. {
  3278. currentStatus = 1; //OCPP Status: Preparing
  3279. }
  3280. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3281. {
  3282. currentStatus = 2; //OCPP Status: Charging
  3283. }
  3284. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3285. {
  3286. currentStatus = 5; //OCPP Status: Finishing
  3287. }
  3288. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3289. {
  3290. currentStatus = 4; //OCPP Status: SuspendedEV
  3291. }
  3292. 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
  3293. {
  3294. currentStatus = 7; //OCPP Status: Unavailable
  3295. }
  3296. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3297. {
  3298. currentStatus = 8; //OCPP Status: Faulted
  3299. }
  3300. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3301. {
  3302. currentStatus = 6; //OCPP Status: Reserved
  3303. }
  3304. } //end of the same index
  3305. } // end of for GB_QUANTITY
  3306. }
  3307. else if(gunType[gun_index] == 'O')
  3308. {
  3309. tempIndex = gun_index;
  3310. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3311. {
  3312. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3313. {
  3314. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3315. {
  3316. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3317. {
  3318. currentStatus = 1; //OCPP Status: Preparing
  3319. }
  3320. else
  3321. {
  3322. currentStatus = 0; //OCPP Status: Available
  3323. }
  3324. }
  3325. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3326. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3327. ) //S_PRECHARGE
  3328. {
  3329. currentStatus = 1; //OCPP Status: Preparing
  3330. }
  3331. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3332. {
  3333. currentStatus = 2; //OCPP Status: Charging
  3334. }
  3335. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3336. {
  3337. currentStatus = 5; //OCPP Status: Finishing
  3338. }
  3339. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3340. {
  3341. currentStatus = 4; //OCPP Status: SuspendedEV
  3342. }
  3343. 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
  3344. {
  3345. currentStatus = 7; //OCPP Status: Unavailable
  3346. }
  3347. 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
  3348. {
  3349. currentStatus = 8; //OCPP Status: Faulted
  3350. }
  3351. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3352. {
  3353. currentStatus = 6; //OCPP Status: Reserved
  3354. }
  3355. } //end of the same index
  3356. }
  3357. }
  3358. else
  3359. {
  3360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3361. {
  3362. tempIndex = 2;
  3363. }
  3364. else
  3365. {
  3366. tempIndex = gun_index;
  3367. }
  3368. for (int index = 0; index < AC_QUANTITY; index++)
  3369. {
  3370. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3371. {
  3372. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3373. {
  3374. 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))
  3375. {
  3376. currentStatus = 1; //OCPP Status: Preparing
  3377. }
  3378. else
  3379. {
  3380. currentStatus = 0; //OCPP Status: Available
  3381. }
  3382. }
  3383. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3384. {
  3385. currentStatus = 1; //OCPP Status: Preparing
  3386. }
  3387. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3388. {
  3389. currentStatus = 2; //OCPP Status: Charging
  3390. }
  3391. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3392. {
  3393. currentStatus = 5; //OCPP Status: Finishing
  3394. }
  3395. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3396. {
  3397. currentStatus = 4; //OCPP Status: SuspendedEV
  3398. }
  3399. 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
  3400. {
  3401. currentStatus = 7; //OCPP Status: Unavailable
  3402. }
  3403. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3404. {
  3405. currentStatus = 8; //OCPP Status: Faulted
  3406. }
  3407. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3408. {
  3409. currentStatus = 6; //OCPP Status: Reserved
  3410. }
  3411. }//end of the same index
  3412. }//end of for AC_QUANTITY
  3413. }
  3414. //it's option
  3415. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3416. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3417. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3418. random_uuid(guid);
  3419. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3420. , MESSAGE_TYPE_CALL
  3421. , guid
  3422. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3423. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3424. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3425. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3426. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3427. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3428. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3429. if((server_sign == TRUE))
  3430. {
  3431. LWS_Send(message);
  3432. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3433. 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*/)
  3434. {
  3435. //DEBUG_ERROR("statusNotification mapitem pass");
  3436. result = PASS;
  3437. }
  3438. }
  3439. else
  3440. {
  3441. result = PASS;
  3442. }
  3443. return result;
  3444. }
  3445. int sendStopTransactionRequest(int gun_index)
  3446. {
  3447. mtrace();
  3448. int result = FAIL;
  3449. //char message[1500]={0};
  3450. char guid[37]={0};
  3451. char tempdata[65]={0};
  3452. int tempIndex = 0;
  3453. char TempStopTransaction[256];
  3454. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3455. //int idx_sample=0;
  3456. DEBUG_INFO("sendStopTransactionRequest \n");
  3457. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3458. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3459. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3460. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3461. if(gunType[gun_index] == 'J')
  3462. {
  3463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3464. {
  3465. tempIndex = ((gun_index==2) ? 1: 0);
  3466. }
  3467. else
  3468. {
  3469. tempIndex = gun_index;
  3470. }
  3471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3472. {
  3473. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3474. {
  3475. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3476. }
  3477. }// END OF CHAdeMO_QUANTITY
  3478. }
  3479. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3480. {
  3481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3482. {
  3483. tempIndex = ((gun_index==2) ? 1: 0);
  3484. }
  3485. else
  3486. {
  3487. tempIndex = gun_index;
  3488. }
  3489. for (int index = 0; index < CCS_QUANTITY; index++)
  3490. {
  3491. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3492. {
  3493. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3494. }
  3495. }// END OF CCS_QUANTITY
  3496. }
  3497. else if(gunType[gun_index] == 'G')
  3498. {
  3499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3500. {
  3501. tempIndex = ((gun_index==2) ? 1: 0);
  3502. }
  3503. else
  3504. {
  3505. tempIndex = gun_index;
  3506. }
  3507. for (int index = 0; index < GB_QUANTITY; index++)
  3508. {
  3509. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3510. {
  3511. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3512. }
  3513. }// END OF GB_QUANTITY
  3514. }
  3515. else if(gunType[gun_index] == 'O')
  3516. {
  3517. tempIndex = gun_index;
  3518. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3519. {
  3520. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3521. {
  3522. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3523. }
  3524. }// END OF GB_QUANTITY
  3525. }
  3526. else
  3527. {
  3528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3529. {
  3530. tempIndex = 2;
  3531. }
  3532. else
  3533. {
  3534. tempIndex = gun_index;
  3535. }
  3536. for (int index = 0; index < AC_QUANTITY; index++)
  3537. {
  3538. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3539. {
  3540. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3541. }
  3542. }// END OF AC_QUANTITY
  3543. }
  3544. //====================================== Stop Transaction Time =====================================================
  3545. struct timeval tmnow;
  3546. struct tm *tm;
  3547. char buf[28];//, usec_buf[6];
  3548. gettimeofday(&tmnow, NULL);
  3549. time_t t;
  3550. t = time(NULL);
  3551. /*UTC time and date*/
  3552. tm = gmtime(&t);
  3553. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3555. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3556. random_uuid(guid);
  3557. /***********************************transactionData******************************************************/
  3558. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3560. //=================================
  3561. // Transaction_Begin
  3562. //=================================
  3563. //============================================ Energy.Active.Import.Interval ================================
  3564. //idx_sample=0;
  3565. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3568. 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*/]);
  3569. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3570. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3571. {
  3572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3573. }
  3574. else
  3575. {
  3576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3577. }
  3578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3580. //=================================
  3581. // Transaction_End
  3582. //=================================
  3583. // ================================= Current.Import L1 ===============================================
  3584. //idx_sample=1;
  3585. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3586. if(gunType[gun_index] == 'J')
  3587. {
  3588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3589. {
  3590. tempIndex = ((gun_index==2) ? 1: 0);
  3591. }
  3592. else
  3593. {
  3594. tempIndex = gun_index;
  3595. }
  3596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3597. {
  3598. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3599. {
  3600. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3601. }
  3602. }// End of for CHAdeMO_QUANTITY
  3603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3604. }
  3605. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3606. {
  3607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3608. {
  3609. tempIndex = ((gun_index==2) ? 1: 0);
  3610. }
  3611. else
  3612. {
  3613. tempIndex = gun_index;
  3614. }
  3615. for (int index = 0; index < CCS_QUANTITY; index++)
  3616. {
  3617. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3618. {
  3619. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3620. }
  3621. }// End of for CCS_QUANTITY
  3622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3623. }
  3624. else if(gunType[gun_index] == 'G')
  3625. {
  3626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3627. {
  3628. tempIndex = ((gun_index==2) ? 1: 0);
  3629. }
  3630. else
  3631. {
  3632. tempIndex = gun_index;
  3633. }
  3634. for (int index = 0; index < GB_QUANTITY; index++)
  3635. {
  3636. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3637. {
  3638. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3639. }
  3640. }// End of for GB_QUANTITY
  3641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3642. }
  3643. else if(gunType[gun_index] == 'O')
  3644. {
  3645. tempIndex = gun_index;
  3646. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3647. {
  3648. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3649. {
  3650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3651. }
  3652. }
  3653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3654. }
  3655. else
  3656. {
  3657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3658. {
  3659. tempIndex = 2;
  3660. }
  3661. else
  3662. {
  3663. tempIndex = gun_index;
  3664. }
  3665. for (int index = 0; index < AC_QUANTITY; index++)
  3666. {
  3667. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3668. {
  3669. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3670. }
  3671. }// End of for AC_QUANTITY
  3672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3673. }
  3674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3679. // ================================= Energy.Active.Import.Interval ==============================================
  3680. //idx_sample=2;
  3681. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3682. if(gunType[gun_index] == 'J')
  3683. {
  3684. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3685. {
  3686. tempIndex = ((gun_index==2) ? 1: 0);
  3687. }
  3688. else
  3689. {
  3690. tempIndex = gun_index;
  3691. }
  3692. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3693. {
  3694. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3695. {
  3696. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3697. }
  3698. }// END OF CHAdeMO_QUANTITY
  3699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3700. }
  3701. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3702. {
  3703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3704. {
  3705. tempIndex = ((gun_index==2) ? 1: 0);
  3706. }
  3707. else
  3708. {
  3709. tempIndex = gun_index;
  3710. }
  3711. for (int index = 0; index < CCS_QUANTITY; index++)
  3712. {
  3713. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3714. {
  3715. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3716. }
  3717. }// END OF CCS_QUANTITY
  3718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3719. }
  3720. else if(gunType[gun_index] == 'G')
  3721. {
  3722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3723. {
  3724. tempIndex = ((gun_index==2) ? 1: 0);
  3725. }
  3726. else
  3727. {
  3728. tempIndex = gun_index;
  3729. }
  3730. for (int index = 0; index < GB_QUANTITY; index++)
  3731. {
  3732. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3733. {
  3734. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3735. }
  3736. }// END OF GB_QUANTITY
  3737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3738. }
  3739. else if(gunType[gun_index] == 'O')
  3740. {
  3741. tempIndex = gun_index;
  3742. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3743. {
  3744. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3745. {
  3746. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3747. }
  3748. }
  3749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3750. }
  3751. else
  3752. {
  3753. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3754. {
  3755. tempIndex = 2;
  3756. }
  3757. else
  3758. {
  3759. tempIndex = gun_index;
  3760. }
  3761. for (int index = 0; index < AC_QUANTITY; index++)
  3762. {
  3763. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3764. {
  3765. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3766. }
  3767. }// END OF AC_QUANTITY
  3768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3769. }
  3770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3775. //=================================== Power.Active.Import ==================================================
  3776. //idx_sample=3;
  3777. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3778. if(gunType[gun_index] == 'J')
  3779. {
  3780. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3781. {
  3782. tempIndex = ((gun_index==2) ? 1: 0);
  3783. }
  3784. else
  3785. {
  3786. tempIndex = gun_index;
  3787. }
  3788. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3789. {
  3790. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3791. {
  3792. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3793. }
  3794. } // End for CHAdeMO_QUANTITY
  3795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3796. }
  3797. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3798. {
  3799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3800. {
  3801. tempIndex = ((gun_index==2) ? 1: 0);
  3802. }
  3803. else
  3804. {
  3805. tempIndex = gun_index;
  3806. }
  3807. for (int index = 0; index < CCS_QUANTITY; index++)
  3808. {
  3809. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3810. {
  3811. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3812. }
  3813. } // END for CCS_QUANTITY
  3814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3815. }
  3816. else if(gunType[gun_index] == 'G')
  3817. {
  3818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3819. {
  3820. tempIndex = ((gun_index==2) ? 1: 0);
  3821. }
  3822. else
  3823. {
  3824. tempIndex = gun_index;
  3825. }
  3826. for (int index = 0; index < GB_QUANTITY; index++)
  3827. {
  3828. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3829. {
  3830. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3831. }
  3832. }// END for GB_QUANTITY
  3833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3834. }
  3835. else if(gunType[gun_index] == 'O')
  3836. {
  3837. tempIndex = gun_index;
  3838. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3839. {
  3840. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3841. {
  3842. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3843. }
  3844. }
  3845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3846. }
  3847. else
  3848. {
  3849. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3850. {
  3851. tempIndex = 2;
  3852. }
  3853. else
  3854. {
  3855. tempIndex = gun_index;
  3856. }
  3857. for (int index = 0; index < AC_QUANTITY; index++)
  3858. {
  3859. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3860. {
  3861. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3862. }
  3863. } // END for AC_QUANTITY
  3864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3865. }
  3866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3871. //============================ Voltage L1 ====================================
  3872. //idx_sample=4;
  3873. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3874. if(gunType[gun_index] == 'J')
  3875. {
  3876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3877. {
  3878. tempIndex = ((gun_index==2) ? 1: 0);
  3879. }
  3880. else
  3881. {
  3882. tempIndex = gun_index;
  3883. }
  3884. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3885. {
  3886. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3887. {
  3888. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3889. }
  3890. } // END OF FOR CHAdeMO_QUANTITY
  3891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3892. }
  3893. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3894. {
  3895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3896. {
  3897. tempIndex = ((gun_index==2) ? 1: 0);
  3898. }
  3899. else
  3900. {
  3901. tempIndex = gun_index;
  3902. }
  3903. for (int index = 0; index < CCS_QUANTITY; index++)
  3904. {
  3905. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3906. {
  3907. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3908. }
  3909. } // END OF FOR CCS_QUANTITY
  3910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3911. }
  3912. else if(gunType[gun_index] == 'G')
  3913. {
  3914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3915. {
  3916. tempIndex = ((gun_index==2) ? 1: 0);
  3917. }
  3918. else
  3919. {
  3920. tempIndex = gun_index;
  3921. }
  3922. for (int index = 0; index < GB_QUANTITY; index++)
  3923. {
  3924. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3925. {
  3926. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3927. }
  3928. } // END OF FOR GB_QUANTITY
  3929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3930. }
  3931. else if(gunType[gun_index] == 'O')
  3932. {
  3933. tempIndex = gun_index;
  3934. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3935. {
  3936. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3937. {
  3938. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3939. }
  3940. }
  3941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3942. }
  3943. else
  3944. {
  3945. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3946. {
  3947. tempIndex = 2;
  3948. }
  3949. else
  3950. {
  3951. tempIndex = gun_index;
  3952. }
  3953. for (int index = 0; index < AC_QUANTITY; index++)
  3954. {
  3955. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3956. {
  3957. 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
  3958. }
  3959. } // END OF FOR AC_QUANTITY
  3960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3961. }
  3962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3967. //====================== End SoC ================================
  3968. //idx_sample=5;
  3969. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3970. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3971. {
  3972. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  3973. {
  3974. tempIndex = ((gun_index==2) ? 1: 0);
  3975. }
  3976. else
  3977. {
  3978. tempIndex = gun_index;
  3979. }
  3980. if(gunType[gun_index] == 'J')
  3981. {
  3982. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3983. {
  3984. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3985. {
  3986. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3987. }
  3988. }
  3989. }
  3990. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3991. {
  3992. for (int index = 0; index < CCS_QUANTITY; index++)
  3993. {
  3994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3995. {
  3996. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3997. }
  3998. }
  3999. }
  4000. else if(gunType[gun_index] == 'G')
  4001. {
  4002. for (int index = 0; index < GB_QUANTITY; index++)
  4003. {
  4004. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4005. {
  4006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4007. }
  4008. }
  4009. }
  4010. else if(gunType[gun_index] == 'O')
  4011. {
  4012. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4013. {
  4014. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4015. {
  4016. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4017. }
  4018. }
  4019. }
  4020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4026. } // END FOR DC CASE
  4027. // ================================= Current.Import L2 ===============================================
  4028. //idx_sample=6;
  4029. // AC 3 phse L2 current
  4030. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4031. {
  4032. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4033. {
  4034. tempIndex = 2;
  4035. }
  4036. else
  4037. {
  4038. tempIndex = gun_index;
  4039. }
  4040. for (int index = 0; index < AC_QUANTITY; index++)
  4041. {
  4042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4043. {
  4044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4045. }
  4046. }// End of for AC_QUANTITY
  4047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4048. }
  4049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4054. // ================================= Current.Import L3 ===============================================
  4055. //idx_sample=7;
  4056. // AC 3 phse L3 current
  4057. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4058. {
  4059. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4060. {
  4061. tempIndex = 2;
  4062. }
  4063. else
  4064. {
  4065. tempIndex = gun_index;
  4066. }
  4067. for (int index = 0; index < AC_QUANTITY; index++)
  4068. {
  4069. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4070. {
  4071. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4072. }
  4073. }// End of for AC_QUANTITY
  4074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4075. }
  4076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4081. //============================ Voltage L2 ====================================
  4082. //idx_sample=8;
  4083. // AC 3 phse L2 voltage
  4084. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4085. {
  4086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4087. {
  4088. tempIndex = 2;
  4089. }
  4090. else
  4091. {
  4092. tempIndex = gun_index;
  4093. }
  4094. for (int index = 0; index < AC_QUANTITY; index++)
  4095. {
  4096. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4097. {
  4098. 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
  4099. }
  4100. } // END OF FOR AC_QUANTITY
  4101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4102. }
  4103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4108. //============================ Voltage L3 ====================================
  4109. //idx_sample=8;
  4110. // AC 3 phse L3 voltage
  4111. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4112. {
  4113. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4114. {
  4115. tempIndex = 2;
  4116. }
  4117. else
  4118. {
  4119. tempIndex = gun_index;
  4120. }
  4121. for (int index = 0; index < AC_QUANTITY; index++)
  4122. {
  4123. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4124. {
  4125. 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
  4126. }
  4127. } // END OF FOR AC_QUANTITY
  4128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4129. }
  4130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4135. //====================== Start SoC ================================
  4136. //idx_sample=10;
  4137. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4138. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4139. {
  4140. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4141. {
  4142. tempIndex = ((gun_index==2) ? 1: 0);
  4143. }
  4144. else
  4145. {
  4146. tempIndex = gun_index;
  4147. }
  4148. if(gunType[gun_index] == 'J')
  4149. {
  4150. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4151. {
  4152. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4153. {
  4154. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4155. }
  4156. }
  4157. }
  4158. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4159. {
  4160. for (int index = 0; index < CCS_QUANTITY; index++)
  4161. {
  4162. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4163. {
  4164. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4165. }
  4166. }
  4167. }
  4168. else if(gunType[gun_index] == 'G')
  4169. {
  4170. for (int index = 0; index < GB_QUANTITY; index++)
  4171. {
  4172. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4173. {
  4174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4175. }
  4176. }
  4177. }
  4178. else if(gunType[gun_index] == 'O')
  4179. {
  4180. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4181. {
  4182. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4183. {
  4184. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4185. }
  4186. }
  4187. }
  4188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4194. } // END FOR DC CASE
  4195. //================================================ Message create ====================================================
  4196. json_object *StopTransaction = json_object_new_object();
  4197. json_object *transactionDatas = json_object_new_array();
  4198. json_object *sampledValues = json_object_new_array();
  4199. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4200. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4201. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4202. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4203. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4204. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4205. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4206. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4207. {
  4208. json_object *transactionData = json_object_new_object();
  4209. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4210. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4211. {
  4212. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4213. {
  4214. json_object *sampledValue = json_object_new_object();
  4215. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4216. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4217. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4218. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4219. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4220. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4221. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4222. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4223. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4224. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4225. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4226. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4227. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4228. json_object_array_add(sampledValues, sampledValue);
  4229. }
  4230. }
  4231. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4232. json_object_array_add(transactionDatas, transactionData);
  4233. }
  4234. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4235. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4236. ,MESSAGE_TYPE_CALL
  4237. ,guid
  4238. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4239. json_object_put(StopTransaction);
  4240. #if 1 // for TempStopTransaction
  4241. //Delete TempStopTransaction
  4242. if((access(TempStopTransaction,F_OK))!=-1)
  4243. {
  4244. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4245. }
  4246. #endif
  4247. #if 1
  4248. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4249. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4250. {
  4251. result = PASS;
  4252. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4253. }
  4254. #endif
  4255. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4256. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4257. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4258. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4259. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4260. {
  4261. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4262. }
  4263. //for test
  4264. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4265. return result;
  4266. }
  4267. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4268. {
  4269. mtrace();
  4270. int result = FAIL;
  4271. char guid[37]={0};
  4272. char tempdata[65]={0};
  4273. int tempIndex = 0;
  4274. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4275. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4276. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4277. //set value
  4278. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4279. 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) )?
  4280. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4281. -1);
  4282. random_uuid(guid);
  4283. //UTC Date time
  4284. struct timeval tmnow;
  4285. struct tm *tm;
  4286. char buf[28];//, usec_buf[6];
  4287. gettimeofday(&tmnow, NULL);
  4288. time_t t;
  4289. t = time(NULL);
  4290. /*UTC time and date*/
  4291. tm = gmtime(&t);
  4292. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4293. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4294. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4295. //idx_sample=0;
  4296. //********************************(1)Current.Import L1************************************************/
  4297. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4298. if(gunType[gun_index] == 'J')
  4299. {
  4300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4301. {
  4302. tempIndex = ((gun_index==2) ? 1: 0);
  4303. }
  4304. else
  4305. {
  4306. tempIndex = gun_index;
  4307. }
  4308. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4309. {
  4310. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4311. {
  4312. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4313. }
  4314. }
  4315. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4316. }
  4317. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4318. {
  4319. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4320. {
  4321. tempIndex = ((gun_index==2) ? 1: 0);
  4322. }
  4323. else
  4324. {
  4325. tempIndex = gun_index;
  4326. }
  4327. for (int index = 0; index < CCS_QUANTITY; index++)
  4328. {
  4329. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4330. {
  4331. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4332. }
  4333. }
  4334. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4335. }
  4336. else if(gunType[gun_index] == 'G')
  4337. {
  4338. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4339. {
  4340. tempIndex = ((gun_index==2) ? 1: 0);
  4341. }
  4342. else
  4343. {
  4344. tempIndex = gun_index;
  4345. }
  4346. for (int index = 0; index < GB_QUANTITY; index++)
  4347. {
  4348. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4349. {
  4350. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4351. }
  4352. }
  4353. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4354. }
  4355. else if(gunType[gun_index] == 'O')
  4356. {
  4357. tempIndex = gun_index;
  4358. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4359. {
  4360. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4361. {
  4362. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4363. }
  4364. }
  4365. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4366. }
  4367. else
  4368. {
  4369. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4370. {
  4371. tempIndex = 2;
  4372. }
  4373. else
  4374. {
  4375. tempIndex = gun_index;
  4376. }
  4377. for (int index = 0; index < AC_QUANTITY; index++)
  4378. {
  4379. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4380. {
  4381. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4382. }
  4383. }
  4384. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4385. }
  4386. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4389. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4390. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4391. //idx_sample=1;
  4392. //********************************(2)Energy.Active.Import.Register ************************************************/
  4393. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4394. if(gunType[gun_index] == 'J')
  4395. {
  4396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4397. {
  4398. tempIndex = ((gun_index==2) ? 1: 0);
  4399. }
  4400. else
  4401. {
  4402. tempIndex = gun_index;
  4403. }
  4404. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4405. {
  4406. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4407. {
  4408. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4409. }
  4410. }
  4411. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4412. }
  4413. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4414. {
  4415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4416. {
  4417. tempIndex = ((gun_index==2) ? 1: 0);
  4418. }
  4419. else
  4420. {
  4421. tempIndex = gun_index;
  4422. }
  4423. for (int index = 0; index < CCS_QUANTITY; index++)
  4424. {
  4425. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4426. {
  4427. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4428. }
  4429. }
  4430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4431. }
  4432. else if(gunType[gun_index] == 'G')
  4433. {
  4434. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4435. {
  4436. tempIndex = ((gun_index==2) ? 1: 0);
  4437. }
  4438. else
  4439. {
  4440. tempIndex = gun_index;
  4441. }
  4442. for (int index = 0; index < GB_QUANTITY; index++)
  4443. {
  4444. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4445. {
  4446. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4447. }
  4448. }
  4449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4450. }
  4451. else if(gunType[gun_index] == 'O')
  4452. {
  4453. tempIndex = gun_index;
  4454. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4455. {
  4456. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4457. {
  4458. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4459. }
  4460. }
  4461. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4462. }
  4463. else
  4464. {
  4465. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4466. {
  4467. tempIndex = 2;
  4468. }
  4469. else
  4470. {
  4471. tempIndex = gun_index;
  4472. }
  4473. for (int index = 0; index < AC_QUANTITY; index++)
  4474. {
  4475. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4476. {
  4477. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4478. }
  4479. }
  4480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4481. }
  4482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4487. //idx_sample=2;
  4488. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4489. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4490. if(gunType[gun_index] == 'J')
  4491. {
  4492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4493. {
  4494. tempIndex = ((gun_index==2) ? 1: 0);
  4495. }
  4496. else
  4497. {
  4498. tempIndex = gun_index;
  4499. }
  4500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4501. {
  4502. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4503. {
  4504. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4505. }
  4506. } // END OF FOR CHAdeMO_QUANTITY
  4507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4508. }
  4509. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4510. {
  4511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4512. {
  4513. tempIndex = ((gun_index==2) ? 1: 0);
  4514. }
  4515. else
  4516. {
  4517. tempIndex = gun_index;
  4518. }
  4519. for (int index = 0; index < CCS_QUANTITY; index++)
  4520. {
  4521. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4522. {
  4523. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4524. }
  4525. } // END OF CCS_QUANTITY
  4526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4527. }
  4528. else if(gunType[gun_index] == 'G')
  4529. {
  4530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4531. {
  4532. tempIndex = ((gun_index==2) ? 1: 0);
  4533. }
  4534. else
  4535. {
  4536. tempIndex = gun_index;
  4537. }
  4538. for (int index = 0; index < GB_QUANTITY; index++)
  4539. {
  4540. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4541. {
  4542. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4543. }
  4544. } // END OF GB_QUANTITY
  4545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4546. }
  4547. else if(gunType[gun_index] == 'O')
  4548. {
  4549. tempIndex = gun_index;
  4550. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4551. {
  4552. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4553. {
  4554. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4555. }
  4556. }
  4557. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4558. }
  4559. else
  4560. {
  4561. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4562. {
  4563. tempIndex = 2;
  4564. }
  4565. else
  4566. {
  4567. tempIndex = gun_index;
  4568. }
  4569. for (int index = 0; index < AC_QUANTITY; index++)
  4570. {
  4571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4572. {
  4573. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4574. }
  4575. }
  4576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4577. }
  4578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4583. //idx_sample=3;
  4584. //********************************(4)Power.Active.Import************************************************/
  4585. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4586. if(gunType[gun_index] == 'J')
  4587. {
  4588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4589. {
  4590. tempIndex = ((gun_index==2) ? 1: 0);
  4591. }
  4592. else
  4593. {
  4594. tempIndex = gun_index;
  4595. }
  4596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4597. {
  4598. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4599. {
  4600. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4601. }
  4602. } // END OF FOR
  4603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4604. }
  4605. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4606. {
  4607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4608. {
  4609. tempIndex = ((gun_index==2) ? 1: 0);
  4610. }
  4611. else
  4612. {
  4613. tempIndex = gun_index;
  4614. }
  4615. for (int index = 0; index < CCS_QUANTITY; index++)
  4616. {
  4617. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4618. {
  4619. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4620. }
  4621. }
  4622. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4623. }
  4624. else if(gunType[gun_index] == 'G')
  4625. {
  4626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4627. {
  4628. tempIndex = ((gun_index==2) ? 1: 0);
  4629. }
  4630. else
  4631. {
  4632. tempIndex = gun_index;
  4633. }
  4634. for (int index = 0; index < GB_QUANTITY; index++)
  4635. {
  4636. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4637. {
  4638. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4639. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4640. }
  4641. }
  4642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4643. }
  4644. else if(gunType[gun_index] == 'O')
  4645. {
  4646. tempIndex = gun_index;
  4647. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4648. {
  4649. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4650. {
  4651. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4652. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4653. }
  4654. }
  4655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4656. }
  4657. else
  4658. {
  4659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4660. {
  4661. tempIndex = 2;
  4662. }
  4663. else
  4664. {
  4665. tempIndex = gun_index;
  4666. }
  4667. for (int index = 0; index < AC_QUANTITY; index++)
  4668. {
  4669. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4670. {
  4671. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4672. }
  4673. }
  4674. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4675. }
  4676. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4677. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4678. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4679. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4681. //idx_sample=4;
  4682. //***********************************************(5)VOLTAGE L1******************************************************/
  4683. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4684. if(gunType[gun_index] == 'J')
  4685. {
  4686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4687. {
  4688. tempIndex = ((gun_index==2) ? 1: 0);
  4689. }
  4690. else
  4691. {
  4692. tempIndex = gun_index;
  4693. }
  4694. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4695. {
  4696. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4697. {
  4698. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4699. }
  4700. }
  4701. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4702. }
  4703. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4704. {
  4705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4706. {
  4707. tempIndex = ((gun_index==2) ? 1: 0);
  4708. }
  4709. else
  4710. {
  4711. tempIndex = gun_index;
  4712. }
  4713. for (int index = 0; index < CCS_QUANTITY; index++)
  4714. {
  4715. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4716. {
  4717. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4718. }
  4719. }
  4720. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4721. }
  4722. else if(gunType[gun_index] == 'G')
  4723. {
  4724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4725. {
  4726. tempIndex = ((gun_index==2) ? 1: 0);
  4727. }
  4728. else
  4729. {
  4730. tempIndex = gun_index;
  4731. }
  4732. for (int index = 0; index < GB_QUANTITY; index++)
  4733. {
  4734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4735. {
  4736. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4737. }
  4738. }
  4739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4740. }
  4741. else if(gunType[gun_index] == 'O')
  4742. {
  4743. tempIndex = gun_index;
  4744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4745. {
  4746. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4747. {
  4748. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4749. }
  4750. }
  4751. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4752. }
  4753. else
  4754. {
  4755. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4756. {
  4757. tempIndex = 2;
  4758. }
  4759. else
  4760. {
  4761. tempIndex = gun_index;
  4762. }
  4763. for (int index = 0; index < AC_QUANTITY; index++)
  4764. {
  4765. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4766. {
  4767. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4768. }
  4769. }
  4770. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4771. }
  4772. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4773. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4774. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4775. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4776. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4777. //***********************************************(6)SOC******************************************************/
  4778. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4779. {
  4780. //idx_sample=5;
  4781. //sampledValue = NULL;
  4782. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4783. {
  4784. tempIndex = ((gun_index==2) ? 1: 0);
  4785. }
  4786. else
  4787. {
  4788. tempIndex = gun_index;
  4789. }
  4790. if(gunType[gun_index] == 'J')
  4791. {
  4792. //tempIndex = ((gun_index==2) ? 1: 0);
  4793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4794. {
  4795. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4796. {
  4797. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4798. }
  4799. }
  4800. }
  4801. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4802. {
  4803. //tempIndex = ((gun_index==2) ? 1: 0);
  4804. for (int index = 0; index < CCS_QUANTITY; index++)
  4805. {
  4806. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4807. {
  4808. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4809. }
  4810. }
  4811. }
  4812. else if(gunType[gun_index] == 'G')
  4813. {
  4814. //tempIndex = ((gun_index==2) ? 1: 0);
  4815. for (int index = 0; index < GB_QUANTITY; index++)
  4816. {
  4817. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4818. {
  4819. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4820. }
  4821. }
  4822. }
  4823. else if(gunType[gun_index] == 'O')
  4824. {
  4825. //tempIndex = ((gun_index==2) ? 1: 0);
  4826. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4827. {
  4828. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4829. {
  4830. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4831. }
  4832. }
  4833. }
  4834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  4835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  4839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4840. }
  4841. //********************************(7)Current.Import L2************************************************/
  4842. // Only for AC 3 phase
  4843. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4844. {
  4845. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4846. {
  4847. tempIndex = 2;
  4848. }
  4849. else
  4850. {
  4851. tempIndex = gun_index;
  4852. }
  4853. for (int index = 0; index < AC_QUANTITY; index++)
  4854. {
  4855. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4856. {
  4857. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4858. }
  4859. }
  4860. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4861. }
  4862. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4863. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4865. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4866. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4867. //********************************(8)Current.Import L3************************************************/
  4868. // Only for AC 3 phase
  4869. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4870. {
  4871. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4872. {
  4873. tempIndex = 2;
  4874. }
  4875. else
  4876. {
  4877. tempIndex = gun_index;
  4878. }
  4879. for (int index = 0; index < AC_QUANTITY; index++)
  4880. {
  4881. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4882. {
  4883. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4884. }
  4885. }
  4886. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4887. }
  4888. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4889. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4890. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4891. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4892. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4893. //***********************************************(9)VOLTAGE L2******************************************************/
  4894. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4895. {
  4896. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4897. {
  4898. tempIndex = 2;
  4899. }
  4900. else
  4901. {
  4902. tempIndex = gun_index;
  4903. }
  4904. for (int index = 0; index < AC_QUANTITY; index++)
  4905. {
  4906. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4907. {
  4908. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4909. }
  4910. }
  4911. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4912. }
  4913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4918. //***********************************************(10)VOLTAGE L3******************************************************/
  4919. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4920. {
  4921. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4922. {
  4923. tempIndex = 2;
  4924. }
  4925. else
  4926. {
  4927. tempIndex = gun_index;
  4928. }
  4929. for (int index = 0; index < AC_QUANTITY; index++)
  4930. {
  4931. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4932. {
  4933. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4934. }
  4935. }
  4936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4937. }
  4938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4941. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4942. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4943. // Message create ====================================================================================================
  4944. if(TRUE)
  4945. {
  4946. json_object *MeterValueReq = json_object_new_object();
  4947. json_object *MeterValues = json_object_new_array();
  4948. json_object *sampledValues = json_object_new_array();
  4949. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  4950. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  4951. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  4952. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  4953. {
  4954. json_object *MeterValue = json_object_new_object();
  4955. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  4956. {
  4957. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  4958. {
  4959. json_object *sampledValue = json_object_new_object();
  4960. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  4961. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  4962. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  4963. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  4964. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  4965. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  4966. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  4967. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  4968. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  4969. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  4970. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  4971. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  4972. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  4973. json_object_array_add(sampledValues, sampledValue);
  4974. }
  4975. }
  4976. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  4977. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  4978. json_object_array_add(MeterValues, MeterValue);
  4979. }
  4980. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  4981. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  4982. ,gun_index + 1
  4983. ,MESSAGE_TYPE_CALL
  4984. ,guid
  4985. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  4986. json_object_put(MeterValueReq);
  4987. }
  4988. // Put request guid to hash map
  4989. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4990. 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*/)
  4991. {
  4992. result = PASS;
  4993. //DEBUG_INFO("MeterValues mapitem pass\n");
  4994. }
  4995. if((dataType != ReadingContext_Trigger) &&
  4996. (dataType != ReadingContext_Sample_Clock) &&
  4997. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  4998. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  4999. else
  5000. {
  5001. if(FirstHeartBeat)
  5002. LWS_Send(queuedata +2);
  5003. }
  5004. return result;
  5005. }
  5006. //==========================================
  5007. // send confirm routine
  5008. //==========================================
  5009. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5010. {
  5011. mtrace();
  5012. int result = FAIL;
  5013. char message[100]={0};
  5014. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5015. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5016. LWS_Send(message);
  5017. result = TRUE;
  5018. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5019. return result;
  5020. }
  5021. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5022. {
  5023. mtrace();
  5024. int result = FAIL;
  5025. char message[100]={0};
  5026. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5027. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5028. LWS_Send(message);
  5029. result = TRUE;
  5030. return result;
  5031. }
  5032. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5033. {
  5034. mtrace();
  5035. int result = FAIL;
  5036. char message[100]={0};
  5037. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5038. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5039. LWS_Send(message);
  5040. result = TRUE;
  5041. return result;
  5042. }
  5043. int sendClearCacheConfirmation(char *uuid,char *payload)
  5044. {
  5045. mtrace();
  5046. int result = FAIL;
  5047. char message[500]={0};
  5048. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5049. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5050. LWS_Send(message);
  5051. return result;
  5052. }
  5053. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5054. {
  5055. mtrace();
  5056. int result = FAIL;
  5057. char message[500]={0};
  5058. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5059. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5060. LWS_Send(message);
  5061. return result;
  5062. }
  5063. int sendDataTransferConfirmation(char *uuid,char *payload)
  5064. {
  5065. mtrace();
  5066. char statusStr[20]={0};
  5067. char dataStr[10]={0};
  5068. char sstr[20]={0};
  5069. int c = 0;
  5070. char *loc;
  5071. int result = FAIL;
  5072. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5073. /**********************status**************************/
  5074. loc = strstr(payload, "status");
  5075. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5076. c = 0;
  5077. while (loc[3+strlen("status")+c] != '\"')
  5078. {
  5079. sstr[c] = loc[3+strlen("status")+c];
  5080. c++;
  5081. }
  5082. sstr[c] = '\0';
  5083. strcpy(statusStr, sstr);
  5084. /**********************data**************************/
  5085. loc = strstr(payload, "data");
  5086. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5087. c = 0;
  5088. while (loc[3+strlen("data")+c] != '\"')
  5089. {
  5090. sstr[c] = loc[3+strlen("data")+c];
  5091. c++;
  5092. }
  5093. sstr[c] = '\0';
  5094. strcpy(dataStr, sstr);
  5095. return result;
  5096. }
  5097. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5098. {
  5099. mtrace();
  5100. int result = FAIL;
  5101. char message[1000]={0};
  5102. int CompositeScheduleIndex = 0;
  5103. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5104. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5105. if(nPeriod == 0)
  5106. {
  5107. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5108. {
  5109. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5110. ,MESSAGE_TYPE_CALLRESULT
  5111. ,uuid
  5112. ,payload
  5113. ,connectorIdInt);
  5114. }
  5115. else
  5116. {
  5117. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5118. ,MESSAGE_TYPE_CALLRESULT
  5119. ,uuid
  5120. ,payload
  5121. ,connectorIdInt
  5122. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5123. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5124. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5125. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5126. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5127. }
  5128. }
  5129. else
  5130. {
  5131. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5132. ,MESSAGE_TYPE_CALLRESULT
  5133. ,uuid
  5134. ,payload
  5135. ,connectorIdInt
  5136. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5137. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5138. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5139. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5140. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5141. {
  5142. if (idx_sample == 0)
  5143. {
  5144. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5145. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5146. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5147. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5148. }
  5149. else
  5150. {
  5151. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5152. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5153. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5154. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5155. }
  5156. }
  5157. sprintf(message + strlen(message), "]}}]");
  5158. }
  5159. LWS_Send(message);
  5160. result = TRUE;
  5161. return result;
  5162. }
  5163. int sendGetConfigurationConfirmation(char *uuid)
  5164. {
  5165. mtrace();
  5166. int result = FAIL;
  5167. int MaxKeySupported = 0;
  5168. int sentConfigurationNumber= 0;
  5169. int sentunConfigurationNumber= 0;
  5170. char message[4000]={0};
  5171. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5172. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5173. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5174. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5175. ,MESSAGE_TYPE_CALLRESULT
  5176. ,uuid );
  5177. //configuration key
  5178. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5179. {
  5180. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5181. {
  5182. if (sentConfigurationNumber == 0)
  5183. {
  5184. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5185. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5186. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5187. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5188. }
  5189. else
  5190. {
  5191. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5192. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5193. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5194. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5195. }
  5196. sentConfigurationNumber = sentConfigurationNumber + 1;
  5197. }
  5198. }
  5199. sprintf(message + strlen(message), "]");
  5200. if(UnknownKeynum != 0)
  5201. {
  5202. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5203. //unkown key
  5204. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5205. {
  5206. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5207. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5208. if(sentunConfigurationNumber == 0)
  5209. {
  5210. sprintf(message + strlen(message), "\"%s\""
  5211. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5212. }
  5213. else
  5214. {
  5215. sprintf(message + strlen(message), ",\"%s\""
  5216. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5217. }
  5218. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5219. }
  5220. sprintf(message + strlen(message), "]");
  5221. }
  5222. sprintf(message + strlen(message), "}]");
  5223. LWS_Send(message);
  5224. return result;
  5225. }
  5226. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5227. {
  5228. mtrace();
  5229. int result = FAIL;
  5230. char message[400]={0};
  5231. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5232. if(strcmp(payload,"")==0)
  5233. {
  5234. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5235. }
  5236. else
  5237. {
  5238. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5239. }
  5240. LWS_Send(message);
  5241. result = TRUE;
  5242. return result;
  5243. }
  5244. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5245. {
  5246. mtrace();
  5247. int result = FAIL;
  5248. char message[80]={0};
  5249. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5250. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5251. LWS_Send(message);
  5252. result = TRUE;
  5253. return result;
  5254. }
  5255. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5256. {
  5257. mtrace();
  5258. int result = FAIL;
  5259. char message[80]={0};
  5260. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5261. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5262. LWS_Send(message);
  5263. result = TRUE;
  5264. return result;
  5265. }
  5266. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5267. {
  5268. mtrace();
  5269. int result = FAIL;
  5270. char message[80]={0};
  5271. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5272. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5273. LWS_Send(message);
  5274. result = TRUE;
  5275. return result;
  5276. }
  5277. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5278. {
  5279. mtrace();
  5280. int result = FAIL;
  5281. char message[80]={0};
  5282. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5283. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5284. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5285. LWS_Send(message);
  5286. result = TRUE;
  5287. return result;
  5288. }
  5289. int sendResetConfirmation(char *uuid,char *payload)
  5290. {
  5291. mtrace();
  5292. int result = FAIL;
  5293. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5294. char message[80]={0};
  5295. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5296. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5297. LWS_Send(message);
  5298. result = TRUE;
  5299. return result;
  5300. }
  5301. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5302. {
  5303. mtrace();
  5304. int result = FAIL;
  5305. char message[500]={0};
  5306. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5307. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5308. LWS_Send(message);
  5309. result = TRUE;
  5310. return result;
  5311. }
  5312. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5313. {
  5314. mtrace();
  5315. int result = FAIL;
  5316. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5317. char message[80]={0};
  5318. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5319. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5320. LWS_Send(message);
  5321. result = TRUE;
  5322. return result;
  5323. }
  5324. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5325. {
  5326. mtrace();
  5327. int result = FAIL;
  5328. char message[80]={0};
  5329. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5330. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5331. LWS_Send(message);
  5332. result = TRUE;
  5333. return result;
  5334. }
  5335. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5336. {
  5337. mtrace();
  5338. int result = FAIL;
  5339. char message[80]={0};
  5340. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5341. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5342. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5343. LWS_Send(message);
  5344. result = TRUE;
  5345. return result;
  5346. }
  5347. int sendUpdateFirmwareConfirmation(char *uuid)
  5348. {
  5349. mtrace();
  5350. int result = FAIL;
  5351. char message[60]={0};
  5352. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5353. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5354. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5355. LWS_Send(message);
  5356. result = TRUE;
  5357. return result;
  5358. }
  5359. //==========================================
  5360. // send CallError routine
  5361. //==========================================
  5362. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5363. {
  5364. mtrace();
  5365. char message[220]={0};
  5366. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5367. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5368. LWS_Send(message);
  5369. }
  5370. //==========================================
  5371. // Handle server request routine Start
  5372. //==========================================
  5373. int handleCancelReservationRequest(char *uuid, char *payload)
  5374. {
  5375. mtrace();
  5376. int result = FAIL;
  5377. int gunNO = 0;
  5378. int reservationIdInt = -1;
  5379. char comfirmstr[20];
  5380. DEBUG_INFO("handleCancelReservationRequest...\n");
  5381. json_object *CancelReservation;
  5382. CancelReservation = json_tokener_parse(payload);
  5383. if(!is_error(CancelReservation))
  5384. {
  5385. // Required data
  5386. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5387. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5388. }
  5389. json_object_put(CancelReservation);
  5390. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5391. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5392. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5393. if(reservationIdInt != -1)
  5394. {
  5395. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5396. //check Transaction active
  5397. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5399. {
  5400. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5401. {
  5402. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5403. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5404. if(gunType[2] == 'J')
  5405. {
  5406. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5407. }
  5408. else
  5409. {
  5410. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5411. }
  5412. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5413. goto end;
  5414. }
  5415. }
  5416. for (int index = 0; index < CCS_QUANTITY; index++)
  5417. {
  5418. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5419. {
  5420. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5421. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5422. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5423. {
  5424. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5425. }
  5426. else
  5427. {
  5428. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5429. }
  5430. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5431. goto end;
  5432. }
  5433. }
  5434. for (int index = 0; index < GB_QUANTITY; index++)
  5435. {
  5436. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5437. {
  5438. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5439. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5440. if(gunType[2] == 'G')
  5441. {
  5442. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5443. }
  5444. else
  5445. {
  5446. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5447. }
  5448. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5449. goto end;
  5450. }
  5451. }
  5452. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5453. {
  5454. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5455. {
  5456. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5457. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5458. if(gunType[2] == 'G')
  5459. {
  5460. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index + 1;
  5461. }
  5462. else
  5463. {
  5464. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5465. }
  5466. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5467. goto end;
  5468. }
  5469. }
  5470. for (int index = 0; index < AC_QUANTITY; index++)
  5471. {
  5472. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5473. {
  5474. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5475. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5476. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5477. {
  5478. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5479. }
  5480. else
  5481. {
  5482. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5483. }
  5484. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5485. goto end;
  5486. }
  5487. }
  5488. }
  5489. //The reservationId does NOT match the reservationId
  5490. sendCancelReservationConfirmation(uuid, comfirmstr);
  5491. end:
  5492. // Fill in ocpp packet uuid
  5493. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5494. return result;
  5495. }
  5496. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5497. {
  5498. mtrace();
  5499. int result = FAIL;
  5500. int gunIndex = 0;
  5501. char typeStr[16]={0};
  5502. char comfirmstr[20];
  5503. int specificId = FALSE;
  5504. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5505. json_object *ChangeAvailability;
  5506. ChangeAvailability = json_tokener_parse(payload);
  5507. if(!is_error(ChangeAvailability))
  5508. {
  5509. // Required data
  5510. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5511. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5512. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5513. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5514. }
  5515. json_object_put(ChangeAvailability);
  5516. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5517. {
  5518. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5519. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5520. }
  5521. else if(gunIndex == 0)
  5522. {
  5523. for(int i=0; i < gunTotalNumber; i++)
  5524. {
  5525. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5526. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5527. }
  5528. }
  5529. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5530. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5531. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5532. {
  5533. specificId = TRUE;
  5534. }
  5535. if(specificId == FALSE)
  5536. goto end;
  5537. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5538. {
  5539. //----------------------gunIndex is 0 ------------------------------------------------//
  5540. if(gunIndex == 0)
  5541. {
  5542. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5543. {
  5544. for(int i=0; i < gunTotalNumber; i++)
  5545. {
  5546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5547. {
  5548. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5549. {
  5550. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5551. {
  5552. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5553. goto end;
  5554. }
  5555. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5556. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5557. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5558. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5559. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5560. {
  5561. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5562. goto end;
  5563. }
  5564. }
  5565. }//END FOR CHAdeMO_QUANTITY
  5566. for (int index = 0; index < CCS_QUANTITY; index++)
  5567. {
  5568. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5569. {
  5570. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5571. {
  5572. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5573. goto end;
  5574. }
  5575. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5576. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5577. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5578. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5579. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5580. {
  5581. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5582. goto end;
  5583. }
  5584. }
  5585. }//END FOR CCS_QUANTITY
  5586. for (int index = 0; index < GB_QUANTITY; index++)
  5587. {
  5588. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5589. {
  5590. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5591. {
  5592. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5593. goto end;
  5594. }
  5595. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5596. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5597. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5598. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5599. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5600. {
  5601. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5602. goto end;
  5603. }
  5604. }
  5605. }// END FOR GB_QUANTITY
  5606. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5607. {
  5608. if ((gunType[i] == 'O')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5609. {
  5610. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5611. {
  5612. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5613. goto end;
  5614. }
  5615. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5616. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5617. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5618. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5619. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5620. {
  5621. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5622. goto end;
  5623. }
  5624. }
  5625. }// END FOR GENERAL_GUN_QUANTITY
  5626. for (int index = 0; index < AC_QUANTITY; index++)
  5627. {
  5628. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5629. {
  5630. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5631. {
  5632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5633. goto end;
  5634. }
  5635. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5636. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5637. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5638. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5639. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5640. {
  5641. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5642. goto end;
  5643. }
  5644. }
  5645. }//END FOR AC_QUANTITY
  5646. }// END FOR gunTotalNumber
  5647. }
  5648. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5649. {
  5650. for(int i=0; i < gunTotalNumber; i++)
  5651. {
  5652. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5653. {
  5654. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5655. goto end;
  5656. }
  5657. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5658. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5659. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5660. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5661. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5662. {
  5663. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5664. goto end;
  5665. }
  5666. }
  5667. }
  5668. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5669. goto end;
  5670. }
  5671. //----------------------gunIndex is not 0 ------------------------------------------------//
  5672. //check Transaction active
  5673. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5674. {
  5675. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5676. {
  5677. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5678. {
  5679. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5680. goto end;
  5681. }
  5682. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5683. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5684. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5685. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5686. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5687. {
  5688. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5689. goto end;
  5690. }
  5691. else
  5692. {
  5693. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5695. goto end;
  5696. }
  5697. }
  5698. }//END FOR CHAdeMO_QUANTITY
  5699. for (int index = 0; index < CCS_QUANTITY; index++)
  5700. {
  5701. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5702. {
  5703. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5704. {
  5705. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5706. goto end;
  5707. }
  5708. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5709. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5710. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5711. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5712. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5713. {
  5714. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5715. goto end;
  5716. }
  5717. else
  5718. {
  5719. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5721. goto end;
  5722. }
  5723. }
  5724. }//END FOR CCS_QUANTITY
  5725. for (int index = 0; index < GB_QUANTITY; index++)
  5726. {
  5727. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5728. {
  5729. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5730. {
  5731. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5732. goto end;
  5733. }
  5734. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5735. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5736. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5737. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5738. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5739. {
  5740. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5741. goto end;
  5742. }
  5743. else
  5744. {
  5745. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5746. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5747. goto end;
  5748. }
  5749. }
  5750. }// END FOR GB_QUANTITY
  5751. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5752. {
  5753. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))
  5754. {
  5755. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5756. {
  5757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5758. goto end;
  5759. }
  5760. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5761. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5762. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5763. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5764. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5765. {
  5766. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5767. goto end;
  5768. }
  5769. else
  5770. {
  5771. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5772. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5773. goto end;
  5774. }
  5775. }
  5776. }// END FOR GENERAL_GUN_QUANTITY
  5777. for (int index = 0; index < AC_QUANTITY; index++)
  5778. {
  5779. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5780. {
  5781. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5782. {
  5783. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5784. goto end;
  5785. }
  5786. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5787. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5788. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5789. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5790. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5791. {
  5792. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5793. goto end;
  5794. }
  5795. else
  5796. {
  5797. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5798. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5799. goto end;
  5800. }
  5801. }
  5802. }//END FOR AC_QUANTITY
  5803. }//END FOR AvailabilityTypeStr[Inoperative]
  5804. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5805. {
  5806. //----------------------gunIndex is 0 ------------------------------------------------//
  5807. if(gunIndex == 0)
  5808. {
  5809. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5810. {
  5811. for(int i=0; i < gunTotalNumber; i++)
  5812. {
  5813. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5814. {
  5815. 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
  5816. {
  5817. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5818. goto end;
  5819. }
  5820. }//END FOR CHAdeMO_QUANTITY
  5821. for (int index = 0; index < CCS_QUANTITY; index++)
  5822. {
  5823. 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
  5824. {
  5825. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5826. goto end;
  5827. }
  5828. }//END FOR CCS_QUANTITY
  5829. for (int index = 0; index < GB_QUANTITY; index++)
  5830. {
  5831. 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
  5832. {
  5833. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5834. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5835. goto end;
  5836. }
  5837. }// END FOR GB_QUANTITY
  5838. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5839. {
  5840. 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
  5841. {
  5842. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5843. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5844. goto end;
  5845. }
  5846. }// END FOR GENERAL_GUN_QUANTITY
  5847. for (int index = 0; index < AC_QUANTITY; index++)
  5848. {
  5849. 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
  5850. {
  5851. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5852. goto end;
  5853. }
  5854. }//END FOR CHAdeMO_QUANTITY
  5855. }// END FOR gunTotalNumber
  5856. }
  5857. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5858. {
  5859. for(int i=0; i < gunTotalNumber; i++)
  5860. {
  5861. for (int index = 0; index < AC_QUANTITY; index++)
  5862. {
  5863. 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
  5864. {
  5865. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5866. goto end;
  5867. }
  5868. }//END FOR CHAdeMO_QUANTITY
  5869. } // END FOR gunTotalNumber
  5870. }
  5871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5872. goto end;
  5873. }
  5874. //----------------------gunIndex is not 0 ------------------------------------------------//
  5875. //check Transaction active
  5876. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5877. {
  5878. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5879. {
  5880. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5881. goto end;
  5882. }
  5883. }//END FOR CHAdeMO_QUANTITY
  5884. for (int index = 0; index < CCS_QUANTITY; index++)
  5885. {
  5886. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5887. {
  5888. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5889. goto end;
  5890. }
  5891. }//END FOR CCS_QUANTITY
  5892. for (int index = 0; index < GB_QUANTITY; index++)
  5893. {
  5894. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5895. {
  5896. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5897. goto end;
  5898. }
  5899. }// END FOR GB_QUANTITY
  5900. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5901. {
  5902. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5903. {
  5904. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5905. goto end;
  5906. }
  5907. }// END FOR GENERAL_GUN_QUANTITY
  5908. for (int index = 0; index < AC_QUANTITY; index++)
  5909. {
  5910. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5911. {
  5912. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5913. goto end;
  5914. }
  5915. }//END FOR AC_QUANTITY
  5916. }//END FOR AvailabilityTypeStr[Operative]
  5917. end:
  5918. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5919. {
  5920. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5921. }
  5922. else
  5923. {
  5924. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5925. }
  5926. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5927. {
  5928. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5929. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5930. }
  5931. else if(gunIndex == 0)
  5932. {
  5933. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5934. {
  5935. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5936. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5937. }
  5938. }
  5939. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5940. return result;
  5941. }
  5942. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5943. {
  5944. mtrace();
  5945. int result = FAIL;
  5946. char keystr[40]={0};
  5947. char valuestr[100]={0};
  5948. char comfirmstr[20]={0};
  5949. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5950. json_object *ChangeConfiguration;
  5951. ChangeConfiguration = json_tokener_parse(payload);
  5952. if(!is_error(ChangeConfiguration))
  5953. {
  5954. // Required data
  5955. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  5956. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5957. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  5958. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5959. }
  5960. json_object_put(ChangeConfiguration);
  5961. if((uuid==NULL) || (payload ==NULL) )
  5962. {
  5963. DEBUG_ERROR("Payload is null\n");
  5964. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5965. }
  5966. else
  5967. {
  5968. int status = setKeyValue(keystr, valuestr);
  5969. switch(status)
  5970. {
  5971. case ConfigurationStatus_Accepted:
  5972. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5973. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5974. StoreConfigurationTable();
  5975. break;
  5976. case RebootRequired:
  5977. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5978. StoreConfigurationTable();
  5979. break;
  5980. case NotSupported:
  5981. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5982. break;
  5983. case ConfigurationStatus_Rejected:
  5984. default:
  5985. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5986. break;
  5987. }
  5988. }
  5989. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5990. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5991. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5992. {
  5993. ChageWebSocketPingInterval(atoi(valuestr));
  5994. }
  5995. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5996. {
  5997. SetOcppConnStatus(FALSE);
  5998. }
  5999. return result;
  6000. }
  6001. int handleClearCacheRequest(char *uuid, char *payload)
  6002. {
  6003. mtrace();
  6004. int result = FAIL;
  6005. char comfirmstr[20];
  6006. char rmFileCmd[100]={0};
  6007. struct stat stats;
  6008. DEBUG_INFO("handleClearCacheRequest...\n");
  6009. stat("/Storage/OCPP", &stats);
  6010. // Check for directory existence
  6011. if (S_ISDIR(stats.st_mode) == 1)
  6012. {}
  6013. else
  6014. {
  6015. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6016. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6017. system(rmFileCmd);
  6018. }
  6019. if(OCPP_cleanLocalCache())
  6020. {
  6021. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6022. }
  6023. else
  6024. {
  6025. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6026. }
  6027. sendClearCacheConfirmation(uuid, comfirmstr);
  6028. return result;
  6029. }
  6030. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6031. {
  6032. mtrace();
  6033. int result = FAIL;
  6034. int resultRename;
  6035. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6036. char chargingProfilePurposeStr[26]={0};
  6037. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6038. char tempchargingProfilePurposeStr[26]={0};
  6039. char str[100]={0};
  6040. char fname[200]={0};
  6041. char comfirmstr[20]={0};
  6042. char word[1600]={0};
  6043. int clearflag = FALSE;
  6044. int chargingProfileIdIsNULL = FALSE;
  6045. int connectorIsNULL = FALSE;
  6046. int chargingProfilePurposeIsNULL = FALSE;
  6047. int stackLevelIsNULL = FALSE;
  6048. //int GotoEnd = FALSE;
  6049. FILE *fptr1, *fptr2;
  6050. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6051. int n_chargingProfile=0;
  6052. int isEmptyFile = FALSE;
  6053. char sLineWord[1600]={0};
  6054. char chargingProfiles[10][100]={0};
  6055. int ChargeProfileCount = 0;
  6056. int ch;
  6057. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6058. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6059. json_object *ClearChargingProfile;
  6060. ClearChargingProfile = json_tokener_parse(payload);
  6061. if(!is_error(ClearChargingProfile))
  6062. {
  6063. // Optional data
  6064. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6065. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6066. else
  6067. chargingProfileIdIsNULL = TRUE;
  6068. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6069. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6070. else
  6071. connectorIsNULL = TRUE;
  6072. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6073. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6074. else
  6075. chargingProfilePurposeIsNULL = TRUE;
  6076. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6077. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6078. else
  6079. stackLevelIsNULL = TRUE;
  6080. }
  6081. json_object_put(ClearChargingProfile);
  6082. if(connectorIsNULL == FALSE)
  6083. {
  6084. switch(connectorIdInt)
  6085. {
  6086. case 0:
  6087. if(chargingProfilePurposeIsNULL == TRUE)
  6088. {
  6089. int l = 0;
  6090. strcpy(fname, ChargePointMaxProfile_JSON);
  6091. if((access(fname,F_OK))!=-1)
  6092. {
  6093. strcpy(chargingProfiles[l], fname);
  6094. l = l + 1;
  6095. }
  6096. strcpy(fname, TxDefaultProfile_0_JSON);
  6097. if((access(fname,F_OK))!=-1)
  6098. {
  6099. strcpy(chargingProfiles[l], fname);
  6100. l = l + 1;
  6101. }
  6102. ChargeProfileCount = l;
  6103. }
  6104. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6105. {
  6106. strcpy(fname, ChargePointMaxProfile_JSON);
  6107. if((access(fname,F_OK))!=-1)
  6108. {
  6109. strcpy(chargingProfiles[0], fname);
  6110. ChargeProfileCount = 1;
  6111. }
  6112. }
  6113. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6114. {
  6115. strcpy(fname, TxDefaultProfile_0_JSON);
  6116. if((access(fname,F_OK))!=-1)
  6117. {
  6118. strcpy(chargingProfiles[0], fname);
  6119. ChargeProfileCount = 1;
  6120. }
  6121. }
  6122. break;
  6123. default:
  6124. if(chargingProfilePurposeIsNULL == TRUE)
  6125. {
  6126. int m = 0;
  6127. memset(fname, 0, ARRAY_SIZE(fname));
  6128. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6129. if((access(fname,F_OK))!=-1)
  6130. {
  6131. strcpy(chargingProfiles[m], fname);
  6132. m = m + 1;
  6133. }
  6134. memset(fname, 0, ARRAY_SIZE(fname));
  6135. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6136. if((access(fname,F_OK))!=-1)
  6137. {
  6138. strcpy(chargingProfiles[m], fname);
  6139. m = m + 1;
  6140. }
  6141. ChargeProfileCount = m;
  6142. }
  6143. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6144. {
  6145. //strcpy(fname, TxDefaultProfile_1_JSON);
  6146. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6147. if((access(fname,F_OK))!=-1)
  6148. {
  6149. strcpy(chargingProfiles[0], fname);
  6150. ChargeProfileCount = 1;
  6151. }
  6152. }
  6153. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6154. {
  6155. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6156. if((access(fname,F_OK))!=-1)
  6157. {
  6158. strcpy(chargingProfiles[0], fname);
  6159. ChargeProfileCount = 1;
  6160. }
  6161. //strcpy(fname, TxProfile_1_JSON);
  6162. }
  6163. //strcpy(fname, ChargePointMaxProfile_JSON );
  6164. break;
  6165. }
  6166. }
  6167. else // Check all Charging Profiles
  6168. {
  6169. int i = 0;
  6170. char fnametemp[200]={0};
  6171. ChargeProfileCount = 0;
  6172. //Check ChargePointMaxProfile.json exit
  6173. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6174. {
  6175. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6176. i = i + 1;
  6177. }
  6178. //Check TxDefaultProfile_0.json exit
  6179. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6180. {
  6181. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6182. i = i + 1;
  6183. }
  6184. //Check TxDefaultProfile_%d.json
  6185. for(int j=1; j <= gunTotalNumber; j++)
  6186. {
  6187. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6188. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6189. if((access(fnametemp,F_OK))!=-1)
  6190. {
  6191. strcpy(chargingProfiles[i], fnametemp);
  6192. i = i + 1;
  6193. }
  6194. }
  6195. //Check TxProfile_%d.json
  6196. for(int j=1; j <= gunTotalNumber; j++)
  6197. {
  6198. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6199. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6200. if((access(fnametemp,F_OK))!=-1)
  6201. {
  6202. strcpy(chargingProfiles[i], fnametemp);
  6203. i = i + 1;
  6204. }
  6205. }
  6206. ChargeProfileCount = i;
  6207. }// End connectorIsNULL is TRUE
  6208. if(ChargeProfileCount == 0)
  6209. {
  6210. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6211. goto end;
  6212. }
  6213. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6214. {
  6215. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6216. goto end;
  6217. }
  6218. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6219. {
  6220. memset(str, 0, ARRAY_SIZE(str));
  6221. // clear temp file
  6222. sprintf(str,"rm -f %s",temp);
  6223. system(str);
  6224. for(int k=0; k < ChargeProfileCount; k++)
  6225. {
  6226. memset(str, 0, ARRAY_SIZE(str));
  6227. //clear file in C
  6228. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6229. system(str);
  6230. }
  6231. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6232. goto end;
  6233. }
  6234. else if(connectorIsNULL == TRUE)
  6235. {
  6236. for(int k=0; k < ChargeProfileCount; k++)
  6237. {
  6238. fptr1 = fopen(chargingProfiles[k], "r");
  6239. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6240. //Check Charging Profile Count
  6241. while(fscanf(fptr1, "%s", word) != EOF)
  6242. {
  6243. //DEBUG_INFO("word=%s\n",word);
  6244. if(strstr(word, "chargingProfileId")!= NULL)
  6245. {
  6246. //DEBUG_INFO("test chargingProfileId \n");
  6247. n_chargingProfile = n_chargingProfile + 1;
  6248. //DEBUG_INFO("chargingProfileId Found\n");
  6249. }
  6250. }
  6251. rewind(fptr1);
  6252. //search Charging Profile Element
  6253. //int i= 0;
  6254. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6255. {
  6256. json_object *tmpProfilee;
  6257. tmpProfilee = json_tokener_parse(sLineWord);
  6258. if(!is_error(tmpProfilee))
  6259. {
  6260. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6261. {
  6262. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6263. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6264. }
  6265. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6266. {
  6267. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6268. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6269. }
  6270. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6271. {
  6272. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6273. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6274. }
  6275. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6276. {
  6277. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6278. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6279. }
  6280. }
  6281. json_object_put(tmpProfilee);
  6282. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6283. {
  6284. //------- not write to fptr2-------//
  6285. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6286. //clearflag = TRUE;
  6287. }
  6288. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6289. {
  6290. //------- not write to fptr2-------//
  6291. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6292. }
  6293. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6294. {
  6295. //------- not write to fptr2-------//
  6296. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6297. }
  6298. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6299. {
  6300. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6301. }
  6302. else
  6303. {
  6304. fprintf(fptr2, sLineWord);//writing data into file
  6305. }
  6306. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6307. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6308. if(clearflag == TRUE)
  6309. {
  6310. fclose(fptr1);
  6311. fclose(fptr2);
  6312. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6313. system(str);
  6314. // clear temp file
  6315. sprintf(str,"rm -f %s",temp);
  6316. system(str);
  6317. }
  6318. else
  6319. {
  6320. fclose(fptr1);
  6321. fclose(fptr2);
  6322. memset(str, 0, ARRAY_SIZE(str));
  6323. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6324. system(str);
  6325. resultRename = rename(temp, chargingProfiles[k]);
  6326. if(resultRename == 0)
  6327. {
  6328. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6329. }
  6330. else
  6331. {
  6332. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6333. }
  6334. if(comfirmstr[0]== 0)
  6335. {
  6336. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6337. }
  6338. //Check chargingProfile is empty file
  6339. /*------ Read the file ----------------*/
  6340. fptr1=fopen(chargingProfiles[k],"r");
  6341. ch=fgetc(fptr1);
  6342. rewind(fptr1);
  6343. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6344. if(ch!=EOF)
  6345. {
  6346. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6347. {
  6348. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6349. if(sLineWord[0]=='\0')
  6350. {
  6351. isEmptyFile = TRUE;
  6352. break;
  6353. }
  6354. else
  6355. {
  6356. isEmptyFile = FALSE;
  6357. break;
  6358. }
  6359. }
  6360. }
  6361. else
  6362. isEmptyFile = TRUE;
  6363. fclose(fptr1);
  6364. if(isEmptyFile == TRUE)
  6365. {
  6366. memset(str, 0, ARRAY_SIZE(str));
  6367. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6368. system(str);
  6369. }
  6370. }
  6371. }// End of while(int k=0; k < ChargePointCount; k++)
  6372. }
  6373. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6374. {
  6375. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6376. for(int k=0; k < ChargeProfileCount; k++)
  6377. {
  6378. fptr1 = fopen(chargingProfiles[k], "r");
  6379. fptr2 = fopen(temp, "w+");
  6380. //Check Charging Profile Count
  6381. while(fscanf(fptr1, "%s", word) != EOF)
  6382. {
  6383. //DEBUG_INFO("word=%s\n",word);
  6384. if(strstr(word, "chargingProfileId")!= NULL)
  6385. {
  6386. n_chargingProfile = n_chargingProfile + 1;
  6387. }
  6388. }
  6389. rewind(fptr1);
  6390. //search Charging Profile Element
  6391. //int i= 0;
  6392. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6393. {
  6394. json_object *tmpProfilee;
  6395. tmpProfilee = json_tokener_parse(sLineWord);
  6396. if(!is_error(tmpProfilee))
  6397. {
  6398. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6399. {
  6400. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6401. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6402. }
  6403. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6404. {
  6405. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6406. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6407. }
  6408. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6409. {
  6410. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6411. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6412. }
  6413. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6414. {
  6415. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6416. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6417. }
  6418. }
  6419. json_object_put(tmpProfilee);
  6420. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6421. {
  6422. //------- not write to fptr2-------//
  6423. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6424. //clearflag = TRUE;
  6425. }
  6426. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6427. {
  6428. //------- not write to fptr2-------//
  6429. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6430. }
  6431. else if(stackLevelIsNULL == TRUE)
  6432. {
  6433. //Clear Whole File
  6434. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6435. clearflag = TRUE;
  6436. break;
  6437. }
  6438. else
  6439. {
  6440. fprintf(fptr2, sLineWord);//writing data into file
  6441. }
  6442. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6443. }
  6444. if(clearflag == TRUE)
  6445. {
  6446. fclose(fptr1);
  6447. fclose(fptr2);
  6448. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6449. system(str);
  6450. // clear temp file
  6451. sprintf(str,"rm -f %s",temp);
  6452. system(str);
  6453. }
  6454. else
  6455. {
  6456. fclose(fptr1);
  6457. fclose(fptr2);
  6458. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6459. system(str);
  6460. resultRename = rename(temp, chargingProfiles[k]);
  6461. if(resultRename == 0)
  6462. {
  6463. DEBUG_INFO("File ChargingProfile renamed successfully");
  6464. }
  6465. else
  6466. {
  6467. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6468. }
  6469. if(comfirmstr[0]== 0)
  6470. {
  6471. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6472. }
  6473. //Check chargingProfile is empty file
  6474. /*------ Read the file ----------------*/
  6475. fptr1=fopen(chargingProfiles[k],"r");
  6476. ch=fgetc(fptr1);
  6477. rewind(fptr1);
  6478. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6479. if(ch!=EOF)
  6480. {
  6481. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6482. {
  6483. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6484. if(sLineWord[0]=='\0')
  6485. {
  6486. isEmptyFile = TRUE;
  6487. break;
  6488. }
  6489. else
  6490. {
  6491. isEmptyFile = FALSE;
  6492. break;
  6493. }
  6494. }
  6495. }
  6496. else
  6497. isEmptyFile = TRUE;
  6498. fclose(fptr1);
  6499. if(isEmptyFile == TRUE)
  6500. {
  6501. memset(str, 0, ARRAY_SIZE(str));
  6502. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6503. system(str);
  6504. }
  6505. /*------- End of reading ---------------*/
  6506. }
  6507. } // while(int k=0; k < ChargeProfileCount; k++)
  6508. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6509. end:
  6510. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6511. {
  6512. if(connectorIdInt == 0)
  6513. {
  6514. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6515. {
  6516. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  6517. }
  6518. }
  6519. else
  6520. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  6521. }
  6522. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6523. return result;
  6524. }
  6525. void createFirmwareVersionByDataTransfer(void)
  6526. {
  6527. json_object *FirmwareDataTransfer = json_object_new_object();
  6528. // AC & DC model
  6529. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6530. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6531. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6532. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6533. // DC model
  6534. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  6535. {
  6536. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6537. {
  6538. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6539. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6540. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6541. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6542. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6543. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6544. }
  6545. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6546. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6547. {
  6548. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6549. }
  6550. }
  6551. else
  6552. {
  6553. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6554. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6555. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6556. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6557. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  6558. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  6559. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  6560. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  6561. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  6562. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  6563. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  6564. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  6565. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  6566. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  6567. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  6568. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  6569. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  6570. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  6571. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  6572. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  6573. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  6574. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  6575. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  6576. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  6577. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  6578. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  6579. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  6580. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  6581. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  6582. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  6583. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  6584. }
  6585. // 4G model
  6586. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6587. {
  6588. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6589. }
  6590. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6591. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6592. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6593. json_object_put(FirmwareDataTransfer);
  6594. }
  6595. int handleDataTransferRequest(char *uuid, char *payload)
  6596. {
  6597. mtrace();
  6598. json_object *response = json_object_new_object();
  6599. int result = FAIL;
  6600. char tempvendorId[255]={0};
  6601. char tempmessageId[50]={0};
  6602. char tempdata[512]={0};
  6603. char message[2048]={0};
  6604. DEBUG_INFO("handleDataTransferRequest...\n");
  6605. if((uuid != NULL) && (payload != NULL))
  6606. {
  6607. json_object *DataTransfer;
  6608. DataTransfer = json_tokener_parse(payload);
  6609. if(!is_error(DataTransfer))
  6610. {
  6611. // Required data
  6612. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6613. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6614. // Optional data
  6615. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6616. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6617. if(json_object_object_get(DataTransfer, "data") != NULL)
  6618. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6619. result = PASS;
  6620. }
  6621. json_object_put(DataTransfer);
  6622. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6623. {
  6624. // Send all moudle firmware version on EVSE
  6625. createFirmwareVersionByDataTransfer();
  6626. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6627. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6628. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6629. json_object_put(response);
  6630. }
  6631. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  6632. {
  6633. system("/usr/bin/run_tmate_restart.sh &");
  6634. }
  6635. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6636. {
  6637. json_object *data;
  6638. data = json_tokener_parse(tempdata);
  6639. if(!is_error(data))
  6640. {
  6641. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6642. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6643. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6644. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6645. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6646. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6647. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6648. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6649. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6650. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6651. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6652. }
  6653. else
  6654. {
  6655. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6656. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6657. }
  6658. json_object_put(data);
  6659. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6660. json_object_put(response);
  6661. }
  6662. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6663. {
  6664. json_object *data;
  6665. data = json_tokener_parse(tempdata);
  6666. if(!is_error(data))
  6667. {
  6668. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  6669. if(json_object_object_get(data, "idToken") != NULL)
  6670. {
  6671. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  6672. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6673. }
  6674. if(json_object_object_get(data, "price") != NULL)
  6675. {
  6676. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  6677. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6678. }
  6679. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6680. }
  6681. else
  6682. {
  6683. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6684. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6685. }
  6686. json_object_put(data);
  6687. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6688. json_object_put(response);
  6689. }
  6690. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6691. {
  6692. json_object *data;
  6693. data = json_tokener_parse(tempdata);
  6694. if(!is_error(data))
  6695. {
  6696. if(json_object_object_get(data, "txId") != NULL)
  6697. {
  6698. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6699. for(int idx = 0;idx<gunTotalNumber;idx++)
  6700. {
  6701. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6702. {
  6703. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6704. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6705. if(json_object_object_get(data, "description") != NULL)
  6706. {
  6707. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6708. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6709. }
  6710. }
  6711. }
  6712. }
  6713. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6714. }
  6715. else
  6716. {
  6717. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6718. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6719. }
  6720. json_object_put(data);
  6721. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6722. json_object_put(response);
  6723. }
  6724. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6725. {
  6726. json_object *data;
  6727. data = json_tokener_parse(tempdata);
  6728. if(!is_error(data))
  6729. {
  6730. if(json_object_object_get(data, "txId") != NULL)
  6731. {
  6732. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6733. for(int idx = 0;idx<gunTotalNumber;idx++)
  6734. {
  6735. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6736. {
  6737. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6738. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6739. if(json_object_object_get(data, "description") != NULL)
  6740. {
  6741. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6742. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6743. }
  6744. }
  6745. }
  6746. }
  6747. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6748. }
  6749. else
  6750. {
  6751. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6752. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6753. }
  6754. json_object_put(data);
  6755. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6756. json_object_put(response);
  6757. }
  6758. else
  6759. {
  6760. // Can not find valid message id
  6761. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6762. }
  6763. }
  6764. else
  6765. {
  6766. // Payload is null
  6767. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6768. }
  6769. LWS_Send(message);
  6770. return result;
  6771. }
  6772. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6773. {
  6774. mtrace();
  6775. int result = FAIL;
  6776. int connectorIdInt, durationInt;
  6777. char chargingRateUnitStr[4]={0};
  6778. char comfirmstr[20];
  6779. int confirmPeriods = 0;
  6780. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6781. json_object *GetCompositeSchedule;
  6782. GetCompositeSchedule = json_tokener_parse(payload);
  6783. if(!is_error(GetCompositeSchedule))
  6784. {
  6785. // Required data
  6786. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6787. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6788. else
  6789. connectorIdInt = -1;
  6790. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6791. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6792. else
  6793. durationInt = 86400;
  6794. // Optional data
  6795. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6796. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6797. }
  6798. json_object_put(GetCompositeSchedule);
  6799. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6800. if((connectorIdInt == 0) ||
  6801. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6802. {
  6803. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6804. struct StructChargingProfile tmpProfile[1];
  6805. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6806. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6807. {
  6808. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6809. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6810. }
  6811. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6812. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6813. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6814. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6815. {
  6816. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6817. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6818. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6819. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6820. {
  6821. confirmPeriods = idx;
  6822. break;
  6823. }
  6824. }
  6825. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6826. }
  6827. else
  6828. {
  6829. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6830. }
  6831. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6832. return result;
  6833. }
  6834. int handleGetConfigurationRequest(char *uuid, char *payload)
  6835. {
  6836. mtrace();
  6837. int result = FAIL;
  6838. int MaxKeySupported = 0;
  6839. int n_keys = 0;
  6840. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6841. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6842. json_object *GetConfiguration;
  6843. GetConfiguration = json_tokener_parse(payload);
  6844. if(!is_error(GetConfiguration))
  6845. {
  6846. // Optional data
  6847. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6848. {
  6849. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6850. {
  6851. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6852. n_keys = idx + 1;
  6853. }
  6854. }
  6855. }
  6856. json_object_put(GetConfiguration);
  6857. UnknownKeynum = 0;
  6858. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6859. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6860. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6861. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6862. if(n_keys != 0)
  6863. {
  6864. for(int i=0;i<n_keys;i++)
  6865. {
  6866. getKeyValue(requestKey[i]);
  6867. }
  6868. }
  6869. else
  6870. {
  6871. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6872. getKeyValue("");
  6873. }
  6874. processUnkownKey();
  6875. sendGetConfigurationConfirmation(uuid);
  6876. return result;
  6877. }
  6878. static char fnamePlusPath[100]={0};
  6879. static char fnamePWithNoPath[60]={0};
  6880. void checkUploadLog(void)
  6881. {
  6882. FILE *fp;
  6883. /* Open the command for reading. */
  6884. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6885. if (fp == NULL) {
  6886. printf("Failed to run command\n" );
  6887. exit(1);
  6888. }
  6889. int ftppathlen = 0;
  6890. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6891. int i = 0;
  6892. /* Read the output a line at a time - output it. */
  6893. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6894. if(i==0)
  6895. {
  6896. ftppathlen = strlen(fnamePlusPath);
  6897. printf("%s\n", fnamePlusPath);
  6898. fnamePlusPath[ftppathlen]='\0';
  6899. break;
  6900. }
  6901. i= i+1;
  6902. }
  6903. /* close */
  6904. pclose(fp);
  6905. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6906. {
  6907. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  6908. {
  6909. fnamePlusPath[k]='\0';
  6910. }
  6911. }
  6912. i=1;
  6913. //char fname[60]={0};
  6914. while(i < ftppathlen)
  6915. {
  6916. int len=ftppathlen-i;
  6917. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6918. {
  6919. printf("compare '/' all right\n");
  6920. break;
  6921. }
  6922. i=i+1;
  6923. }
  6924. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6925. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6926. fnamePWithNoPath[i+1] = '\0';
  6927. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6928. {
  6929. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6930. {
  6931. fnamePWithNoPath[j]='\0';
  6932. }
  6933. }
  6934. FILE* fp1 = fopen(fnamePlusPath, "r");
  6935. if (fp1)
  6936. {
  6937. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6938. // file exists
  6939. fclose(fp1);
  6940. }
  6941. else
  6942. {
  6943. // file doesn't exist
  6944. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6945. }
  6946. }
  6947. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6948. {
  6949. mtrace();
  6950. int result = FAIL;
  6951. time_t CurrentTime;
  6952. struct tm *tm;
  6953. pthread_t th_Status;
  6954. CurrentTime = time(NULL);
  6955. tm = localtime(&CurrentTime);
  6956. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  6957. 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);
  6958. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6959. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6960. return result;
  6961. }
  6962. void* GetDiagnosticsProcess(void* data)
  6963. {
  6964. pthread_detach(pthread_self());
  6965. mtrace();
  6966. int retriesInt=0, retryIntervalInt=0;
  6967. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6968. 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};
  6969. int port=0;
  6970. int isSuccess = FALSE;
  6971. char ftpbuf[200]={0};
  6972. char cmdBuf[512];
  6973. json_object *GetDiagnostics;
  6974. DEBUG_INFO("GetDiagnosticsProcess...\n");
  6975. GetDiagnostics = json_tokener_parse(data);
  6976. if(!is_error(GetDiagnostics))
  6977. {
  6978. // Required data
  6979. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  6980. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  6981. // Optional data
  6982. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  6983. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  6984. else
  6985. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6986. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  6987. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  6988. else
  6989. retryIntervalInt = 30;
  6990. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  6991. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  6992. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  6993. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  6994. }
  6995. json_object_put(GetDiagnostics);
  6996. // Pack log to compress file
  6997. system("exec /root/logPackTools 'log' 6");
  6998. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6999. system(cmdBuf);
  7000. checkUploadLog();
  7001. //****************location*******************/
  7002. if(strcmp(locationstr,"")==0)
  7003. {
  7004. DEBUG_INFO("location is <Empty>!\n");
  7005. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7006. goto end;
  7007. }
  7008. memset(protocol, 0, ARRAY_SIZE(protocol));
  7009. memset(user, 0, ARRAY_SIZE(user) );
  7010. memset(password, 0, ARRAY_SIZE(password));
  7011. memset(host, 0, ARRAY_SIZE(host));
  7012. memset(path, 0, ARRAY_SIZE(path));
  7013. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7014. memset(host1, 0, ARRAY_SIZE(host1));
  7015. memset(path1, 0, ARRAY_SIZE(path1));
  7016. /*location: ftp://user:password@host:port/path*/
  7017. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7018. if((access(fnamePlusPath,F_OK))!=-1)
  7019. {
  7020. DEBUG_INFO("fnamePlusPath exist.\n");
  7021. }
  7022. else
  7023. {
  7024. DEBUG_INFO("fnamePlusPath not exist!\n");
  7025. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7026. goto end;
  7027. }
  7028. if(strchr(locationstr,'@')==NULL)
  7029. {
  7030. sscanf(locationstr,
  7031. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7032. protocol, host, &port, path);
  7033. strcpy(user,"anonymous");
  7034. strcpy(password,"");
  7035. }
  7036. else
  7037. {
  7038. //DEBUG_INFO("pch=%s\n", pch);
  7039. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7040. protocol, user, password, host, &port, path);
  7041. }
  7042. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7043. {
  7044. DEBUG_INFO("protocol is not ftp/http ! \n");
  7045. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7046. goto end;
  7047. }
  7048. if(strncmp(locationstr,"http", 4) == 0)
  7049. {
  7050. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7051. sprintf(ftppath,"/%s", path);
  7052. do
  7053. {
  7054. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7055. sleep(3);
  7056. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7057. if(!isSuccess)
  7058. {
  7059. DEBUG_INFO("Diagnostics fail.\n");
  7060. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7061. sleep(retryIntervalInt);
  7062. }
  7063. else
  7064. {
  7065. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7066. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7067. }
  7068. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  7069. }
  7070. else
  7071. {
  7072. sscanf(host,"%[^/]%s",host1, path1);
  7073. sprintf(ftppath,"%s", path1);
  7074. int ftppathlen=strlen(ftppath);
  7075. int i=1;
  7076. char filenametemp[50];
  7077. while(i < ftppathlen)
  7078. {
  7079. int len=ftppathlen-i;
  7080. if(ftppath[len]== 47) // '/' ascll code: 47
  7081. {
  7082. DEBUG_INFO("find '/' all right\n");
  7083. break;
  7084. }
  7085. i=i+1;
  7086. }
  7087. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7088. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7089. filenametemp[i+1] = 0;
  7090. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7091. if(port == 0)
  7092. port = 21;
  7093. do
  7094. {
  7095. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7096. sleep(3);
  7097. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7098. if(!isSuccess)
  7099. {
  7100. DEBUG_INFO("Diagnostics fail.\n");
  7101. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7102. sleep(retryIntervalInt);
  7103. }
  7104. else
  7105. {
  7106. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7107. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7108. }
  7109. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  7110. }
  7111. end:
  7112. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7113. pthread_exit(NULL);
  7114. }
  7115. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7116. {
  7117. mtrace();
  7118. int result = FAIL;
  7119. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7120. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7121. {
  7122. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7123. localversion = -1;
  7124. }
  7125. else
  7126. {
  7127. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7128. OCPP_getListVerion();
  7129. }
  7130. //from db.OCPP_getListVerion
  7131. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7132. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7133. sendGetLocalListVersionConfirmation(uuid,"");
  7134. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7135. return result;
  7136. }
  7137. int handleRemoteStartRequest(char *uuid, char *payload)
  7138. {
  7139. mtrace();
  7140. int result = FAIL;
  7141. int connectorIdInt=0;
  7142. int tempIndex = 0;
  7143. int connectorIdIsNULL, chargingProfileIsNULL;
  7144. char comfirmstr[20]={0};
  7145. char cmdBuf[512];
  7146. json_object *RemoteStartTransaction;
  7147. FILE *fp;
  7148. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7149. if(server_pending == TRUE)
  7150. {
  7151. return 0;
  7152. }
  7153. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7154. RemoteStartTransaction = json_tokener_parse(payload);
  7155. if(!is_error(RemoteStartTransaction))
  7156. {
  7157. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7158. {
  7159. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7160. if(connectorIdInt <= gunTotalNumber)
  7161. {
  7162. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7163. // Required data
  7164. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7165. // Optional data
  7166. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7167. {
  7168. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7169. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7170. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7171. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7172. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7173. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7174. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7175. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7176. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7177. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7178. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7179. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7180. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7181. {
  7182. 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")));
  7183. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7184. 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"));
  7185. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7186. 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"));
  7187. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7188. 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")));
  7189. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7190. {
  7191. 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++)
  7192. {
  7193. 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"));
  7194. 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"));
  7195. 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)
  7196. 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"));
  7197. }
  7198. }
  7199. }
  7200. }
  7201. else
  7202. chargingProfileIsNULL = TRUE;
  7203. }
  7204. }
  7205. else
  7206. connectorIdIsNULL = TRUE;
  7207. }
  7208. else
  7209. connectorIdIsNULL = TRUE;
  7210. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7211. {
  7212. DEBUG_WARN("Connector id is NULL\n.");
  7213. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7214. goto end;
  7215. }
  7216. /*
  7217. enum _SYSTEM_STATUS
  7218. {
  7219. S_BOOTING = 0,
  7220. S_IDLE, = 1
  7221. S_AUTHORIZING, = 2
  7222. S_REASSIGN_CHECK, = 3
  7223. S_REASSIGN, = 4
  7224. S_PRECHARGE, = 5
  7225. S_PREPARING_FOR_EV, = 6
  7226. S_PREPARING_FOR_EVSE, = 7
  7227. S_CHARGING, = 8
  7228. S_TERMINATING, = 9
  7229. S_COMPLETE, = 10
  7230. S_ALARM, = 11
  7231. S_FAULT = 12
  7232. }
  7233. */
  7234. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7235. {
  7236. //check Transaction active
  7237. if(gunType[connectorIdInt -1] == 'J')
  7238. {
  7239. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7240. {
  7241. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7242. }
  7243. else
  7244. {
  7245. tempIndex = connectorIdInt -1;
  7246. }
  7247. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7248. {
  7249. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7250. {
  7251. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7252. {
  7253. //Reserved
  7254. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7255. }
  7256. 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))
  7257. {
  7258. //Reserved
  7259. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7260. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7261. goto end;
  7262. }
  7263. else
  7264. {
  7265. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7266. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7267. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7268. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7269. {
  7270. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7271. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7272. goto end;
  7273. }
  7274. }//END FOR ELSE
  7275. }
  7276. }// END FOR CHAdeMO_QUANTITY
  7277. }
  7278. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7279. {
  7280. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7281. {
  7282. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7283. }
  7284. else
  7285. {
  7286. tempIndex = connectorIdInt -1;
  7287. }
  7288. for (int index = 0; index < CCS_QUANTITY; index++)
  7289. {
  7290. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7291. {
  7292. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7293. {
  7294. //Reserved
  7295. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7296. }
  7297. 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))
  7298. {
  7299. //Reserved
  7300. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7301. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7302. goto end;
  7303. }
  7304. else
  7305. {
  7306. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7307. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7308. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7309. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7310. {
  7311. DEBUG_WARN("CCS connector not allow start\n.");
  7312. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7313. goto end;
  7314. }
  7315. }// END FOR ELSE
  7316. }
  7317. }// END FOR CCS_QUANTITY
  7318. }
  7319. else if(gunType[connectorIdInt -1] == 'G')
  7320. {
  7321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7322. {
  7323. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7324. }
  7325. else
  7326. {
  7327. tempIndex = connectorIdInt -1;
  7328. }
  7329. for (int index = 0; index < GB_QUANTITY; index++)
  7330. {
  7331. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7332. {
  7333. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7334. {
  7335. //Reserved
  7336. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7337. }
  7338. 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))
  7339. {
  7340. //Reserved
  7341. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7342. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7343. goto end;
  7344. }
  7345. else
  7346. {
  7347. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7348. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7349. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7350. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7351. {
  7352. DEBUG_WARN("GB connector not allow start\n.");
  7353. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7354. goto end;
  7355. }
  7356. }// END FOR ELSE
  7357. }
  7358. } // END FOR GB_QUANTITY
  7359. }
  7360. else if(gunType[connectorIdInt -1] == 'O')
  7361. {
  7362. tempIndex = connectorIdInt -1;
  7363. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7364. {
  7365. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7366. {
  7367. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7368. {
  7369. //Reserved
  7370. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7371. }
  7372. 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))
  7373. {
  7374. //Reserved
  7375. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7376. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7377. goto end;
  7378. }
  7379. else
  7380. {
  7381. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7382. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7383. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7384. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7385. {
  7386. DEBUG_WARN("GB connector not allow start\n.");
  7387. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7388. goto end;
  7389. }
  7390. }// END FOR ELSE
  7391. }
  7392. } // END FOR GB_QUANTITY
  7393. }
  7394. else
  7395. {
  7396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7397. {
  7398. tempIndex = 2;
  7399. }
  7400. else
  7401. {
  7402. tempIndex = connectorIdInt -1;
  7403. }
  7404. for (int index = 0; index < AC_QUANTITY; index++)
  7405. {
  7406. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7407. {
  7408. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7409. {
  7410. //Reserved
  7411. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7412. }
  7413. 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))
  7414. {
  7415. //Reserved
  7416. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7417. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7418. goto end;
  7419. }
  7420. else
  7421. {
  7422. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7423. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7424. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7425. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7426. {
  7427. DEBUG_WARN("AC connector not allow start\n.");
  7428. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7429. goto end;
  7430. }
  7431. }//END FOR ELSE
  7432. }
  7433. }// END FOR AC_QUANTITY
  7434. }
  7435. if(chargingProfileIsNULL == FALSE)
  7436. {
  7437. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7438. {
  7439. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7440. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7441. //memset idTag
  7442. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7443. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7444. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7445. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7446. // Save profile to file
  7447. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7448. system(cmdBuf);
  7449. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7450. fp = fopen(cmdBuf, "w");
  7451. 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));
  7452. fclose(fp);
  7453. }
  7454. else
  7455. {
  7456. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7457. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7458. }
  7459. }
  7460. else
  7461. {
  7462. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7463. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7464. //memset idTag
  7465. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7466. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7467. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7468. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7469. }
  7470. }
  7471. else
  7472. {
  7473. DEBUG_WARN("Connector id over\n.");
  7474. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7475. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7476. }
  7477. end:
  7478. json_object_put(RemoteStartTransaction);
  7479. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7480. {
  7481. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7482. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7483. }
  7484. //OCPP send RemoteStartConfirmation by first.
  7485. sendRemoteStartConfirmation(uuid, comfirmstr);
  7486. return result;
  7487. }
  7488. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7489. {
  7490. mtrace();
  7491. int result = FAIL;
  7492. int match = FALSE;
  7493. int GunNO = 0;
  7494. int tempIndex = 0;
  7495. int transactionIdInt=0;
  7496. int transactionIdIsNULL= TRUE;
  7497. char comfirmstr[20];
  7498. json_object *RemoteStopTransaction;
  7499. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7500. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7501. if(server_pending == TRUE)
  7502. {
  7503. return 0;
  7504. }
  7505. RemoteStopTransaction = json_tokener_parse(payload);
  7506. if(!is_error(RemoteStopTransaction))
  7507. {
  7508. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7509. {
  7510. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7511. transactionIdIsNULL = FALSE;
  7512. }
  7513. }
  7514. json_object_put(RemoteStopTransaction);
  7515. if(transactionIdIsNULL == FALSE)
  7516. {
  7517. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7518. {
  7519. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7520. {
  7521. //check Transaction active
  7522. if(gunType[gun_index] == 'J')
  7523. {
  7524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7525. {
  7526. tempIndex = ((gun_index==2) ? 1: 0);
  7527. }
  7528. else
  7529. {
  7530. tempIndex = gun_index;
  7531. }
  7532. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7533. {
  7534. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7535. {
  7536. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7537. {
  7538. match = TRUE;
  7539. GunNO = gun_index;
  7540. }
  7541. }
  7542. }// END FOR CHAdeMO_QUANTITY
  7543. }
  7544. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7545. {
  7546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7547. {
  7548. tempIndex = ((gun_index==2) ? 1: 0);
  7549. }
  7550. else
  7551. {
  7552. tempIndex = gun_index;
  7553. }
  7554. for (int index = 0; index < CCS_QUANTITY; index++)
  7555. {
  7556. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7557. {
  7558. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7559. {
  7560. match = TRUE;
  7561. GunNO = gun_index;
  7562. }
  7563. }
  7564. }// END FOR CCS_QUANTITY
  7565. }
  7566. else if(gunType[gun_index] == 'G')
  7567. {
  7568. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7569. {
  7570. tempIndex = ((gun_index==2) ? 1: 0);
  7571. }
  7572. else
  7573. {
  7574. tempIndex = gun_index;
  7575. }
  7576. for (int index = 0; index < GB_QUANTITY; index++)
  7577. {
  7578. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7579. {
  7580. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7581. {
  7582. match = TRUE;
  7583. GunNO = gun_index;
  7584. }
  7585. }
  7586. }// END FOR GB_QUANTITY
  7587. }
  7588. else if(gunType[gun_index] == 'O')
  7589. {
  7590. tempIndex = gun_index;
  7591. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7592. {
  7593. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7594. {
  7595. 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
  7596. {
  7597. match = TRUE;
  7598. GunNO = gun_index;
  7599. }
  7600. }
  7601. }// END FOR GB_QUANTITY
  7602. }
  7603. else
  7604. {
  7605. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7606. {
  7607. tempIndex = 2;
  7608. }
  7609. else
  7610. {
  7611. tempIndex = gun_index;
  7612. }
  7613. for (int index = 0; index < AC_QUANTITY; index++)
  7614. {
  7615. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7616. {
  7617. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7618. {
  7619. match = TRUE;
  7620. GunNO = gun_index;
  7621. }
  7622. }
  7623. }// END FOR CHAdeMO_QUANTITY
  7624. } // END FOR AC ELSE
  7625. }// CHECK IF ResponseTransactionId == transactionIdInt
  7626. }//END FOR
  7627. if( match == TRUE)
  7628. {
  7629. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7630. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7631. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7632. }
  7633. else
  7634. {
  7635. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7636. }
  7637. }
  7638. else
  7639. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7640. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7641. return result;
  7642. }
  7643. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7644. {
  7645. mtrace();
  7646. int result = FAIL;
  7647. int connectorIdInt=0, reservationIdInt=0;
  7648. int tempIndex = 0;
  7649. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7650. char comfirmstr[20]={0};
  7651. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7652. int c = 0;
  7653. char *loc;
  7654. //char *ptr;
  7655. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7656. strcpy(sstrtemp, stringtrimspace(payload));
  7657. //***(1)connectorId ****/
  7658. c=0;
  7659. loc = strstr(sstrtemp, "connectorId");
  7660. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7661. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7662. {
  7663. sstr[c] = loc[strlen("connectorId")+2+c];
  7664. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7665. c++;
  7666. }
  7667. sstr[c] = '\0';
  7668. connectorIdInt = atoi(sstr);
  7669. //***(2)expiryDate ****/
  7670. loc = strstr(sstrtemp, "expiryDate");
  7671. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7672. c = 0;
  7673. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7674. {
  7675. sstr[c] = loc[3+strlen("expiryDate")+c];
  7676. c++;
  7677. }
  7678. sstr[c] = '\0';
  7679. strcpy(expiryDatestr, sstr);
  7680. //***(3)idTag ****/
  7681. loc = strstr(sstrtemp, "idTag");
  7682. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7683. c = 0;
  7684. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7685. {
  7686. sstr[c] = loc[3+strlen("idTag")+c];
  7687. c++;
  7688. }
  7689. sstr[c] = '\0';
  7690. strcpy(idTagstr, sstr);
  7691. //***(4)parentIdTag ****/
  7692. loc = strstr(sstrtemp, "parentIdTag");
  7693. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7694. c = 0;
  7695. if(loc == NULL)
  7696. {
  7697. strcpy(parentIdTagstr, "");
  7698. }
  7699. else
  7700. {
  7701. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7702. {
  7703. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7704. c++;
  7705. }
  7706. sstr[c] = '\0';
  7707. strcpy(parentIdTagstr, sstr);
  7708. }
  7709. //***(5)reservationId ****/
  7710. c=0;
  7711. loc = strstr(sstrtemp, "reservationId");
  7712. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7713. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7714. {
  7715. sstr[c] = loc[strlen("reservationId")+2+c];
  7716. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7717. c++;
  7718. }
  7719. sstr[c] = '\0';
  7720. reservationIdInt = atoi(sstr);
  7721. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7722. /*
  7723. enum SYSTEM_STATUS
  7724. {
  7725. SYS_MODE_BOOTING = 0,
  7726. SYS_MODE_IDLE = 1,
  7727. SYS_MODE_AUTHORIZING = 2,
  7728. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7729. SYS_MODE_REASSIGN = 4,
  7730. SYS_MODE_PREPARING = 5,
  7731. SYS_MODE_PREPARE_FOR_EV = 6,
  7732. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7733. SYS_MODE_CHARGING = 8,
  7734. SYS_MODE_TERMINATING = 9,
  7735. SYS_MODE_COMPLETE = 10,
  7736. SYS_MODE_ALARM = 11,
  7737. SYS_MODE_FAULT = 12,
  7738. SYS_MODE_RESERVATION = 13,
  7739. SYS_MODE_BOOKING = 14,
  7740. SYS_MODE_MAINTAIN = 15,
  7741. SYS_MODE_DEBUG = 16,
  7742. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7743. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7744. SYS_MODE_UPDATE = 19
  7745. };
  7746. */
  7747. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7748. {
  7749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7750. goto end;
  7751. }
  7752. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7753. {
  7754. //check Transaction active
  7755. if(gunType[connectorIdInt -1] == 'J')
  7756. {
  7757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7758. {
  7759. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7760. }
  7761. else
  7762. {
  7763. tempIndex = connectorIdInt -1;
  7764. }
  7765. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7766. {
  7767. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7768. {
  7769. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7770. {
  7771. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7772. {
  7773. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7774. {
  7775. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7776. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7777. }
  7778. 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'))
  7779. {
  7780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7781. }
  7782. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7783. {
  7784. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7785. }
  7786. else
  7787. {
  7788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7789. }
  7790. }
  7791. 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
  7792. {
  7793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7794. }
  7795. }
  7796. else
  7797. {
  7798. //replace reservation
  7799. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7801. }
  7802. }
  7803. } // END FOR CHAdeMO_QUANTITY
  7804. }
  7805. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7806. {
  7807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7808. {
  7809. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7810. }
  7811. else
  7812. {
  7813. tempIndex = connectorIdInt -1;
  7814. }
  7815. for (int index = 0; index < CCS_QUANTITY; index++)
  7816. {
  7817. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7818. {
  7819. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7820. {
  7821. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7822. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7823. {
  7824. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7825. {
  7826. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7827. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7828. }
  7829. 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'))
  7830. {
  7831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7832. }
  7833. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7834. {
  7835. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7836. }
  7837. else
  7838. {
  7839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7840. }
  7841. }
  7842. 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
  7843. {
  7844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7845. }
  7846. }
  7847. else
  7848. {
  7849. //replace reservation
  7850. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7851. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7852. }
  7853. }
  7854. } // END FOR CCS_QUANTITY
  7855. }
  7856. else if(gunType[connectorIdInt -1] == 'G')
  7857. {
  7858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7859. {
  7860. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7861. }
  7862. else
  7863. {
  7864. tempIndex = connectorIdInt -1;
  7865. }
  7866. for (int index = 0; index < GB_QUANTITY; index++)
  7867. {
  7868. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7869. {
  7870. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7871. {
  7872. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7873. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7874. {
  7875. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7876. {
  7877. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7878. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7879. }
  7880. 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'))
  7881. {
  7882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7883. }
  7884. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7885. {
  7886. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7887. }
  7888. else
  7889. {
  7890. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7891. }
  7892. }
  7893. 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
  7894. {
  7895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7896. }
  7897. }
  7898. else
  7899. {
  7900. //replace reservation
  7901. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7902. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7903. }
  7904. }
  7905. }// END FOR GB_QUANTITY
  7906. }
  7907. else if(gunType[connectorIdInt -1] == 'O')
  7908. {
  7909. tempIndex = connectorIdInt -1;
  7910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7911. {
  7912. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7913. {
  7914. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  7915. {
  7916. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7917. 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
  7918. {
  7919. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7920. {
  7921. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7922. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7923. }
  7924. 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'))
  7925. {
  7926. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7927. }
  7928. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7929. {
  7930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7931. }
  7932. else
  7933. {
  7934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7935. }
  7936. }
  7937. 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
  7938. {
  7939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7940. }
  7941. }
  7942. else
  7943. {
  7944. //replace reservation
  7945. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7947. }
  7948. }
  7949. }// END FOR GB_QUANTITY
  7950. }
  7951. else
  7952. {
  7953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7954. {
  7955. tempIndex = 2;
  7956. }
  7957. else
  7958. {
  7959. tempIndex = (connectorIdInt -1);
  7960. }
  7961. for (int index = 0; index < AC_QUANTITY; index++)
  7962. {
  7963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7964. {
  7965. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7966. {
  7967. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7968. {
  7969. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7970. {
  7971. 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))
  7972. {
  7973. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7974. }
  7975. else
  7976. {
  7977. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7979. }
  7980. }
  7981. 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'))
  7982. {
  7983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7984. }
  7985. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7986. {
  7987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7988. }
  7989. else
  7990. {
  7991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7992. }
  7993. }
  7994. 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
  7995. {
  7996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7997. }
  7998. }
  7999. else
  8000. {
  8001. //replace reservation
  8002. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8004. }
  8005. }
  8006. } // END FOR AC_QUANTITY
  8007. }
  8008. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8009. }
  8010. else if(connectorIdInt == 0)
  8011. {
  8012. //check Transaction active
  8013. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8014. {
  8015. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8016. {
  8017. 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'))
  8018. {
  8019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8020. goto end;
  8021. }
  8022. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8023. {
  8024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8025. goto end;
  8026. }
  8027. 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
  8028. {
  8029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8030. goto end;
  8031. }
  8032. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8033. {
  8034. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8035. goto end;
  8036. }
  8037. }
  8038. }// END FOR CHAdeMO_QUANTITY
  8039. for (int index = 0; index < CCS_QUANTITY; index++)
  8040. {
  8041. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8042. {
  8043. 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'))
  8044. {
  8045. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8046. goto end;
  8047. }
  8048. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8049. {
  8050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8051. goto end;
  8052. }
  8053. 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
  8054. {
  8055. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8056. goto end;
  8057. }
  8058. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8059. {
  8060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8061. goto end;
  8062. }
  8063. }
  8064. } // END FOR CCS_QUANTITY
  8065. for (int index = 0; index < GB_QUANTITY; index++)
  8066. {
  8067. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8068. {
  8069. 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'))
  8070. {
  8071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8072. goto end;
  8073. }
  8074. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8075. {
  8076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8077. goto end;
  8078. }
  8079. 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
  8080. {
  8081. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8082. goto end;
  8083. }
  8084. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8085. {
  8086. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8087. goto end;
  8088. }
  8089. }
  8090. } // END FOR GB_QUANTITY
  8091. for (int index = 0; index < AC_QUANTITY; index++)
  8092. {
  8093. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8094. {
  8095. 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'))
  8096. {
  8097. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8098. goto end;
  8099. }
  8100. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8101. {
  8102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8103. goto end;
  8104. }
  8105. 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
  8106. {
  8107. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8108. goto end;
  8109. }
  8110. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8111. {
  8112. 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))
  8113. {
  8114. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8115. goto end;
  8116. }
  8117. }
  8118. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8119. {
  8120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8121. goto end;
  8122. }
  8123. }
  8124. }// END FOR AC_QUANTITY
  8125. //The connectorId is 0
  8126. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8127. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8128. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8129. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8130. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8131. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8132. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8133. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8134. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8135. result = TRUE;
  8136. return result;
  8137. }
  8138. else
  8139. {
  8140. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8141. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8142. }
  8143. if(strcmp(comfirmstr,"Accepted") == 0)
  8144. {
  8145. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8146. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8147. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8148. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8149. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8150. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8151. result = TRUE;
  8152. return result;
  8153. }
  8154. end:
  8155. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8156. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8157. return result;
  8158. }
  8159. int handleResetRequest(char *uuid, char *payload)
  8160. {
  8161. mtrace();
  8162. int result = FAIL;
  8163. char sstr[10]={0},sstrtemp[30]={ 0 };
  8164. char typestr[10]={0};
  8165. char comfirmstr[20]={0};
  8166. int c = 0;
  8167. char *loc;
  8168. DEBUG_INFO("handleResetRequest...\n");
  8169. strcpy(sstrtemp, stringtrimspace(payload));
  8170. loc = strstr(sstrtemp, "type");
  8171. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8172. c = 0;
  8173. while (loc[3+strlen("type")+c] != '\"')
  8174. {
  8175. sstr[c] = loc[3+strlen("type")+c];
  8176. c++;
  8177. }
  8178. sstr[c] = '\0';
  8179. strcpy(typestr,sstr);
  8180. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8181. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8182. {
  8183. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8184. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8185. result = TRUE;
  8186. return result;
  8187. }
  8188. else
  8189. {
  8190. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8191. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8192. goto errorend;
  8193. }
  8194. errorend:
  8195. sendResetConfirmation(uuid, comfirmstr);
  8196. return result;
  8197. }
  8198. int handleSendLocalListRequest(char *uuid, char *payload)
  8199. {
  8200. mtrace();
  8201. int result = FAIL;
  8202. int listVersionInt;
  8203. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8204. char listsearch[]="listVersion";
  8205. char updateTypesearch[]="updateType";
  8206. char localAuthorizationListsearch[]="localAuthorizationList";
  8207. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8208. char CardList[500][160]={0};
  8209. char updateTypestr[15]={0};
  8210. char idTagstr[20]={0};
  8211. char parentIdTag[20]={0};
  8212. char expiryDate[30]={0};
  8213. char idTagstatus[16]={0};
  8214. int c = 0;
  8215. int i = 0;
  8216. char *delim1 = "}";
  8217. char * pch;
  8218. char *loc;
  8219. //char *ptr;
  8220. char comfirmstr[20];
  8221. //int n_localAuthorizations = 0;
  8222. int checkState_Faulted = FALSE;
  8223. DEBUG_INFO("handleSendLocalListRequest...\n");
  8224. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8225. {
  8226. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8227. goto end;
  8228. }
  8229. //check Charge Point state
  8230. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8231. {
  8232. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8233. {
  8234. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8235. }
  8236. }
  8237. for (int index = 0; index < CCS_QUANTITY; index++)
  8238. {
  8239. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8240. {
  8241. checkState_Faulted = TRUE; //OCPP Status
  8242. }
  8243. }
  8244. for (int index = 0; index < GB_QUANTITY; index++)
  8245. {
  8246. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8247. {
  8248. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8249. }
  8250. }
  8251. //check Charge Point state
  8252. for (int index = 0; index < AC_QUANTITY; index++)
  8253. {
  8254. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8255. {
  8256. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8257. }
  8258. }
  8259. if(checkState_Faulted == TRUE)
  8260. {
  8261. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8262. goto end;
  8263. }
  8264. //Filter payload space
  8265. strcpy(sstrtemp, stringtrimspace(payload));
  8266. //listVersion
  8267. c = 0;
  8268. loc = strstr(sstrtemp, listsearch);
  8269. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8270. {
  8271. sstr[c] = loc[strlen("listVersion")+2+c];
  8272. c++;
  8273. }
  8274. sstr[c] = '\0';
  8275. listVersionInt = atoi(sstr);
  8276. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8277. //updateType
  8278. loc = strstr(sstrtemp, updateTypesearch);
  8279. c = 0;
  8280. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8281. {
  8282. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8283. c++;
  8284. }
  8285. sstr[c] = '\0';
  8286. strcpy(updateTypestr, sstr);
  8287. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8288. //localAuthorizationList
  8289. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8290. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8291. if(loc != NULL) // localAuthorizationList is not NULL
  8292. {
  8293. //Check UpdateType
  8294. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8295. {
  8296. //Local list full update
  8297. printf("Local list full update.\n");
  8298. OCPP_getListVerion();
  8299. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8300. {
  8301. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8302. goto end;
  8303. }
  8304. OCPP_cleanLocalList();
  8305. }
  8306. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8307. {
  8308. //Local list different update
  8309. printf("Local list different update.\n");
  8310. OCPP_getListVerion();
  8311. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8312. {
  8313. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8314. goto end;
  8315. }
  8316. }
  8317. else
  8318. {
  8319. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8320. goto end;
  8321. }
  8322. c = 0;
  8323. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8324. {
  8325. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8326. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8327. c++;
  8328. }
  8329. sstr[c] = '\0';
  8330. //DEBUG_INFO("sstr=%s\n", sstr);
  8331. //parsing strings to words
  8332. i = 0;
  8333. pch = strtok(sstr,delim1);
  8334. while (pch != NULL)
  8335. {
  8336. strcpy(CardList[i], pch);
  8337. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8338. pch = strtok (NULL, delim1);
  8339. i = i + 1;
  8340. }
  8341. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8342. //local Authorizations List Numbers
  8343. //n_localAuthorizations = i;
  8344. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8345. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8346. c= 0;
  8347. while(c < i) // i is CardList Number
  8348. {
  8349. //Search "IdToken"
  8350. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8351. loc = strstr(CardList[c], "idTag");
  8352. int j = 0;
  8353. while (loc[3+strlen("idTag")+j] != '\"')
  8354. {
  8355. sstr[j] = loc[3+strlen("idTag")+j];
  8356. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8357. j++;
  8358. }
  8359. sstr[j] = '\0';
  8360. strcpy(idTagstr, sstr);
  8361. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8362. //Search "expiryDate"
  8363. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8364. loc = strstr(CardList[c], "expiryDate");
  8365. j = 0;
  8366. if(loc != NULL)
  8367. {
  8368. while (loc[3+strlen("expiryDate")+j] != '\"')
  8369. {
  8370. sstr[j] = loc[3+strlen("expiryDate")+j];
  8371. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8372. j++;
  8373. }
  8374. sstr[j] = '\0';
  8375. strcpy(expiryDate, sstr);
  8376. }
  8377. else
  8378. {
  8379. strcpy(expiryDate, "");
  8380. }
  8381. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8382. //Search "parentIdTag"
  8383. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8384. loc = strstr(CardList[c], "parentIdTag");
  8385. j = 0;
  8386. if(loc != NULL)
  8387. {
  8388. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8389. {
  8390. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8391. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8392. j++;
  8393. }
  8394. sstr[j] = '\0';
  8395. strcpy(parentIdTag, sstr);
  8396. }
  8397. else
  8398. {
  8399. strcpy(parentIdTag, "");
  8400. }
  8401. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8402. //Search "status"
  8403. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8404. loc = strstr(CardList[c], "status");
  8405. j = 0;
  8406. while (loc[3+strlen("status")+j] != '\"')
  8407. {
  8408. sstr[j] = loc[3+strlen("status")+j];
  8409. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8410. j++;
  8411. }
  8412. sstr[j] = '\0';
  8413. strcpy(idTagstatus, sstr);
  8414. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8415. OCPP_getIdTagFromLocalList(idTagstr);
  8416. //OCPP_getIdTagFromLocalList("test"); For Test
  8417. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8418. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8419. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8420. {
  8421. //Local list full update
  8422. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8423. // update list
  8424. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8425. //DEBUG_INFO("Local list full update. 1\n");
  8426. //OCPP_get_TableAuthlocalAllData();
  8427. //DEBUG_INFO("Local list full update. 2\n");
  8428. }
  8429. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8430. {
  8431. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8432. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8433. }
  8434. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8435. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8436. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8437. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8438. c++;
  8439. }
  8440. }
  8441. else
  8442. {
  8443. //Check UpdateType
  8444. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8445. {
  8446. //Local list full update
  8447. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8448. OCPP_cleanLocalList();
  8449. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8450. goto end;
  8451. }
  8452. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8453. {
  8454. //Local list different update
  8455. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8456. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8457. goto end;
  8458. }
  8459. }
  8460. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8461. end:
  8462. sendSendLocalListConfirmation(uuid, comfirmstr);
  8463. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8464. return result;
  8465. }
  8466. #define MAX 200
  8467. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8468. {
  8469. mtrace();
  8470. int result = FAIL;
  8471. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8472. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8473. char chargingProfilePurposeStr[30]={0};
  8474. char chargingProfileKindStr[16]={0};
  8475. char recurrencyKindStr[10]={0};
  8476. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8477. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8478. int chargingSchedulePeriodCount = 0;
  8479. char comfirmstr[20]={0};
  8480. int meet= FALSE;
  8481. FILE *fptr1;
  8482. char filename[MAX]={0};
  8483. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8484. char rmFileCmd[50]={0};
  8485. char tempchargingProfilePurposeStr[30]={0};
  8486. char word[1600]={0};
  8487. int n_chargingProfile = 0;
  8488. json_object *SetChargingProfile;
  8489. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8490. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8491. SetChargingProfile = json_tokener_parse(payload);
  8492. if(!is_error(SetChargingProfile))
  8493. {
  8494. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8495. {
  8496. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8497. if(connectorIdInt == 0)
  8498. {
  8499. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8500. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8501. }
  8502. else
  8503. {
  8504. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8505. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8506. }
  8507. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8508. }
  8509. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8510. {
  8511. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8512. {
  8513. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8514. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8515. {
  8516. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8517. }
  8518. else
  8519. {
  8520. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8521. }
  8522. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8523. }
  8524. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8525. {
  8526. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8527. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8528. {
  8529. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8530. }
  8531. else
  8532. {
  8533. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8534. }
  8535. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8536. }
  8537. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8538. {
  8539. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8540. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8541. {
  8542. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8543. }
  8544. else
  8545. {
  8546. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8547. }
  8548. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8549. }
  8550. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8551. {
  8552. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8553. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8554. {
  8555. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8556. }
  8557. else
  8558. {
  8559. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8560. }
  8561. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8562. }
  8563. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8564. {
  8565. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8566. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8567. {
  8568. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8569. }
  8570. else
  8571. {
  8572. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8573. }
  8574. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8575. }
  8576. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8577. {
  8578. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8579. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8580. {
  8581. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8582. }
  8583. else
  8584. {
  8585. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8586. }
  8587. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8588. }
  8589. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8590. {
  8591. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8592. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8593. {
  8594. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8595. }
  8596. else
  8597. {
  8598. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8599. }
  8600. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8601. }
  8602. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8603. {
  8604. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8605. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8606. {
  8607. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8608. }
  8609. else
  8610. {
  8611. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8612. }
  8613. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8614. }
  8615. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8616. {
  8617. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8618. {
  8619. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8620. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8621. {
  8622. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8623. }
  8624. else
  8625. {
  8626. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8627. }
  8628. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8629. }
  8630. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8631. {
  8632. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8633. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8634. {
  8635. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8636. }
  8637. else
  8638. {
  8639. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8640. }
  8641. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8642. }
  8643. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8644. {
  8645. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8646. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8647. {
  8648. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8649. }
  8650. else
  8651. {
  8652. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8653. }
  8654. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8655. }
  8656. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8657. {
  8658. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8659. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8660. {
  8661. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8662. }
  8663. else
  8664. {
  8665. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8666. }
  8667. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8668. }
  8669. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8670. {
  8671. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8672. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8673. if(chargingSchedulePeriodCount <= 10)
  8674. {
  8675. 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++)
  8676. {
  8677. 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)
  8678. {
  8679. 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"));
  8680. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8681. {
  8682. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8683. }
  8684. else
  8685. {
  8686. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8687. }
  8688. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8689. }
  8690. 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)
  8691. {
  8692. 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"));
  8693. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8694. {
  8695. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8696. }
  8697. else
  8698. {
  8699. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8700. }
  8701. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8702. }
  8703. 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)
  8704. {
  8705. 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"));
  8706. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8707. {
  8708. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8709. }
  8710. else
  8711. {
  8712. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8713. }
  8714. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8715. }
  8716. }
  8717. }
  8718. }
  8719. }
  8720. }
  8721. }
  8722. json_object_put(SetChargingProfile);
  8723. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8724. {
  8725. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8726. goto end;
  8727. }
  8728. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8729. {
  8730. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8731. if(connectorIdInt != 0)
  8732. {
  8733. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8734. goto end;
  8735. }
  8736. strcpy(filename, ChargePointMaxProfile_JSON );
  8737. fptr1 = fopen(filename, "r");
  8738. if (!fptr1)
  8739. {
  8740. //file not exist
  8741. DEBUG_INFO("Unable to open the input file!!\n");
  8742. fptr1 = fopen(filename, "w+");
  8743. }
  8744. else
  8745. {
  8746. //Check Charging Profile Count
  8747. while(fscanf(fptr1, "%s", word) != EOF)
  8748. {
  8749. //DEBUG_INFO("word=%s\n",word);
  8750. if(strstr(word, "chargingProfileId")!= NULL)
  8751. {
  8752. //DEBUG_INFO("test chargingProfileId \n");
  8753. n_chargingProfile = n_chargingProfile + 1;
  8754. //DEBUG_INFO("chargingProfileId Found\n");
  8755. }
  8756. }
  8757. }
  8758. fclose(fptr1);
  8759. }
  8760. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8761. {
  8762. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8763. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8764. {
  8765. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8766. goto end;
  8767. }
  8768. memset(filename, 0, ARRAY_SIZE(filename));
  8769. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8770. fptr1 = fopen(filename, "r");
  8771. if (!fptr1)
  8772. {
  8773. //file not exist
  8774. //DEBUG_INFO("Unable to open the input file!!\n");
  8775. fptr1 = fopen(filename, "w+");
  8776. }
  8777. else
  8778. {
  8779. //Check Charging Profile Count
  8780. while(fscanf(fptr1, "%s", word) != EOF)
  8781. {
  8782. //DEBUG_INFO("word=%s\n",word);
  8783. if(strstr(word, "chargingProfileId")!= NULL)
  8784. {
  8785. //DEBUG_INFO("test chargingProfileId \n");
  8786. n_chargingProfile = n_chargingProfile + 1;
  8787. //DEBUG_INFO("chargingProfileId Found\n");
  8788. }
  8789. }
  8790. }
  8791. fclose(fptr1);
  8792. }
  8793. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8794. {
  8795. //printf("set chargingProfile 1-4\n");
  8796. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8797. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8798. if(connectorIdInt == 0)
  8799. {
  8800. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8801. goto end;
  8802. }
  8803. int tempIndex = 0;
  8804. //check Transaction active
  8805. if(gunType[connectorIdInt -1] == 'J')
  8806. {
  8807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8808. {
  8809. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8810. }
  8811. else
  8812. {
  8813. tempIndex = connectorIdInt -1;
  8814. }
  8815. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8816. {
  8817. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8818. {
  8819. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8820. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8821. {
  8822. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8823. {
  8824. meet = TRUE;
  8825. break;
  8826. }
  8827. }
  8828. }
  8829. }
  8830. }
  8831. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8832. {
  8833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8834. {
  8835. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8836. }
  8837. else
  8838. {
  8839. tempIndex = connectorIdInt -1;
  8840. }
  8841. for (int index = 0; index < CCS_QUANTITY; index++)
  8842. {
  8843. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8844. {
  8845. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8846. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8847. {
  8848. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8849. {
  8850. meet = TRUE;
  8851. break;
  8852. }
  8853. }
  8854. }
  8855. }
  8856. }
  8857. else if(gunType[connectorIdInt -1] == 'G')
  8858. {
  8859. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8860. {
  8861. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8862. }
  8863. else
  8864. {
  8865. tempIndex = connectorIdInt -1;
  8866. }
  8867. for (int index = 0; index < GB_QUANTITY; index++)
  8868. {
  8869. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8870. {
  8871. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8872. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8873. {
  8874. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8875. {
  8876. meet = TRUE;
  8877. break;
  8878. }
  8879. }
  8880. }
  8881. }
  8882. }
  8883. else if(gunType[connectorIdInt -1] == 'O')
  8884. {
  8885. tempIndex = connectorIdInt -1;
  8886. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8887. {
  8888. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8889. {
  8890. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8891. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8892. {
  8893. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8894. {
  8895. meet = TRUE;
  8896. break;
  8897. }
  8898. }
  8899. }
  8900. }
  8901. }
  8902. else
  8903. {
  8904. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8905. {
  8906. tempIndex = 2;
  8907. }
  8908. else
  8909. {
  8910. tempIndex = (connectorIdInt -1);
  8911. }
  8912. for (int index = 0; index < AC_QUANTITY; index++)
  8913. {
  8914. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8915. {
  8916. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8917. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8918. {
  8919. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8920. {
  8921. meet = TRUE;
  8922. break;
  8923. }
  8924. }
  8925. }
  8926. }
  8927. }
  8928. //check Transaction active
  8929. if(meet == FALSE)
  8930. {
  8931. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8932. goto end;
  8933. }
  8934. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8935. {
  8936. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8937. goto end;
  8938. }
  8939. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8940. fptr1 = fopen(filename, "r");
  8941. if (!fptr1)
  8942. {
  8943. //file not exist
  8944. DEBUG_INFO("Unable to open the input file!!\n");
  8945. fptr1 = fopen(filename, "w+");
  8946. }
  8947. else
  8948. {
  8949. //Check Charging Profile Count
  8950. while(fscanf(fptr1, "%s", word) != EOF)
  8951. {
  8952. //DEBUG_INFO("word=%s\n",word);
  8953. if(strstr(word, "chargingProfileId")!= NULL)
  8954. {
  8955. //DEBUG_INFO("test chargingProfileId \n");
  8956. n_chargingProfile = n_chargingProfile + 1;
  8957. //DEBUG_INFO("chargingProfileId Found\n");
  8958. }
  8959. }
  8960. }
  8961. fclose(fptr1);
  8962. }
  8963. // Check ChargeProfileMaxStackLevel
  8964. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8965. {
  8966. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8967. goto end;
  8968. }
  8969. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8970. {
  8971. int i = 0;
  8972. char fnametemp[200]={0};
  8973. n_chargingProfile = 0;
  8974. //Check ChargePointMaxProfile.json exit
  8975. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8976. {
  8977. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8978. //Check Charging Profile Count
  8979. while(fscanf(fptr1, "%s", word) != EOF)
  8980. {
  8981. //DEBUG_INFO("word=%s\n",word);
  8982. if(strstr(word, "chargingProfileId")!= NULL)
  8983. {
  8984. //DEBUG_INFO("test chargingProfileId \n");
  8985. n_chargingProfile = n_chargingProfile + 1;
  8986. i = i + 1;
  8987. //DEBUG_INFO("chargingProfileId Found\n");
  8988. }
  8989. memset(word, 0, ARRAY_SIZE(word));
  8990. }
  8991. fclose(fptr1);
  8992. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8993. }
  8994. //Check TxDefaultProfile_0.json exit
  8995. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8996. {
  8997. i = 0;
  8998. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8999. //Check Charging Profile Count
  9000. while(fscanf(fptr1, "%s", word) != EOF)
  9001. {
  9002. //DEBUG_INFO("word=%s\n",word);
  9003. if(strstr(word, "chargingProfileId")!= NULL)
  9004. {
  9005. //DEBUG_INFO("test chargingProfileId \n");
  9006. n_chargingProfile = n_chargingProfile + 1;
  9007. i = i + 1;
  9008. //DEBUG_INFO("chargingProfileId Found\n");
  9009. }
  9010. memset(word, 0, ARRAY_SIZE(word));
  9011. }
  9012. fclose(fptr1);
  9013. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9014. }
  9015. //Check TxDefaultProfile_%d.json
  9016. for(int j=1; j <= gunTotalNumber; j++)
  9017. {
  9018. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9019. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9020. if((access(fnametemp,F_OK))!=-1)
  9021. {
  9022. i = 0;
  9023. fptr1 = fopen(fnametemp, "r");
  9024. //Check Charging Profile Count
  9025. while(fscanf(fptr1, "%s", word) != EOF)
  9026. {
  9027. //DEBUG_INFO("word=%s\n",word);
  9028. if(strstr(word, "chargingProfileId")!= NULL)
  9029. {
  9030. //DEBUG_INFO("test chargingProfileId \n");
  9031. n_chargingProfile = n_chargingProfile + 1;
  9032. i = i + 1;
  9033. //DEBUG_INFO("chargingProfileId Found\n");
  9034. }
  9035. memset(word, 0, ARRAY_SIZE(word));
  9036. }
  9037. fclose(fptr1);
  9038. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9039. }
  9040. }
  9041. //Check TxProfile_%d.json
  9042. for(int j=1; j <= gunTotalNumber; j++)
  9043. {
  9044. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9045. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9046. if((access(fnametemp,F_OK))!=-1)
  9047. {
  9048. i = 0;
  9049. fptr1 = fopen(fnametemp, "r");
  9050. //Check Charging Profile Count
  9051. while(fscanf(fptr1, "%s", word) != EOF)
  9052. {
  9053. //DEBUG_INFO("word=%s\n",word);
  9054. if(strstr(word, "chargingProfileId")!= NULL)
  9055. {
  9056. //DEBUG_INFO("test chargingProfileId \n");
  9057. n_chargingProfile = n_chargingProfile + 1;
  9058. i = i + 1;
  9059. //DEBUG_INFO("chargingProfileId Found\n");
  9060. }
  9061. memset(word, 0, ARRAY_SIZE(word));
  9062. }
  9063. fclose(fptr1);
  9064. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9065. }
  9066. }
  9067. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9068. {
  9069. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9070. goto end;
  9071. }
  9072. }
  9073. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9074. //**********************************Write to File********************************************************/
  9075. FILE *infile;
  9076. FILE *outfile;
  9077. infile = fopen (filename, "r");
  9078. outfile = fopen (tempfile, "w");
  9079. int d =0;
  9080. d = fgetc(infile);
  9081. rewind(infile);
  9082. if(d == EOF)
  9083. {
  9084. // Profile is empty
  9085. fprintf(outfile,"%s\n",payload);
  9086. fclose(infile);
  9087. fclose(outfile);
  9088. sprintf(rmFileCmd,"rm -f %s",filename);
  9089. system(rmFileCmd);
  9090. rename(tempfile, filename);
  9091. }
  9092. else
  9093. {
  9094. // Profile is not empty
  9095. char buf[2048]={0};
  9096. int ChargingProfileAdded = FALSE;
  9097. while (fgets(buf, sizeof(buf), infile) != NULL)
  9098. {
  9099. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9100. json_object *tmpChargingProfile;
  9101. tmpChargingProfile = json_tokener_parse(buf);
  9102. if(!is_error(SetChargingProfile))
  9103. {
  9104. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9105. {
  9106. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9107. }
  9108. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9109. {
  9110. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9111. {
  9112. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9113. }
  9114. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9115. {
  9116. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9117. }
  9118. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9119. {
  9120. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9121. }
  9122. }
  9123. }
  9124. json_object_put(tmpChargingProfile);
  9125. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9126. {
  9127. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9128. {
  9129. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9130. if(ChargingProfileAdded == FALSE)
  9131. {
  9132. fprintf(outfile,"%s\n",payload);
  9133. ChargingProfileAdded = TRUE;
  9134. }
  9135. }
  9136. else
  9137. {
  9138. if(tempstackLevelInt < stackLevelInt)
  9139. {
  9140. if(ChargingProfileAdded == FALSE)
  9141. {
  9142. fprintf(outfile,"%s\n",buf);
  9143. fprintf(outfile,"%s\n",payload);
  9144. ChargingProfileAdded = TRUE;
  9145. }
  9146. else
  9147. {
  9148. fprintf(outfile,"%s\n",buf);
  9149. }
  9150. }
  9151. else
  9152. {
  9153. if(ChargingProfileAdded == FALSE)
  9154. {
  9155. fprintf(outfile,"%s\n",buf);
  9156. fprintf(outfile,"%s\n",payload);
  9157. ChargingProfileAdded = TRUE;
  9158. }
  9159. else
  9160. {
  9161. fprintf(outfile,"%s\n",buf);
  9162. }
  9163. }
  9164. }
  9165. }
  9166. else
  9167. {
  9168. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9169. {
  9170. if(ChargingProfileAdded == FALSE)
  9171. {
  9172. fprintf(outfile,"%s\n",buf);
  9173. fprintf(outfile,"%s\n",payload);
  9174. ChargingProfileAdded = TRUE;
  9175. }
  9176. else
  9177. {
  9178. fprintf(outfile,"%s\n",buf);
  9179. }
  9180. }
  9181. else if(tempstackLevelInt < stackLevelInt)
  9182. {
  9183. if(ChargingProfileAdded == FALSE)
  9184. {
  9185. fprintf(outfile,"%s\n",buf);
  9186. fprintf(outfile,"%s\n",payload);
  9187. ChargingProfileAdded = TRUE;
  9188. }
  9189. else
  9190. {
  9191. fprintf(outfile,"%s\n",buf);
  9192. }
  9193. }
  9194. else
  9195. {
  9196. if(ChargingProfileAdded == FALSE)
  9197. {
  9198. fprintf(outfile,"%s\n",buf);
  9199. fprintf(outfile,"%s\n",payload);
  9200. ChargingProfileAdded = TRUE;
  9201. }
  9202. else
  9203. {
  9204. fprintf(outfile,"%s\n",buf);
  9205. }
  9206. }
  9207. }
  9208. } // end of while loop
  9209. fclose(infile);
  9210. fclose(outfile);
  9211. sprintf(rmFileCmd,"rm -f %s",filename);
  9212. system(rmFileCmd);
  9213. rename(tempfile, filename);
  9214. }
  9215. sleep(1);
  9216. result = TRUE;
  9217. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9218. end:
  9219. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9220. {
  9221. if(connectorIdInt == 0)
  9222. {
  9223. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9224. {
  9225. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  9226. }
  9227. }
  9228. else
  9229. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  9230. }
  9231. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9232. return result;
  9233. }
  9234. int handleTriggerMessageRequest(char *uuid, char *payload)
  9235. {
  9236. mtrace();
  9237. int result = FAIL;
  9238. int connectorIdIsNULL = FALSE;
  9239. int connectorIdInt =0;
  9240. char sstr[40]={0},sstrtemp[100]={ 0 };
  9241. char requestedMessagestr[40]={0};
  9242. char comfirmstr[20]={0};
  9243. int c = 0;
  9244. char *loc;
  9245. DEBUG_INFO("handleTriggerMessageRequest\n");
  9246. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9247. strcpy(sstrtemp, stringtrimspace(payload));
  9248. c = 0;
  9249. loc = strstr(sstrtemp, "requestedMessage");
  9250. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9251. {
  9252. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9253. c++;
  9254. }
  9255. sstr[c] = '\0';
  9256. strcpy(requestedMessagestr, sstr);
  9257. c = 0;
  9258. loc = strstr(sstrtemp, "connectorId");
  9259. if(loc == NULL)
  9260. {
  9261. connectorIdIsNULL = TRUE;
  9262. }
  9263. else
  9264. {
  9265. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9266. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9267. {
  9268. sstr[c] = loc[strlen("connectorId")+2+c];
  9269. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9270. c++;
  9271. }
  9272. sstr[c] = '\0';
  9273. connectorIdInt = atoi(sstr);
  9274. }
  9275. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9276. {
  9277. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9278. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9279. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9280. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9281. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9282. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9283. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9284. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9285. {
  9286. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9287. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9288. return TRUE;
  9289. }
  9290. else
  9291. {
  9292. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9293. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9294. }
  9295. }
  9296. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9297. {
  9298. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9299. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9300. return TRUE;
  9301. }
  9302. //==========================
  9303. // Trigger message
  9304. //==========================
  9305. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9306. {
  9307. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9308. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9309. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9310. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9311. {
  9312. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9313. }
  9314. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9315. }
  9316. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9317. {
  9318. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9319. }
  9320. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9321. {
  9322. //sendBootNotificationRequest();
  9323. server_sign = FALSE;
  9324. }
  9325. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9326. {
  9327. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9328. }
  9329. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9330. {
  9331. if(connectorIdIsNULL == FALSE)
  9332. {
  9333. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9334. {
  9335. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9336. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9337. }
  9338. }
  9339. else
  9340. {
  9341. for(int idx=0;idx< gunTotalNumber;idx++)
  9342. {
  9343. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9344. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9345. }
  9346. }
  9347. }
  9348. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9349. {
  9350. if(connectorIdIsNULL == FALSE)
  9351. {
  9352. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9353. {
  9354. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9355. }
  9356. }
  9357. else
  9358. {
  9359. for(int idx=0;idx< gunTotalNumber;idx++)
  9360. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9361. }
  9362. }
  9363. return result;
  9364. }
  9365. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9366. {
  9367. mtrace();
  9368. int result = FAIL;
  9369. int connectorIdInt =0;
  9370. char comfirmstr[20]={0};
  9371. int tempIndex = 0;
  9372. json_object *UnlockConnector;
  9373. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9374. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9375. UnlockConnector = json_tokener_parse(payload);
  9376. if(!is_error(UnlockConnector))
  9377. {
  9378. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9379. {
  9380. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9381. }
  9382. }
  9383. json_object_put(UnlockConnector);
  9384. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9385. if(gunTotalNumber == 0)
  9386. {
  9387. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9388. goto end;
  9389. }
  9390. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9391. {
  9392. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9393. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9394. goto end;
  9395. }
  9396. else
  9397. {
  9398. //check Transaction active
  9399. if(gunType[connectorIdInt-1] == 'J')
  9400. {
  9401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9402. {
  9403. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9404. }
  9405. else
  9406. {
  9407. tempIndex = connectorIdInt -1;
  9408. }
  9409. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9410. {
  9411. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9412. {
  9413. //stop Transaction
  9414. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9415. }
  9416. }
  9417. }
  9418. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9419. {
  9420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9421. {
  9422. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9423. }
  9424. else
  9425. {
  9426. tempIndex = connectorIdInt -1;
  9427. }
  9428. for (int index = 0; index < CCS_QUANTITY; index++)
  9429. {
  9430. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9431. {
  9432. //stop Transaction
  9433. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9434. }
  9435. }
  9436. }
  9437. else if(gunType[connectorIdInt-1] == 'G')
  9438. {
  9439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9440. {
  9441. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9442. }
  9443. else
  9444. {
  9445. tempIndex = connectorIdInt -1;
  9446. }
  9447. for (int index = 0; index < GB_QUANTITY; index++)
  9448. {
  9449. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9450. {
  9451. //stop Transaction
  9452. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9453. }
  9454. }
  9455. }
  9456. else if(gunType[connectorIdInt-1] == 'O')
  9457. {
  9458. tempIndex = connectorIdInt -1;
  9459. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9460. {
  9461. 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)))
  9462. {
  9463. //stop Transaction
  9464. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9465. }
  9466. }
  9467. }
  9468. else
  9469. {
  9470. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9471. {
  9472. tempIndex = 2;
  9473. }
  9474. else
  9475. {
  9476. tempIndex = connectorIdInt-1;
  9477. }
  9478. for (int index = 0; index < AC_QUANTITY; index++)
  9479. {
  9480. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9481. {
  9482. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9483. }
  9484. }
  9485. }
  9486. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9487. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9488. result = TRUE;
  9489. return result;
  9490. }
  9491. end:
  9492. //json_object_put(obj); --- remove temporally
  9493. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9494. return result;
  9495. }
  9496. static char UpdateFirmwarepayloadData[300]={0};
  9497. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9498. {
  9499. mtrace();
  9500. int result = FAIL;
  9501. pthread_t t;
  9502. sendUpdateFirmwareConfirmation(uuid);
  9503. memset(UpdateFirmwarepayloadData, 0, 300);
  9504. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9505. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9506. ////pthread_join(t, NULL); //
  9507. //pthread_detach(t);
  9508. //sendUpdateFirmwareConfirmation(uuid);
  9509. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9510. return result;
  9511. }
  9512. void *UpdateFirmwareProcess(void *data)
  9513. {
  9514. pthread_detach(pthread_self());
  9515. mtrace();
  9516. int retriesInt =0, retryIntervalInt=0;
  9517. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9518. int port=0;
  9519. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9520. int isSuccess = 0;
  9521. char ftpbuf[200];
  9522. char temp[100];
  9523. char * pch;
  9524. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9525. json_object *UpdateFirmware;
  9526. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9527. if(!is_error(UpdateFirmware))
  9528. {
  9529. // Required data
  9530. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9531. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9532. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9533. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9534. // Optional data
  9535. if(json_object_object_get(UpdateFirmware, "retries"))
  9536. {
  9537. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9538. }
  9539. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9540. {
  9541. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9542. }
  9543. }
  9544. json_object_put(UpdateFirmware);
  9545. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9546. memset(path, 0, ARRAY_SIZE(path));
  9547. system("rm -f /mnt/*");
  9548. if(strncmp(locationstr,"http", 4) == 0)
  9549. {
  9550. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9551. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9552. // protocol, user, password, host, path);
  9553. sprintf(ftppath,"/%s", path);
  9554. DEBUG_INFO("locationstr: %s\n", locationstr);
  9555. DEBUG_INFO("protocol: %s\n",protocol);
  9556. DEBUG_INFO("host: %s\n",host);
  9557. DEBUG_INFO("path: %s\n",path);
  9558. DEBUG_INFO("ftppath: %s\n",ftppath);
  9559. int ftppathlen=strlen(ftppath);
  9560. int i=1;
  9561. char filenametemp[50];
  9562. while(i < ftppathlen)
  9563. {
  9564. int len=ftppathlen-i;
  9565. if(ftppath[len]== 47) // '/' ascll code: 47
  9566. {
  9567. DEBUG_INFO("compare '/' all right\n");
  9568. break;
  9569. }
  9570. i=i+1;
  9571. }
  9572. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9573. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9574. filenametemp[i+1] = 0;
  9575. do
  9576. {
  9577. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9578. sleep(3);
  9579. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9580. if(!isSuccess)
  9581. {
  9582. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9583. sleep(retryIntervalInt);
  9584. }
  9585. else
  9586. {
  9587. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9588. }
  9589. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9590. }
  9591. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9592. {
  9593. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9594. memset(temp, 0, ARRAY_SIZE(temp));
  9595. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9596. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9597. int ftppathlen=strlen(ftpbuf);
  9598. int i=1;
  9599. char filenametemp[50];
  9600. while(i < ftppathlen)
  9601. {
  9602. int len=ftppathlen-i;
  9603. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9604. {
  9605. DEBUG_INFO(" compare '/' all right\n");
  9606. break;
  9607. }
  9608. i=i+1;
  9609. }
  9610. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9611. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9612. filenametemp[i+1] = 0;
  9613. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9614. pch=strchr(temp,'@');
  9615. if(pch==NULL)
  9616. {
  9617. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9618. protocol, host, &port, path);
  9619. strcpy(user,"anonymous");
  9620. strcpy(password,"");
  9621. }
  9622. else
  9623. {
  9624. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9625. protocol, user, password, host, &port, path);
  9626. }
  9627. sscanf(host,"%[^/]%s",host1, path1);
  9628. sprintf(ftppath,"%s", path1);
  9629. //DEBUG_INFO("protocol =%s\n",protocol);
  9630. //DEBUG_INFO("user =%s\n",user);
  9631. //DEBUG_INFO("password =%s\n",password);
  9632. //DEBUG_INFO("host1 =%s\n",host1);
  9633. //DEBUG_INFO("port =%d\n",port);
  9634. //DEBUG_INFO("path1 =%s\n",path1);
  9635. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9636. //ftpFile(host, user, password, port, ftppath, fname);
  9637. //download firmware pthred
  9638. if(port == 0)
  9639. {
  9640. port = 21;
  9641. }
  9642. do
  9643. {
  9644. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9645. sleep(3);
  9646. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9647. if(!isSuccess)
  9648. {
  9649. //BulldogUtil.sleepMs(interval*1000);
  9650. DEBUG_INFO("Update firmware request and download file fail.\n");
  9651. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9652. sleep(retryIntervalInt);
  9653. }
  9654. else
  9655. {
  9656. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9657. }
  9658. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9659. }
  9660. else
  9661. {
  9662. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9663. }
  9664. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9665. pthread_exit(NULL);
  9666. }
  9667. //==========================================
  9668. // Handle server response routine
  9669. //==========================================
  9670. void handleAuthorizeResponse(char *payload, int gun_index)
  9671. {
  9672. mtrace();
  9673. char expiryDatestr[30]={0};
  9674. char parentIdTagstr[20]={0};
  9675. char statusstr[20]={0};
  9676. int expiryDateISNULL=FALSE;
  9677. int parentIdTagISNULL=FALSE;
  9678. DEBUG_INFO("handleAuthorizeResponse...\n");
  9679. json_object *Authorize;
  9680. Authorize = json_tokener_parse(payload);
  9681. if(!is_error(Authorize))
  9682. {
  9683. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9684. {
  9685. // Required data
  9686. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9687. // Optional data
  9688. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9689. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9690. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9691. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9692. }
  9693. }
  9694. json_object_put(Authorize);
  9695. if(expiryDateISNULL == FALSE)
  9696. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9697. if(parentIdTagISNULL == FALSE)
  9698. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9699. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9700. //Update idTag information to authorization cache if supproted
  9701. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9702. {
  9703. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  9704. }
  9705. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9706. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9707. authorizeRetryTimes = 0;
  9708. }
  9709. void handleBootNotificationResponse(char *payload, int gun_index)
  9710. {
  9711. mtrace();
  9712. char statusStr[12]={0};
  9713. char currentTimeStr[30]={0};
  9714. int intervalInt = 0;
  9715. struct tm tp;
  9716. char buf[28]={0};
  9717. char timebuf[50]={0};
  9718. DEBUG_INFO("handleBootNotificationResponse...\n");
  9719. json_object *BootNotification;
  9720. BootNotification = json_tokener_parse(payload);
  9721. if(!is_error(BootNotification))
  9722. {
  9723. // Required data
  9724. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9725. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9726. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9727. }
  9728. json_object_put(BootNotification);
  9729. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9730. BootNotificationInterval = intervalInt;
  9731. HeartBeatWaitTime = intervalInt;
  9732. //write back to ShmOCPP16Data->BootNotification
  9733. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9734. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9735. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9736. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9737. {
  9738. server_sign = TRUE;
  9739. server_pending =FALSE;
  9740. }
  9741. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9742. {
  9743. server_pending = TRUE;
  9744. }
  9745. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9746. tp.tm_isdst = -1;
  9747. //time_t utc = mktime(&tp);
  9748. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9749. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9750. sprintf(timebuf,"date -s '%s'",buf);
  9751. system(timebuf);
  9752. srand(time(NULL));
  9753. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9754. //==============================================
  9755. // RTC sync
  9756. //==============================================
  9757. system("/sbin/hwclock -w --systohc");
  9758. SetOcppConnStatus(TRUE);
  9759. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9760. }
  9761. void handleDataTransferResponse(char *payload, int gun_index)
  9762. {
  9763. char sstr[160]={0};//sstr[200]={ 0 };
  9764. int c = 0;
  9765. char *loc;
  9766. DEBUG_INFO("handleDataTransferResponse ...\n");
  9767. loc = strstr(payload, "status");
  9768. printf("loc=%s\n",loc);
  9769. c = 0;
  9770. while (loc[3+strlen("status")+c] != '\"')
  9771. {
  9772. sstr[c] = loc[3+strlen("status")+c];
  9773. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9774. c++;
  9775. }
  9776. sstr[c] = '\0';
  9777. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9778. }
  9779. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9780. {
  9781. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9782. //struct json_object *obj;
  9783. // obj = json_tokener_parse(payload);
  9784. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9785. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9786. //No fields are defined.
  9787. }
  9788. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9789. {
  9790. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9791. //struct json_object *obj;
  9792. // obj = json_tokener_parse(payload);
  9793. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9794. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9795. //No fields are defined.
  9796. }
  9797. void handleHeartbeatResponse(char *payload, int gun_index)
  9798. {
  9799. mtrace();
  9800. struct tm tp;
  9801. char buf[28]={0};
  9802. char timebuf[50]={0};
  9803. DEBUG_INFO("handleHeartbeatResponse...\n");
  9804. json_object *Heartbeat;
  9805. Heartbeat = json_tokener_parse(payload);
  9806. if(!is_error(Heartbeat))
  9807. {
  9808. // Required data
  9809. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9810. }
  9811. json_object_put(Heartbeat);
  9812. if(FirstHeartBeat == 0)
  9813. {
  9814. FirstHeartBeat = 1;
  9815. DEBUG_INFO("FirstHeartBeat \n");
  9816. }
  9817. HeartBeatWithNOResponse = 0;
  9818. clientTime.Heartbeat=time((time_t*)NULL);
  9819. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9820. tp.tm_isdst = -1;
  9821. //time_t utc = mktime(&tp);
  9822. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9823. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9824. sprintf(timebuf,"date -s '%s'",buf);
  9825. system(timebuf);
  9826. //==============================================
  9827. // RTC sync
  9828. //==============================================
  9829. system("/sbin/hwclock -w --systohc");
  9830. }
  9831. void handleMeterValuesResponse(char *payload, int gun_index)
  9832. {
  9833. mtrace();
  9834. DEBUG_INFO("handleMeterValuesResponse...\n");
  9835. }
  9836. void handleStartTransactionResponse(char *payload, int gun_index)
  9837. {
  9838. mtrace();
  9839. //int transactionIdInt = 0;
  9840. FILE *outfile;
  9841. char data[100]={0};
  9842. DEBUG_INFO("handleStartTransactionResponse...\n");
  9843. json_object *StartTransaction;
  9844. StartTransaction = json_tokener_parse(payload);
  9845. if(!is_error(StartTransaction))
  9846. {
  9847. // Required data
  9848. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9849. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9850. // Optional data
  9851. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9852. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9853. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9854. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9855. }
  9856. json_object_put(StartTransaction);
  9857. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9858. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9859. //-----------Start : write to the Queue TransactionId file -----------------//
  9860. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9861. {}
  9862. else
  9863. {
  9864. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9865. if(log == NULL)
  9866. {
  9867. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9868. return ;
  9869. }
  9870. else
  9871. {
  9872. fclose(log);
  9873. }
  9874. }
  9875. // open file for writing
  9876. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9877. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9878. {
  9879. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9880. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9881. fputs(data, outfile);
  9882. fclose (outfile);
  9883. }
  9884. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9885. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9886. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9887. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9888. }
  9889. void handleStatusNotificationResponse(char *payload, int gun_index)
  9890. {
  9891. mtrace();
  9892. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9893. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9894. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9895. }
  9896. void handleStopTransactionnResponse(char *payload, int gun_index)
  9897. {
  9898. mtrace();
  9899. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9900. json_object *StopTransaction;
  9901. StopTransaction = json_tokener_parse(payload);
  9902. if(!is_error(StopTransaction))
  9903. {
  9904. // Optional data
  9905. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9906. {
  9907. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9908. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9909. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9910. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9911. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9912. }
  9913. }
  9914. json_object_put(StopTransaction);
  9915. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9916. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9917. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9918. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9919. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9920. }
  9921. //==========================================
  9922. // Handle Error routine
  9923. //==========================================
  9924. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9925. {
  9926. mtrace();
  9927. #ifdef SystemLogMessage
  9928. DEBUG_INFO("errorCode: %s\n", errorCode);
  9929. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9930. DEBUG_INFO("errorDetails: %s\n", payload);
  9931. #endif
  9932. }
  9933. //===============================================
  9934. // Common routine
  9935. //===============================================
  9936. int initialConfigurationTable(void)
  9937. {
  9938. //clock_t start_t, end_t, total_t;
  9939. FILE *fp;
  9940. FILE *outfile;
  9941. char str[200]={0};
  9942. char sstr[100]={0};
  9943. int c = 0;
  9944. char *loc;
  9945. DEBUG_INFO("initialConfigurationTable...\n");
  9946. //start_t = clock();
  9947. //printf("Starting of the program, start_t = %ld\n", start_t);
  9948. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9949. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9950. {
  9951. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9952. if(outfile == NULL)
  9953. {
  9954. DEBUG_INFO("Error opening file\n");
  9955. return FALSE;
  9956. }
  9957. /*Core Profile*/
  9958. //AllowOfflineTxForUnknownId
  9959. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9963. //AuthorizationCacheEnabled
  9964. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9968. //AuthorizeRemoteTxRequests
  9969. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9973. //BlinkRepeat
  9974. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9978. //ClockAlignedDataInterval
  9979. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9982. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9983. //ConnectionTimeOut
  9984. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9988. //GetConfigurationMaxKeys
  9989. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  9992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9993. // HeartbeatInterval
  9994. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  9997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9998. // LightIntensity
  9999. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10003. // LocalAuthorizeOffline
  10004. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10008. // LocalPreAuthorize
  10009. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10013. // MaxEnergyOnInvalidId
  10014. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10017. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10019. // MeterValuesAlignedData
  10020. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10024. else
  10025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10027. // MeterValuesAlignedDataMaxLength
  10028. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10030. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10032. else
  10033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10035. // MeterValuesSampledData
  10036. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10038. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10040. else
  10041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10043. // MeterValuesSampledDataMaxLength
  10044. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10046. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10048. else
  10049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10051. // MeterValueSampleInterval
  10052. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10056. // MinimumStatusDuration
  10057. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10060. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10062. // NumberOfConnectors
  10063. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10066. {
  10067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10068. }
  10069. else
  10070. {
  10071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10072. }
  10073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10074. // ResetRetries
  10075. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10079. // ConnectorPhaseRotation
  10080. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10084. // ConnectorPhaseRotationMaxLength
  10085. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10089. // StopTransactionOnEVSideDisconnect
  10090. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10094. // StopTransactionOnInvalidId
  10095. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10099. // StopTxnAlignedData
  10100. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10104. // StopTxnAlignedDataMaxLength
  10105. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10109. // StopTxnSampledData
  10110. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10112. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10114. else
  10115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10117. // StopTxnSampledDataMaxLength
  10118. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10121. {
  10122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10123. }
  10124. else
  10125. {
  10126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10127. }
  10128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10129. // SupportedFeatureProfiles
  10130. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10134. // SupportedFeatureProfilesMaxLength
  10135. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10139. // TransactionMessageAttempts
  10140. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10143. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10145. // TransactionMessageRetryInterval
  10146. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10149. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10151. // UnlockConnectorOnEVSideDisconnect
  10152. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10156. // WebSocketPingInterval
  10157. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10161. // QueueOffLineStartTransactionMessage
  10162. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10166. // AuthorizationKey
  10167. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10171. // SecurityProfile
  10172. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10176. // DefaultPrice
  10177. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10181. // CustomDisplayCostAndPrice
  10182. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10186. // CustomIdleFeeAfterStop
  10187. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10191. //* Local Auth List Management Profile*/
  10192. #if 0
  10193. //For OCTT Test Case
  10194. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10197. #endif
  10198. #if 1
  10199. //LocalAuthListEnabled
  10200. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10204. #endif
  10205. //LocalAuthListMaxLength
  10206. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10210. //SendLocalListMaxLength
  10211. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10215. //ReserveConnectorZeroSupported
  10216. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10220. //* Smart Charging Profile */
  10221. //ChargeProfileMaxStackLevel
  10222. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10226. // ChargingScheduleAllowedChargingRateUnit
  10227. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10231. // ChargingScheduleMaxPeriods
  10232. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10236. // ConnectorSwitch3to1PhaseSupported
  10237. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10241. // MaxChargingProfilesInstalled
  10242. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10246. fclose(outfile);
  10247. }
  10248. else
  10249. {
  10250. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10251. char keystr[60]={0};
  10252. char readonlystr[10]={0};
  10253. char valuestr[100]={0};
  10254. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10255. if(fp == NULL) {
  10256. DEBUG_INFO("Error opening file");
  10257. return FALSE;
  10258. }
  10259. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10260. {
  10261. //DEBUG_INFO("Get Configuration \n");
  10262. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10263. //*************************key*********************************/
  10264. loc = strstr(str, "key");
  10265. c = 0;
  10266. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10267. while (loc[strlen("key")+3+c] != '\"')
  10268. {
  10269. sstr[c] = loc[strlen("key")+3+c];
  10270. c++;
  10271. }
  10272. sstr[c] = '\0';
  10273. strcpy(keystr,sstr);
  10274. //*************************readonly*********************************/
  10275. loc = strstr(str, "readonly");
  10276. c = 0;
  10277. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10278. while (loc[strlen("readonly")+2+c] != ',')
  10279. {
  10280. sstr[c] = loc[strlen("readonly")+2+c];
  10281. c++;
  10282. }
  10283. sstr[c] = '\0';
  10284. strcpy(readonlystr,sstr);
  10285. //*************************value*********************************/
  10286. loc = strstr(str, "value");
  10287. c = 0;
  10288. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10289. while (loc[strlen("value")+3+c] != '\"')
  10290. {
  10291. sstr[c] = loc[strlen("value")+3+c];
  10292. c++;
  10293. }
  10294. sstr[c] = '\0';
  10295. strcpy(valuestr,sstr);
  10296. // DEBUG_INFO("keystr=%s\n",keystr);
  10297. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10298. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10299. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10300. {
  10301. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10302. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10304. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10305. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10306. }
  10307. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10308. {
  10309. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10310. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10312. }
  10313. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10314. {
  10315. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10317. }
  10318. if(strcmp(keystr, "BlinkRepeat") == 0)
  10319. {
  10320. //Charger.BlinkRepeat = Integer.parseInt(value);
  10321. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10323. }
  10324. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10325. {
  10326. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10328. }
  10329. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10330. {
  10331. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10333. }
  10334. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10335. {
  10336. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10338. }
  10339. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10340. {
  10341. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10343. HeartBeatWaitTime = atoi(valuestr);
  10344. }
  10345. if(strcmp(keystr, "LightIntensity") == 0)
  10346. {
  10347. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10349. }
  10350. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10351. {
  10352. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10354. }
  10355. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10356. {
  10357. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10359. }
  10360. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10361. {
  10362. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10364. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10365. }
  10366. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10367. {
  10368. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10370. }
  10371. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10372. {
  10373. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10375. }
  10376. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10377. {
  10378. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10380. }
  10381. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10382. {
  10383. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10385. }
  10386. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10387. {
  10388. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10390. }
  10391. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10392. {
  10393. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10395. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10396. }
  10397. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10398. {
  10399. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10401. }
  10402. if(strcmp(keystr, "ResetRetries") == 0)
  10403. {
  10404. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10406. }
  10407. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10408. {
  10409. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10411. }
  10412. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10413. {
  10414. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10416. }
  10417. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10418. {
  10419. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10421. }
  10422. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10423. {
  10424. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10426. }
  10427. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10428. {
  10429. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10431. }
  10432. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10433. {
  10434. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10436. }
  10437. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10438. {
  10439. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10441. }
  10442. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10443. {
  10444. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10446. }
  10447. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10448. {
  10449. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10451. }
  10452. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10453. {
  10454. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10456. }
  10457. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10458. {
  10459. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10461. TransactionMessageAttemptsValue = atoi(valuestr);
  10462. }
  10463. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10464. {
  10465. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10467. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10468. }
  10469. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10470. {
  10471. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10473. }
  10474. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10475. {
  10476. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10478. }
  10479. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10480. {
  10481. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10483. }
  10484. if(strcmp(keystr, "AuthorizationKey") == 0)
  10485. {
  10486. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10488. }
  10489. if(strcmp(keystr, "SecurityProfile") == 0)
  10490. {
  10491. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10493. }
  10494. if(strcmp(keystr, "DefaultPrice") == 0)
  10495. {
  10496. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10498. }
  10499. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10500. {
  10501. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10503. }
  10504. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10505. {
  10506. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10508. }
  10509. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10510. {
  10511. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10512. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10513. }
  10514. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10515. {
  10516. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10518. }
  10519. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10520. {
  10521. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10523. }
  10524. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10525. {
  10526. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10528. }
  10529. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10530. {
  10531. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10533. }
  10534. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10535. {
  10536. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10538. }
  10539. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10540. {
  10541. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10543. }
  10544. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10545. {
  10546. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10548. }
  10549. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10550. {
  10551. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10553. }
  10554. }
  10555. fclose(fp);
  10556. }
  10557. return 0;
  10558. }
  10559. void StoreConfigurationTable(void)
  10560. {
  10561. FILE *outfile;
  10562. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10563. if(outfile == NULL)
  10564. {
  10565. DEBUG_INFO("Error opening file");
  10566. return ;
  10567. }
  10568. /*Core Profile*/
  10569. //AllowOfflineTxForUnknownId
  10570. /*
  10571. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10572. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10575. */
  10576. //DEBUG_INFO("data=%s\n",data);
  10577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10578. //AuthorizationCacheEnabled
  10579. /*
  10580. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10583. */
  10584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10585. //AuthorizeRemoteTxRequests
  10586. /*
  10587. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10590. */
  10591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10592. //BlinkRepeat
  10593. /*
  10594. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10597. */
  10598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10599. //ClockAlignedDataInterval
  10600. /*
  10601. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10604. */
  10605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10606. //ConnectionTimeOut
  10607. /*
  10608. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10611. */
  10612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10613. //GetConfigurationMaxKeys
  10614. /*
  10615. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10618. */
  10619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10620. // HeartbeatInterval
  10621. /*
  10622. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10625. */
  10626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10627. // LightIntensity
  10628. /*
  10629. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10632. */
  10633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10634. // LocalAuthorizeOffline
  10635. /*
  10636. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10639. */
  10640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10641. // LocalPreAuthorize
  10642. /*
  10643. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10646. */
  10647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10648. // MaxEnergyOnInvalidId
  10649. /*
  10650. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10653. */
  10654. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10656. // MeterValuesAlignedData
  10657. /*
  10658. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10661. */
  10662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10663. // MeterValuesAlignedDataMaxLength
  10664. /*
  10665. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10668. */
  10669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10670. // MeterValuesSampledData
  10671. /*
  10672. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10675. */
  10676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10677. // MeterValuesSampledDataMaxLength
  10678. /*
  10679. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10682. */
  10683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10684. // MeterValueSampleInterval
  10685. /*
  10686. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10689. */
  10690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10691. // MinimumStatusDuration
  10692. /*
  10693. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10696. */
  10697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10698. // NumberOfConnectors
  10699. /*
  10700. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10703. {
  10704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10705. }
  10706. else
  10707. {
  10708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10709. }
  10710. */
  10711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10712. // ResetRetries
  10713. /*
  10714. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10717. */
  10718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10719. // ConnectorPhaseRotation
  10720. /*
  10721. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10724. */
  10725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10726. // ConnectorPhaseRotationMaxLength
  10727. /*
  10728. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10731. */
  10732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10733. // StopTransactionOnEVSideDisconnect
  10734. /*
  10735. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10738. */
  10739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10740. // StopTransactionOnInvalidId
  10741. /*
  10742. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10745. */
  10746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10747. // StopTxnAlignedData
  10748. /*
  10749. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10752. */
  10753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10754. // StopTxnAlignedDataMaxLength
  10755. /*
  10756. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10759. */
  10760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10761. // StopTxnSampledData
  10762. /*
  10763. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10766. */
  10767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10768. // StopTxnSampledDataMaxLength
  10769. /*
  10770. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10773. */
  10774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10775. // SupportedFeatureProfiles
  10776. /*
  10777. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10780. */
  10781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10782. // SupportedFeatureProfilesMaxLength
  10783. /*
  10784. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10787. */
  10788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10789. // TransactionMessageAttempts
  10790. /*
  10791. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10794. */
  10795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10796. // TransactionMessageRetryInterval
  10797. /*
  10798. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10801. */
  10802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10803. // UnlockConnectorOnEVSideDisconnect
  10804. /*
  10805. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10808. */
  10809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10810. // WebSocketPingInterval
  10811. /*
  10812. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10815. */
  10816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10817. // QueueOffLineStartTransactionMessage
  10818. /*
  10819. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10822. */
  10823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10824. // AuthorizationKey
  10825. /*
  10826. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10829. */
  10830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10831. // SecurityProfile
  10832. /*
  10833. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10836. */
  10837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10838. // DefaultPrice
  10839. /*
  10840. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10843. */
  10844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10845. // CustomDisplayCostAndPrice
  10846. /*
  10847. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10850. */
  10851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10852. // CustomIdleFeeAfterStop
  10853. /*
  10854. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10857. */
  10858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10859. //* Local Auth List Management Profile*/
  10860. //LocalAuthListEnabled
  10861. /*
  10862. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10865. */
  10866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10867. //LocalAuthListMaxLength
  10868. /*
  10869. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10872. */
  10873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10874. //SendLocalListMaxLength
  10875. /*
  10876. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10879. */
  10880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10881. //ReserveConnectorZeroSupported
  10882. /*
  10883. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10886. */
  10887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10888. //* Smart Charging Profile */
  10889. //ChargeProfileMaxStackLevel
  10890. /*
  10891. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10894. */
  10895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10896. // ChargingScheduleAllowedChargingRateUnit
  10897. /*
  10898. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10901. */
  10902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10903. // ChargingScheduleMaxPeriods
  10904. /*
  10905. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10908. */
  10909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10910. // ConnectorSwitch3to1PhaseSupported
  10911. /*
  10912. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10915. */
  10916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10917. // MaxChargingProfilesInstalled
  10918. /*
  10919. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10922. */
  10923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10924. fclose(outfile);
  10925. }
  10926. void getKeyValue(char *keyReq)
  10927. {
  10928. int isEmpty = FALSE;
  10929. int isKnowKey = FALSE;
  10930. DEBUG_INFO("keyReq = %s\n", keyReq);
  10931. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10932. isEmpty = TRUE;
  10933. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10934. {
  10935. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10938. {
  10939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10940. }
  10941. else
  10942. {
  10943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10944. }
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10946. isKnowKey = TRUE;
  10947. }
  10948. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10949. {
  10950. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10953. {
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10955. }
  10956. else
  10957. {
  10958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10959. }
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10961. isKnowKey = TRUE;
  10962. }
  10963. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10964. {
  10965. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10968. {
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10970. }
  10971. else
  10972. {
  10973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10974. }
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10976. isKnowKey = TRUE;
  10977. }
  10978. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10979. {
  10980. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10983. {
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10985. }
  10986. else
  10987. {
  10988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10989. }
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10991. isKnowKey = TRUE;
  10992. }
  10993. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10994. {
  10995. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10998. {
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11000. }
  11001. else
  11002. {
  11003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11004. }
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11006. isKnowKey = TRUE;
  11007. }
  11008. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11009. {
  11010. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11013. {
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11015. }
  11016. else
  11017. {
  11018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11019. }
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11021. isKnowKey = TRUE;
  11022. }
  11023. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11024. {
  11025. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11027. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11028. {
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11030. }
  11031. else
  11032. {
  11033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11034. }
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11036. isKnowKey = TRUE;
  11037. }
  11038. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11039. {
  11040. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11042. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11043. {
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11045. }
  11046. else
  11047. {
  11048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11049. }
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11051. isKnowKey = TRUE;
  11052. }
  11053. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11054. {
  11055. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11057. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11058. {
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11060. }
  11061. else
  11062. {
  11063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11064. }
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11066. isKnowKey = TRUE;
  11067. }
  11068. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11069. {
  11070. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11073. {
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11075. }
  11076. else
  11077. {
  11078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11079. }
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11081. isKnowKey = TRUE;
  11082. }
  11083. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11084. {
  11085. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11088. {
  11089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11090. }
  11091. else
  11092. {
  11093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11094. }
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11096. isKnowKey = TRUE;
  11097. }
  11098. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11099. {
  11100. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11103. {
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11105. }
  11106. else
  11107. {
  11108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11109. }
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11111. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11112. isKnowKey = TRUE;
  11113. }
  11114. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11115. {
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11119. {
  11120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11121. }
  11122. else
  11123. {
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11125. }
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11127. isKnowKey = TRUE;
  11128. }
  11129. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11130. {
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11134. {
  11135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11136. }
  11137. else
  11138. {
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11140. }
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11142. isKnowKey = TRUE;
  11143. }
  11144. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11145. {
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11149. {
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11151. }
  11152. else
  11153. {
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11155. }
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11157. isKnowKey = TRUE;
  11158. }
  11159. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11160. {
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11163. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11164. {
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11166. }
  11167. else
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11170. }
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11172. isKnowKey = TRUE;
  11173. }
  11174. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11175. {
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11179. {
  11180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11181. }
  11182. else
  11183. {
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11185. }
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11187. isKnowKey = TRUE;
  11188. }
  11189. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11190. {
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11194. {
  11195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11196. }
  11197. else
  11198. {
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11200. }
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11202. isKnowKey = TRUE;
  11203. }
  11204. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11205. {
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11208. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11209. {
  11210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11211. }
  11212. else
  11213. {
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11215. }
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11217. isKnowKey = TRUE;
  11218. }
  11219. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11220. {
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11223. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11224. {
  11225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11226. }
  11227. else
  11228. {
  11229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11230. }
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11232. isKnowKey = TRUE;
  11233. }
  11234. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11235. {
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11239. {
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11241. }
  11242. else
  11243. {
  11244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11245. }
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11247. isKnowKey = TRUE;
  11248. }
  11249. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11250. {
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11254. {
  11255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11256. }
  11257. else
  11258. {
  11259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11260. }
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11262. isKnowKey = TRUE;
  11263. }
  11264. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11265. {
  11266. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11268. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11269. {
  11270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11271. }
  11272. else
  11273. {
  11274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11275. }
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11277. isKnowKey = TRUE;
  11278. }
  11279. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11280. {
  11281. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11283. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11284. {
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11286. }
  11287. else
  11288. {
  11289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11290. }
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11292. isKnowKey = TRUE;
  11293. }
  11294. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11295. {
  11296. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11298. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11299. {
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11301. }
  11302. else
  11303. {
  11304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11305. }
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11307. isKnowKey = TRUE;
  11308. }
  11309. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11310. {
  11311. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11314. {
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11316. }
  11317. else
  11318. {
  11319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11320. }
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11322. isKnowKey = TRUE;
  11323. }
  11324. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11325. {
  11326. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11329. {
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11331. }
  11332. else
  11333. {
  11334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11335. }
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11337. isKnowKey = TRUE;
  11338. }
  11339. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11340. {
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11344. {
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11346. }
  11347. else
  11348. {
  11349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11350. }
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11352. isKnowKey = TRUE;
  11353. }
  11354. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11355. {
  11356. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11359. {
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11361. }
  11362. else
  11363. {
  11364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11365. }
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11367. isKnowKey = TRUE;
  11368. }
  11369. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11370. {
  11371. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11374. {
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11376. }
  11377. else
  11378. {
  11379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11380. }
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11382. isKnowKey = TRUE;
  11383. }
  11384. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11385. {
  11386. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11388. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11389. {
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11391. }
  11392. else
  11393. {
  11394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11395. }
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11397. isKnowKey = TRUE;
  11398. }
  11399. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11400. {
  11401. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11404. {
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11406. }
  11407. else
  11408. {
  11409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11410. }
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11412. isKnowKey = TRUE;
  11413. }
  11414. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11415. {
  11416. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11418. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11419. {
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11421. }
  11422. else
  11423. {
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11425. }
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11427. isKnowKey = TRUE;
  11428. }
  11429. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11430. {
  11431. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11434. {
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11436. }
  11437. else
  11438. {
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11440. }
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11442. isKnowKey = TRUE;
  11443. }
  11444. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11445. {
  11446. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11448. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11449. {
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11451. }
  11452. else
  11453. {
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11455. }
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11457. isKnowKey = TRUE;
  11458. }
  11459. /*
  11460. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11461. {
  11462. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11465. {
  11466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11467. }
  11468. else
  11469. {
  11470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11471. }
  11472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11473. isKnowKey = TRUE;
  11474. }*/
  11475. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11476. {
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11480. {
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11482. }
  11483. else
  11484. {
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11486. }
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11488. isKnowKey = TRUE;
  11489. }
  11490. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11491. {
  11492. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11495. {
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11497. }
  11498. else
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11501. }
  11502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11503. isKnowKey = TRUE;
  11504. }
  11505. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11506. {
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11510. {
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11512. }
  11513. else
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11516. }
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11518. isKnowKey = TRUE;
  11519. }
  11520. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11521. {
  11522. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11525. {
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11527. }
  11528. else
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11531. }
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11533. isKnowKey = TRUE;
  11534. }
  11535. #if 1
  11536. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11540. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11541. {
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11543. }
  11544. else
  11545. {
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11547. }
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11549. isKnowKey = TRUE;
  11550. }
  11551. #endif
  11552. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11553. {
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11556. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11557. {
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11559. }
  11560. else
  11561. {
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11563. }
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11565. isKnowKey = TRUE;
  11566. }
  11567. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11568. {
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11571. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11572. {
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11574. }
  11575. else
  11576. {
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11578. }
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11580. isKnowKey = TRUE;
  11581. }
  11582. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11583. {
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11586. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11587. {
  11588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11589. }
  11590. else
  11591. {
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11593. }
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11595. isKnowKey = TRUE;
  11596. }
  11597. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11598. {
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11601. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11602. {
  11603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11604. }
  11605. else
  11606. {
  11607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11608. }
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11610. isKnowKey = TRUE;
  11611. }
  11612. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11613. {
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11616. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11617. {
  11618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11619. }
  11620. else
  11621. {
  11622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11623. }
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11625. isKnowKey = TRUE;
  11626. }
  11627. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11628. {
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11631. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11632. {
  11633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11634. }
  11635. else
  11636. {
  11637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11638. }
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11640. isKnowKey = TRUE;
  11641. }
  11642. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11643. {
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11646. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11647. {
  11648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11649. }
  11650. else
  11651. {
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11653. }
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11655. isKnowKey = TRUE;
  11656. }
  11657. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11658. {
  11659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11661. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11662. {
  11663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11664. }
  11665. else
  11666. {
  11667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11668. }
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11670. isKnowKey = TRUE;
  11671. }
  11672. //=========================================================
  11673. if(!isEmpty && !isKnowKey)
  11674. {
  11675. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11676. strcpy(unknownkey[UnknownKeynum], keyReq);
  11677. UnknownKeynum = UnknownKeynum + 1;
  11678. }
  11679. }
  11680. void processUnkownKey(void)
  11681. {
  11682. DEBUG_INFO("processUnkownKey...\n");
  11683. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11684. for(int index=0; index < UnknownKeynum; index++)
  11685. {
  11686. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11687. {
  11688. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11689. }
  11690. }
  11691. }
  11692. int setKeyValue(char *key, char *value)
  11693. {
  11694. int isSuccess = NotSupported;
  11695. int check_ascii=0;
  11696. char str[10]={0};
  11697. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11698. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11699. {
  11700. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11702. {
  11703. strcpy(str, (const char*)value);
  11704. for(int i = 0; str[i]; i++){
  11705. str[i] = tolower(str[i]);
  11706. }
  11707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11708. isSuccess = ConfigurationStatus_Accepted;
  11709. }
  11710. else
  11711. {
  11712. isSuccess = ConfigurationStatus_Rejected;
  11713. }
  11714. }
  11715. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11716. {
  11717. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11718. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11719. {
  11720. strcpy(str, (const char*)value);
  11721. for(int i = 0; str[i]; i++){
  11722. str[i] = tolower(str[i]);
  11723. }
  11724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11725. isSuccess = ConfigurationStatus_Accepted;
  11726. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11727. }
  11728. else
  11729. {
  11730. isSuccess = ConfigurationStatus_Rejected;
  11731. }
  11732. }
  11733. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11734. {
  11735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11736. {
  11737. strcpy(str, (const char*)value);
  11738. for(int i = 0; str[i]; i++)
  11739. {
  11740. str[i] = tolower(str[i]);
  11741. }
  11742. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11744. isSuccess = ConfigurationStatus_Accepted;
  11745. }
  11746. else
  11747. {
  11748. isSuccess = ConfigurationStatus_Rejected;
  11749. }
  11750. }
  11751. if(strcmp(key, "BlinkRepeat") == 0)
  11752. {
  11753. //Charger.BlinkRepeat = Integer.parseInt(value);
  11754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11755. {
  11756. check_ascii = value[0];
  11757. if( (check_ascii < 48) || (check_ascii > 57) )
  11758. {
  11759. isSuccess = ConfigurationStatus_Rejected;
  11760. }
  11761. else
  11762. {
  11763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11764. isSuccess = ConfigurationStatus_Accepted;
  11765. }
  11766. }
  11767. else
  11768. {
  11769. isSuccess = ConfigurationStatus_Rejected;
  11770. }
  11771. }
  11772. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11773. {
  11774. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11775. {
  11776. check_ascii = value[0];
  11777. if( (check_ascii < 48) || (check_ascii > 57) )
  11778. {
  11779. isSuccess = ConfigurationStatus_Rejected;
  11780. }
  11781. else
  11782. {
  11783. if((atoi(value) == 0) || (atoi(value) >= 10))
  11784. {
  11785. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11787. isSuccess = ConfigurationStatus_Accepted;
  11788. }
  11789. else
  11790. isSuccess = ConfigurationStatus_Rejected;
  11791. }
  11792. }
  11793. else
  11794. {
  11795. isSuccess = ConfigurationStatus_Rejected;
  11796. }
  11797. }
  11798. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11799. {
  11800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11801. {
  11802. check_ascii = value[0];
  11803. if( (check_ascii < 48) || (check_ascii > 57) )
  11804. {
  11805. isSuccess = ConfigurationStatus_Rejected;
  11806. }
  11807. else
  11808. {
  11809. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11811. isSuccess = ConfigurationStatus_Accepted;
  11812. }
  11813. }
  11814. else
  11815. {
  11816. isSuccess = ConfigurationStatus_Rejected;
  11817. }
  11818. }
  11819. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11820. {
  11821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11822. {
  11823. check_ascii = value[0];
  11824. if( (check_ascii < 48) || (check_ascii > 57) )
  11825. {
  11826. isSuccess = ConfigurationStatus_Rejected;
  11827. }
  11828. else
  11829. {
  11830. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11832. isSuccess = ConfigurationStatus_Accepted;
  11833. }
  11834. }
  11835. else
  11836. {
  11837. isSuccess = ConfigurationStatus_Rejected;
  11838. }
  11839. }
  11840. if(strcmp(key, "HeartbeatInterval") == 0)
  11841. {
  11842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11843. {
  11844. check_ascii = value[0];
  11845. if( (check_ascii < 48) || (check_ascii > 57) )
  11846. {
  11847. isSuccess = ConfigurationStatus_Rejected;
  11848. }
  11849. else
  11850. {
  11851. if((atoi(value) == 0) || (atoi(value) >= 10))
  11852. {
  11853. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11855. HeartBeatWaitTime = atoi(value);
  11856. isSuccess = ConfigurationStatus_Accepted;
  11857. }
  11858. else
  11859. {
  11860. isSuccess = ConfigurationStatus_Rejected;
  11861. }
  11862. }
  11863. }
  11864. else
  11865. {
  11866. isSuccess = ConfigurationStatus_Rejected;
  11867. }
  11868. }
  11869. if(strcmp(key, "LightIntensity") == 0)
  11870. {
  11871. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11872. {
  11873. check_ascii = value[0];
  11874. if( (check_ascii < 48) || (check_ascii > 57) )
  11875. {
  11876. isSuccess = ConfigurationStatus_Rejected;
  11877. }
  11878. else
  11879. {
  11880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11881. isSuccess = ConfigurationStatus_Accepted;
  11882. }
  11883. }
  11884. else
  11885. {
  11886. isSuccess = ConfigurationStatus_Rejected;
  11887. }
  11888. }
  11889. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11890. {
  11891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11892. {
  11893. strcpy(str, (const char*)value);
  11894. for(int i = 0; str[i]; i++)
  11895. {
  11896. str[i] = tolower(str[i]);
  11897. }
  11898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11899. isSuccess = ConfigurationStatus_Accepted;
  11900. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11901. }
  11902. else
  11903. {
  11904. isSuccess = ConfigurationStatus_Rejected;
  11905. }
  11906. }
  11907. if(strcmp(key, "LocalPreAuthorize") == 0)
  11908. {
  11909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11910. {
  11911. strcpy(str, (const char*)value);
  11912. for(int i = 0; str[i]; i++)
  11913. {
  11914. str[i] = tolower(str[i]);
  11915. }
  11916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11917. isSuccess = ConfigurationStatus_Accepted;
  11918. }
  11919. else
  11920. {
  11921. isSuccess = ConfigurationStatus_Rejected;
  11922. }
  11923. }
  11924. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11925. {
  11926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11927. {
  11928. check_ascii = value[0];
  11929. if( (check_ascii < 48) || (check_ascii > 57) )
  11930. {
  11931. isSuccess = ConfigurationStatus_Rejected;
  11932. }
  11933. else
  11934. {
  11935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11936. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11937. isSuccess = ConfigurationStatus_Accepted;
  11938. }
  11939. }
  11940. else
  11941. {
  11942. isSuccess = ConfigurationStatus_Rejected;
  11943. }
  11944. }
  11945. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11946. {
  11947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11948. {
  11949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11950. isSuccess = ConfigurationStatus_Accepted;
  11951. }
  11952. else
  11953. {
  11954. isSuccess = ConfigurationStatus_Rejected;
  11955. }
  11956. }
  11957. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11958. {
  11959. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11960. {
  11961. check_ascii = value[0];
  11962. if( (check_ascii < 48) || (check_ascii > 57) )
  11963. {
  11964. isSuccess = ConfigurationStatus_Rejected;
  11965. }
  11966. else
  11967. {
  11968. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11970. isSuccess = ConfigurationStatus_Accepted;
  11971. }
  11972. }
  11973. else
  11974. {
  11975. isSuccess = ConfigurationStatus_Rejected;
  11976. }
  11977. }
  11978. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11979. {
  11980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11981. {
  11982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11983. isSuccess = ConfigurationStatus_Accepted;
  11984. }
  11985. else
  11986. {
  11987. isSuccess = ConfigurationStatus_Rejected;
  11988. }
  11989. }
  11990. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11991. {
  11992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11993. {
  11994. check_ascii = value[0];
  11995. if( (check_ascii < 48) || (check_ascii > 57) )
  11996. {
  11997. isSuccess = ConfigurationStatus_Rejected;
  11998. }
  11999. else
  12000. {
  12001. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12003. isSuccess = ConfigurationStatus_Accepted;
  12004. }
  12005. }
  12006. else
  12007. {
  12008. isSuccess = ConfigurationStatus_Rejected;
  12009. }
  12010. }
  12011. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12012. {
  12013. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12014. {
  12015. check_ascii = value[0];
  12016. if( (check_ascii < 48) || (check_ascii > 57) )
  12017. {
  12018. isSuccess = ConfigurationStatus_Rejected;
  12019. }
  12020. else
  12021. {
  12022. if((atoi(value) == 0) || (atoi(value) >= 10))
  12023. {
  12024. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12026. isSuccess = ConfigurationStatus_Accepted;
  12027. }
  12028. else
  12029. {
  12030. isSuccess = ConfigurationStatus_Rejected;
  12031. }
  12032. }
  12033. }
  12034. else
  12035. {
  12036. isSuccess = ConfigurationStatus_Rejected;
  12037. }
  12038. }
  12039. if(strcmp(key, "MinimumStatusDuration") == 0)
  12040. {
  12041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12042. {
  12043. check_ascii = value[0];
  12044. if( (check_ascii < 48) || (check_ascii > 57) )
  12045. {
  12046. isSuccess = ConfigurationStatus_Rejected;
  12047. }
  12048. else
  12049. {
  12050. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12051. {
  12052. isSuccess = ConfigurationStatus_Rejected;
  12053. }
  12054. else
  12055. {
  12056. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12058. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12059. isSuccess = ConfigurationStatus_Accepted;
  12060. }
  12061. }
  12062. }
  12063. else
  12064. {
  12065. isSuccess = ConfigurationStatus_Rejected;
  12066. }
  12067. }
  12068. if(strcmp(key, "NumberOfConnectors") == 0)
  12069. {
  12070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12071. {
  12072. check_ascii = value[0];
  12073. if( (check_ascii < 48) || (check_ascii > 57) )
  12074. {
  12075. isSuccess = ConfigurationStatus_Rejected;
  12076. }
  12077. else
  12078. {
  12079. //Charger.ResetRetries = Integer.parseInt(value);
  12080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12081. isSuccess = ConfigurationStatus_Accepted;
  12082. }
  12083. }
  12084. else
  12085. {
  12086. isSuccess = ConfigurationStatus_Rejected;
  12087. }
  12088. }
  12089. if(strcmp(key, "ResetRetries") == 0)
  12090. {
  12091. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12092. {
  12093. check_ascii = value[0];
  12094. if( (check_ascii < 48) || (check_ascii > 57) )
  12095. {
  12096. isSuccess = ConfigurationStatus_Rejected;
  12097. }
  12098. else
  12099. {
  12100. //Charger.ResetRetries = Integer.parseInt(value);
  12101. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12102. isSuccess = ConfigurationStatus_Accepted;
  12103. }
  12104. }
  12105. else
  12106. {
  12107. isSuccess = ConfigurationStatus_Rejected;
  12108. }
  12109. }
  12110. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12111. {
  12112. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12113. {
  12114. strcpy(str, (const char*)value);
  12115. for(int i = 0; str[i]; i++)
  12116. {
  12117. str[i] = tolower(str[i]);
  12118. }
  12119. if(strcmp(str, "notapplicable")== 0)
  12120. {
  12121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12122. isSuccess = ConfigurationStatus_Accepted;
  12123. }
  12124. else if(strcmp(str, "unknown")== 0)
  12125. {
  12126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12127. isSuccess = ConfigurationStatus_Accepted;
  12128. }
  12129. else if(strcmp(str, "rst")== 0)
  12130. {
  12131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12132. isSuccess = ConfigurationStatus_Accepted;
  12133. }
  12134. else if(strcmp(str, "rts")== 0)
  12135. {
  12136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12137. isSuccess = ConfigurationStatus_Accepted;
  12138. }
  12139. else if(strcmp(str, "srt")== 0)
  12140. {
  12141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12142. isSuccess = ConfigurationStatus_Accepted;
  12143. }
  12144. else if(strcmp(str, "str")== 0)
  12145. {
  12146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12147. isSuccess = ConfigurationStatus_Accepted;
  12148. }
  12149. else if(strcmp(str, "trs")== 0)
  12150. {
  12151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12152. isSuccess = ConfigurationStatus_Accepted;
  12153. }
  12154. else if(strcmp(str, "tsr")== 0)
  12155. {
  12156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12157. isSuccess = ConfigurationStatus_Accepted;
  12158. }
  12159. else
  12160. {
  12161. isSuccess = ConfigurationStatus_Rejected;
  12162. }
  12163. }
  12164. else
  12165. {
  12166. isSuccess = ConfigurationStatus_Rejected;
  12167. }
  12168. }
  12169. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12170. {
  12171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12172. {
  12173. check_ascii = value[0];
  12174. if( (check_ascii < 48) || (check_ascii > 57) )
  12175. {
  12176. isSuccess = ConfigurationStatus_Rejected;
  12177. }
  12178. else
  12179. {
  12180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12181. isSuccess = ConfigurationStatus_Accepted;
  12182. }
  12183. }
  12184. else
  12185. {
  12186. isSuccess = ConfigurationStatus_Rejected;
  12187. }
  12188. }
  12189. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12190. {
  12191. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12192. {
  12193. strcpy(str, (const char*)value);
  12194. for(int i = 0; str[i]; i++)
  12195. {
  12196. str[i] = tolower(str[i]);
  12197. }
  12198. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12200. isSuccess = ConfigurationStatus_Accepted;
  12201. }
  12202. else
  12203. {
  12204. isSuccess = ConfigurationStatus_Rejected;
  12205. }
  12206. }
  12207. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12208. {
  12209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12210. {
  12211. strcpy(str, (const char*)value);
  12212. for(int i = 0; str[i]; i++)
  12213. {
  12214. str[i] = tolower(str[i]);
  12215. }
  12216. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12218. isSuccess = ConfigurationStatus_Accepted;
  12219. }
  12220. else
  12221. {
  12222. isSuccess = ConfigurationStatus_Rejected;
  12223. }
  12224. }
  12225. if(strcmp(key, "StopTxnAlignedData") == 0)
  12226. {
  12227. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12228. {
  12229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12230. isSuccess = ConfigurationStatus_Accepted;
  12231. }
  12232. else
  12233. {
  12234. isSuccess = ConfigurationStatus_Rejected;
  12235. }
  12236. }
  12237. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12238. {
  12239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12240. {
  12241. check_ascii = value[0];
  12242. if( (check_ascii < 48) || (check_ascii > 57) )
  12243. {
  12244. isSuccess = ConfigurationStatus_Rejected;
  12245. }
  12246. else
  12247. {
  12248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12249. isSuccess = ConfigurationStatus_Accepted;
  12250. }
  12251. }
  12252. else
  12253. {
  12254. isSuccess = ConfigurationStatus_Rejected;
  12255. }
  12256. }
  12257. if(strcmp(key, "StopTxnSampledData") == 0)
  12258. {
  12259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12260. {
  12261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12262. isSuccess = ConfigurationStatus_Accepted;
  12263. }
  12264. else
  12265. {
  12266. isSuccess = ConfigurationStatus_Rejected;
  12267. }
  12268. }
  12269. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12270. {
  12271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12272. {
  12273. check_ascii = value[0];
  12274. if( (check_ascii < 48) || (check_ascii > 57) )
  12275. {
  12276. isSuccess = ConfigurationStatus_Rejected;
  12277. }
  12278. else
  12279. {
  12280. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12281. isSuccess = ConfigurationStatus_Accepted;
  12282. }
  12283. }
  12284. else
  12285. {
  12286. isSuccess = ConfigurationStatus_Rejected;
  12287. }
  12288. }
  12289. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12290. {
  12291. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12292. {
  12293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12294. isSuccess = ConfigurationStatus_Accepted;
  12295. }
  12296. else
  12297. {
  12298. isSuccess = ConfigurationStatus_Rejected;
  12299. }
  12300. }
  12301. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12302. {
  12303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12304. {
  12305. check_ascii = value[0];
  12306. if( (check_ascii < 48) || (check_ascii > 57) )
  12307. {
  12308. isSuccess = ConfigurationStatus_Rejected;
  12309. }
  12310. else
  12311. {
  12312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12313. isSuccess = ConfigurationStatus_Accepted;
  12314. }
  12315. }
  12316. else
  12317. {
  12318. isSuccess = ConfigurationStatus_Rejected;
  12319. }
  12320. }
  12321. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12322. {
  12323. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12324. {
  12325. check_ascii = value[0];
  12326. if( (check_ascii < 48) || (check_ascii > 57) )
  12327. {
  12328. isSuccess = ConfigurationStatus_Rejected;
  12329. }
  12330. else
  12331. {
  12332. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12334. TransactionMessageAttemptsValue = atoi(value);
  12335. isSuccess = ConfigurationStatus_Accepted;
  12336. }
  12337. }
  12338. else
  12339. {
  12340. isSuccess = ConfigurationStatus_Rejected;
  12341. }
  12342. }
  12343. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12344. {
  12345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12346. {
  12347. check_ascii = value[0];
  12348. if( (check_ascii < 48) || (check_ascii > 57) )
  12349. {
  12350. isSuccess = ConfigurationStatus_Rejected;
  12351. }
  12352. else
  12353. {
  12354. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12356. TransactionMessageRetryIntervalValue = atoi(value);
  12357. isSuccess = ConfigurationStatus_Accepted;
  12358. }
  12359. }
  12360. else
  12361. {
  12362. isSuccess = ConfigurationStatus_Rejected;
  12363. }
  12364. }
  12365. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12366. {
  12367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12368. {
  12369. strcpy(str, (const char*)value);
  12370. for(int i = 0; str[i]; i++)
  12371. {
  12372. str[i] = tolower(str[i]);
  12373. }
  12374. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12376. isSuccess = ConfigurationStatus_Accepted;
  12377. }
  12378. else
  12379. {
  12380. isSuccess = ConfigurationStatus_Rejected;
  12381. }
  12382. }
  12383. if(strcmp(key, "WebSocketPingInterval") == 0)
  12384. {
  12385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12386. {
  12387. check_ascii = value[0];
  12388. if( (check_ascii < 48) || (check_ascii > 57) )
  12389. {
  12390. isSuccess = ConfigurationStatus_Rejected;
  12391. }
  12392. else
  12393. {
  12394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12395. isSuccess = ConfigurationStatus_Accepted;
  12396. }
  12397. }
  12398. else
  12399. {
  12400. isSuccess = ConfigurationStatus_Rejected;
  12401. }
  12402. }
  12403. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12404. {
  12405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12406. {
  12407. strcpy(str, (const char*)value);
  12408. for(int i = 0; str[i]; i++)
  12409. {
  12410. str[i] = tolower(str[i]);
  12411. }
  12412. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12414. isSuccess = ConfigurationStatus_Accepted;
  12415. }
  12416. else
  12417. {
  12418. isSuccess = ConfigurationStatus_Rejected;
  12419. }
  12420. }
  12421. if(strcmp(key, "AuthorizationKey") == 0)
  12422. {
  12423. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12424. {
  12425. strcpy(str, (const char*)value);
  12426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12427. isSuccess = ConfigurationStatus_Accepted;
  12428. }
  12429. else
  12430. {
  12431. isSuccess = ConfigurationStatus_Rejected;
  12432. }
  12433. }
  12434. if(strcmp(key, "SecurityProfile") == 0)
  12435. {
  12436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12437. {
  12438. check_ascii = value[0];
  12439. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12440. {
  12441. isSuccess = ConfigurationStatus_Rejected;
  12442. }
  12443. else if(check_ascii == 0x33)
  12444. {
  12445. isSuccess = NotSupported;
  12446. }
  12447. else
  12448. {
  12449. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12450. {
  12451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12452. isSuccess = ConfigurationStatus_Accepted;
  12453. }
  12454. else
  12455. isSuccess = ConfigurationStatus_Rejected;
  12456. }
  12457. }
  12458. else
  12459. {
  12460. isSuccess = ConfigurationStatus_Rejected;
  12461. }
  12462. }
  12463. if(strcmp(key, "DefaultPrice") == 0)
  12464. {
  12465. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12466. {
  12467. strcpy(str, (const char*)value);
  12468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12469. isSuccess = ConfigurationStatus_Accepted;
  12470. }
  12471. else
  12472. {
  12473. isSuccess = ConfigurationStatus_Rejected;
  12474. }
  12475. }
  12476. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12477. {
  12478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12479. {
  12480. strcpy(str, (const char*)value);
  12481. for(int i = 0; str[i]; i++)
  12482. {
  12483. str[i] = tolower(str[i]);
  12484. }
  12485. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12487. isSuccess = ConfigurationStatus_Accepted;
  12488. }
  12489. else
  12490. {
  12491. isSuccess = ConfigurationStatus_Rejected;
  12492. }
  12493. }
  12494. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12495. {
  12496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12497. {
  12498. strcpy(str, (const char*)value);
  12499. for(int i = 0; str[i]; i++)
  12500. {
  12501. str[i] = tolower(str[i]);
  12502. }
  12503. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12505. isSuccess = ConfigurationStatus_Accepted;
  12506. }
  12507. else
  12508. {
  12509. isSuccess = ConfigurationStatus_Rejected;
  12510. }
  12511. }
  12512. #if 0
  12513. //For OCPP Test Case
  12514. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12515. {
  12516. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12517. {
  12518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12519. isSuccess = ConfigurationStatus_Accepted;
  12520. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12521. }
  12522. else
  12523. {
  12524. isSuccess = ConfigurationStatus_Rejected;
  12525. }
  12526. }
  12527. #endif
  12528. #if 1
  12529. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12530. {
  12531. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12532. {
  12533. strcpy(str, (const char*)value);
  12534. for(int i = 0; str[i]; i++)
  12535. {
  12536. str[i] = tolower(str[i]);
  12537. }
  12538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12539. isSuccess = ConfigurationStatus_Accepted;
  12540. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12541. }
  12542. else
  12543. {
  12544. isSuccess = ConfigurationStatus_Rejected;
  12545. }
  12546. }
  12547. #endif
  12548. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12549. {
  12550. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12551. {
  12552. check_ascii = value[0];
  12553. if( (check_ascii < 48) || (check_ascii > 57) )
  12554. {
  12555. isSuccess = ConfigurationStatus_Rejected;
  12556. }
  12557. else
  12558. {
  12559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12560. isSuccess = ConfigurationStatus_Accepted;
  12561. }
  12562. }
  12563. else
  12564. {
  12565. isSuccess = ConfigurationStatus_Rejected;
  12566. }
  12567. }
  12568. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12569. {
  12570. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12571. {
  12572. check_ascii = value[0];
  12573. if( (check_ascii < 48) || (check_ascii > 57) )
  12574. {
  12575. isSuccess = ConfigurationStatus_Rejected;
  12576. }
  12577. else
  12578. {
  12579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12580. isSuccess = ConfigurationStatus_Accepted;
  12581. }
  12582. }
  12583. else
  12584. {
  12585. isSuccess = ConfigurationStatus_Rejected;
  12586. }
  12587. }
  12588. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12589. {
  12590. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12591. {
  12592. strcpy(str, (const char*)value);
  12593. for(int i = 0; str[i]; i++)
  12594. {
  12595. str[i] = tolower(str[i]);
  12596. }
  12597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12598. isSuccess = ConfigurationStatus_Accepted;
  12599. }
  12600. else
  12601. {
  12602. isSuccess = ConfigurationStatus_Rejected;
  12603. }
  12604. }
  12605. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12606. {
  12607. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12608. {
  12609. check_ascii = value[0];
  12610. if( (check_ascii < 48) || (check_ascii > 57) )
  12611. {
  12612. isSuccess = ConfigurationStatus_Rejected;
  12613. }
  12614. else
  12615. {
  12616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12617. isSuccess = ConfigurationStatus_Accepted;
  12618. }
  12619. }
  12620. else
  12621. {
  12622. isSuccess = ConfigurationStatus_Rejected;
  12623. }
  12624. }
  12625. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12626. {
  12627. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12628. {
  12629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12630. isSuccess = ConfigurationStatus_Accepted;
  12631. }
  12632. else
  12633. {
  12634. isSuccess = ConfigurationStatus_Rejected;
  12635. }
  12636. }
  12637. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12638. {
  12639. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12640. {
  12641. check_ascii = value[0];
  12642. if( (check_ascii < 48) || (check_ascii > 57) )
  12643. {
  12644. isSuccess = ConfigurationStatus_Rejected;
  12645. }
  12646. else
  12647. {
  12648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12649. isSuccess = ConfigurationStatus_Accepted;
  12650. }
  12651. }
  12652. else
  12653. {
  12654. isSuccess = ConfigurationStatus_Rejected;
  12655. }
  12656. }
  12657. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12658. {
  12659. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12660. {
  12661. strcpy(str, (const char*)value);
  12662. for(int i = 0; str[i]; i++)
  12663. {
  12664. str[i] = tolower(str[i]);
  12665. }
  12666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12667. isSuccess = ConfigurationStatus_Accepted;
  12668. }
  12669. else
  12670. {
  12671. isSuccess = ConfigurationStatus_Rejected;
  12672. }
  12673. }
  12674. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12675. {
  12676. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12677. {
  12678. check_ascii = value[0];
  12679. if( (check_ascii < 48) || (check_ascii > 57) )
  12680. {
  12681. isSuccess = ConfigurationStatus_Rejected;
  12682. }
  12683. else
  12684. {
  12685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12686. isSuccess = ConfigurationStatus_Accepted;
  12687. }
  12688. }
  12689. else
  12690. {
  12691. isSuccess = ConfigurationStatus_Rejected;
  12692. }
  12693. }
  12694. return isSuccess;
  12695. }
  12696. int TransactionMessageAttemptsGet(void)
  12697. {
  12698. return TransactionMessageAttemptsValue;
  12699. }
  12700. int FirstHeartBeatResponse(void)
  12701. {
  12702. return FirstHeartBeat;
  12703. }
  12704. int TransactionMessageRetryIntervalGet(void)
  12705. {
  12706. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12707. }
  12708. int ReadHttpStatus(int sock)
  12709. {
  12710. //char c;
  12711. char buff[1024]="",*ptr=buff+1;
  12712. int bytes_received, status;
  12713. DEBUG_INFO("Begin Response ..\n");
  12714. while((bytes_received = recv(sock, ptr, 1, 0))){
  12715. if(bytes_received==-1){
  12716. perror("ReadHttpStatus");
  12717. exit(1);
  12718. }
  12719. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12720. ptr++;
  12721. }
  12722. *ptr=0;
  12723. ptr=buff+1;
  12724. sscanf(ptr,"%*s %d ", &status);
  12725. DEBUG_INFO("%s\n",ptr);
  12726. DEBUG_INFO("status=%d\n",status);
  12727. DEBUG_INFO("End Response ..\n");
  12728. return (bytes_received>0)?status:0;
  12729. }
  12730. //the only filed that it parsed is 'Content-Length'
  12731. int ParseHeader(int sock)
  12732. {
  12733. //char c;
  12734. char buff[1024]="",*ptr=buff+4;
  12735. int bytes_received;
  12736. DEBUG_INFO("Begin HEADER ..\n");
  12737. while((bytes_received = recv(sock, ptr, 1, 0))){
  12738. if(bytes_received==-1){
  12739. perror("Parse Header");
  12740. exit(1);
  12741. }
  12742. if(
  12743. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12744. (ptr[-1]=='\r') && (*ptr=='\n' )
  12745. ) break;
  12746. ptr++;
  12747. }
  12748. *ptr=0;
  12749. ptr=buff+4;
  12750. //printf("%s",ptr);
  12751. if(bytes_received){
  12752. ptr=strstr(ptr,"Content-Length:");
  12753. if(ptr){
  12754. sscanf(ptr,"%*s %d",&bytes_received);
  12755. }else
  12756. bytes_received=-1; //unknown size
  12757. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12758. }
  12759. DEBUG_INFO("End HEADER ..\n");
  12760. return bytes_received ;
  12761. }
  12762. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12763. {
  12764. char rmFileCmd[100]={0};
  12765. char FilePath[100]={0};
  12766. char ftpbuf[200];
  12767. int systemresult;
  12768. //DEBUG_INFO("filename=%s\n",filename);
  12769. //DEBUG_INFO("url=%s\n",url);
  12770. sprintf(FilePath,"/mnt/%s",filename);
  12771. system("ping 8.8.8.8 &");
  12772. if((access(FilePath,F_OK))!=-1)
  12773. {
  12774. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12775. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12776. system(rmFileCmd);
  12777. }
  12778. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12779. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12780. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12781. systemresult = system(ftpbuf);
  12782. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12783. if(systemresult != 0)
  12784. {
  12785. DEBUG_INFO("http DownLoad error!\n");
  12786. return FALSE;
  12787. }
  12788. system("pkill ping");
  12789. return TRUE;
  12790. }
  12791. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12792. {
  12793. char rmFileCmd[100]={0};
  12794. char FilePath[100]={0};
  12795. char ftpbuf[200];
  12796. int systemresult;
  12797. //char temp[100];
  12798. sprintf(FilePath,"/mnt/%s",filename);
  12799. system("ping 8.8.8.8 &");
  12800. if((access(FilePath,F_OK))!=-1)
  12801. {
  12802. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12803. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12804. system(rmFileCmd);
  12805. }
  12806. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12807. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12808. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12809. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12810. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12811. systemresult = system(ftpbuf);
  12812. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12813. if(systemresult != 0)
  12814. {
  12815. printf("wget error!\n");
  12816. return FALSE;
  12817. }
  12818. system("pkill ping");
  12819. return TRUE;
  12820. }
  12821. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12822. {
  12823. char rmFileCmd[100]={0};
  12824. char FilePath[100]={0};
  12825. char ftpbuf[200];
  12826. int systemresult;
  12827. //DEBUG_INFO("filename=%s\n",filename);
  12828. //DEBUG_INFO("url=%s\n",url);
  12829. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12830. if((access(FilePath,F_OK))!=-1)
  12831. {
  12832. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12833. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12834. system(rmFileCmd);
  12835. }
  12836. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12837. if(fp == NULL)
  12838. {
  12839. DEBUG_INFO("log is NULL\n");
  12840. return FALSE;
  12841. }
  12842. else
  12843. {
  12844. fprintf(fp, "%s\n", url);
  12845. fprintf(fp, "%s\n", filename);
  12846. fclose(fp);
  12847. }
  12848. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12849. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12850. systemresult = system(ftpbuf);
  12851. DEBUG_INFO("systemresult = %d\n",systemresult);
  12852. if(systemresult != 0)
  12853. {
  12854. DEBUG_INFO("http upload error!\n");
  12855. return FALSE;
  12856. }
  12857. return TRUE;
  12858. }
  12859. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12860. {
  12861. struct hostent* server;
  12862. char *IPbuffer;
  12863. char ftpbuf[200];
  12864. int systemresult;
  12865. // To retrieve host information
  12866. server = gethostbyname(location);
  12867. // To convert an Internet network
  12868. // address into ASCII string
  12869. IPbuffer = inet_ntoa(*((struct in_addr*)
  12870. server->h_addr_list[0]));
  12871. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12872. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12873. /* format : ftpput -u username -p passwd IP target source*/
  12874. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12875. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12876. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12877. systemresult = system(ftpbuf);
  12878. DEBUG_INFO("systemresult=%d\n",systemresult);
  12879. if(systemresult != 0)
  12880. {
  12881. DEBUG_INFO("ftpput error!\n");
  12882. return FALSE;
  12883. }
  12884. return TRUE;
  12885. }
  12886. /**
  12887. * Place the contents of the specified file into a memory buffer
  12888. *
  12889. * @param[in] filename The path and name of the file to read
  12890. * @param[out] filebuffer A pointer to the contents in memory
  12891. * @return status 0 success, 1 on failure
  12892. */
  12893. int get_file_contents(const char* filename, char** outbuffer) {
  12894. FILE* file = NULL;
  12895. long filesize;
  12896. const int blocksize = 1;
  12897. size_t readsize;
  12898. char* filebuffer;
  12899. // Open the file
  12900. file = fopen(filename, "r");
  12901. if (NULL == file)
  12902. {
  12903. printf("'%s' not opened\n", filename);
  12904. exit(EXIT_FAILURE);
  12905. }
  12906. // Determine the file size
  12907. fseek(file, 0, SEEK_END);
  12908. filesize = ftell(file);
  12909. rewind (file);
  12910. // Allocate memory for the file contents
  12911. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12912. *outbuffer = filebuffer;
  12913. if (filebuffer == NULL)
  12914. {
  12915. fputs ("malloc out-of-memory", stderr);
  12916. exit(EXIT_FAILURE);
  12917. }
  12918. // Read in the file
  12919. readsize = fread(filebuffer, blocksize, filesize, file);
  12920. if (readsize != filesize)
  12921. {
  12922. fputs ("didn't read file completely",stderr);
  12923. exit(EXIT_FAILURE);
  12924. }
  12925. // Clean exit
  12926. fclose(file);
  12927. return EXIT_SUCCESS;
  12928. }
  12929. static int selectSqlCount = 0;
  12930. static int callback(void *data, int argc, char **argv, char **azColName){
  12931. int i;
  12932. //printf("%s: ", (const char*)data);
  12933. selectSqlCount = argc;
  12934. for(i = 0; i<argc; i++){
  12935. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12936. }
  12937. //printf("\n");
  12938. return 0;
  12939. }
  12940. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12941. //int i;
  12942. //printf("%s:\n", (const char*)data);
  12943. localversion = argv[5] ? atoi(argv[5]) : 0;
  12944. //printf("localversion=%d\n", localversion);
  12945. return 0;
  12946. }
  12947. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  12948. //printf("%s:\n", (const char*)data);
  12949. //idTag
  12950. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  12951. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  12952. //parentIdTag
  12953. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  12954. //expir_date
  12955. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  12956. //status
  12957. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  12958. //version
  12959. if(columenCount > 5)
  12960. idTagQuery.listVersionInt = atoi(columnValue[5]);
  12961. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12962. return 0;
  12963. }
  12964. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12965. {
  12966. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12967. // printf("localversion=%d\n", localversion);
  12968. return 0;
  12969. }
  12970. //=========================================
  12971. // Sqlite3 related function
  12972. //=========================================
  12973. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12974. {
  12975. for (int i = 0; i < n_columns; i++)
  12976. {
  12977. DEBUG_INFO("%s\t", col_values[i]);
  12978. }
  12979. DEBUG_INFO("\n");
  12980. return 0;
  12981. }
  12982. int OCPP_cleanLocalCache()
  12983. {
  12984. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  12985. char *errMsg = 0;
  12986. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12987. if (SQLITE_OK != rc)
  12988. {
  12989. DEBUG_INFO("SQL error: %s\n",errMsg);
  12990. return FALSE;
  12991. }
  12992. return TRUE;
  12993. }
  12994. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  12995. {
  12996. int isSuccess = TRUE;
  12997. int ret = 0;
  12998. //const char* data = "Callback function called";
  12999. char sql[300];
  13000. char zErrMsg[200];
  13001. memset(sql, 0, 300);
  13002. memset(zErrMsg, 0, 200);
  13003. 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);
  13004. //* Execute SQL statement */
  13005. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13006. if( ret != SQLITE_OK )
  13007. {
  13008. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13009. isSuccess = FALSE;
  13010. }
  13011. return isSuccess;
  13012. }
  13013. void OCPP_getIdTagFromLocalCache(char idTag[])
  13014. {
  13015. int rc = 0;
  13016. char sql[100];
  13017. char zErrMsg[100];
  13018. memset(sql, 0, 100);
  13019. memset(zErrMsg, 0, 100);
  13020. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13021. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13022. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  13023. /* Execute SQL statement */
  13024. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13025. if( rc != SQLITE_OK )
  13026. {
  13027. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13028. }
  13029. }
  13030. void OCPP_getListVerion()
  13031. {
  13032. int rc = 0;
  13033. // const char* data = "Callback function called";
  13034. char sql[100];
  13035. char zErrMsg[100];
  13036. memset(sql, 0, 100);
  13037. memset(zErrMsg, 0, 100);
  13038. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13039. /* Execute SQL statement */
  13040. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13041. if( rc != SQLITE_OK )
  13042. {
  13043. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13044. }
  13045. }
  13046. void OCPP_get_TableAuthlocalAllData(void)
  13047. {
  13048. int rc = 0;
  13049. char sql[100];
  13050. char zErrMsg[100];
  13051. memset(sql, 0, 100);
  13052. memset(zErrMsg, 0, 100);
  13053. sprintf(sql,"select * from ocpp_auth_local ");
  13054. /* Execute SQL statement */
  13055. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13056. if( rc != SQLITE_OK )
  13057. {
  13058. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13059. }
  13060. //return ver;
  13061. }
  13062. int OCPP_cleanLocalList()
  13063. {
  13064. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13065. char *errMsg = 0;
  13066. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13067. if (SQLITE_OK != rc)
  13068. {
  13069. DEBUG_INFO("%s\n",errMsg);
  13070. return FALSE;
  13071. }
  13072. return TRUE;
  13073. }
  13074. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13075. {
  13076. int isSuccess = FALSE;
  13077. int ret = 0;
  13078. //const char* data = "Callback function called";
  13079. char sql[300];
  13080. char zErrMsg[200];
  13081. memset(sql, 0, 300);
  13082. memset(zErrMsg, 0, 200);
  13083. 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);
  13084. //* Execute SQL statement */
  13085. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13086. if( ret != SQLITE_OK )
  13087. {
  13088. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13089. return isSuccess;
  13090. }
  13091. memset(sql, 0, 300);
  13092. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13093. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13094. if( ret != SQLITE_OK )
  13095. {
  13096. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13097. return isSuccess;
  13098. }
  13099. isSuccess = TRUE;
  13100. return isSuccess;
  13101. }
  13102. void OCPP_getIdTagFromLocalList(char idTag[])
  13103. {
  13104. int rc = 0;
  13105. // const char* data = "Callback function called";
  13106. char sql[100];
  13107. char zErrMsg[100];
  13108. memset(sql, 0, 100);
  13109. memset(zErrMsg, 0, 100);
  13110. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13111. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13112. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13113. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13114. /* Execute SQL statement */
  13115. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13116. if( rc != SQLITE_OK )
  13117. {
  13118. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13119. }
  13120. //return ver;
  13121. }
  13122. void OCPP_deleteIdTagFromLocalList(char idTag[])
  13123. {
  13124. //int ver = 0;
  13125. //int isSuccess = FALSE;
  13126. int rc = 0;
  13127. char sql[100];
  13128. char zErrMsg[100];
  13129. memset(sql, 0, 100);
  13130. memset(zErrMsg, 0, 100);
  13131. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13132. //* Execute SQL statement */
  13133. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13134. if( rc != SQLITE_OK )
  13135. {
  13136. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13137. }
  13138. }
  13139. int GetOcppServerURL()
  13140. {
  13141. int result = FALSE;
  13142. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13143. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13144. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13145. struct yuarel url;
  13146. char urlStr[512];
  13147. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13148. {
  13149. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13150. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13151. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13152. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13153. if(yuarel_parse(&url, urlStr) != -1)
  13154. {
  13155. sprintf(OcppProtocol, "%s", url.scheme);
  13156. sprintf(OcppHost, "%s", url.host);
  13157. if(url.path == NULL)
  13158. OcppTempPath[0] = '\0';
  13159. else
  13160. {
  13161. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13162. {
  13163. sprintf(OcppTempPath, "%s/", url.path);
  13164. }
  13165. else
  13166. {
  13167. sprintf(OcppTempPath, "%s", url.path);
  13168. }
  13169. }
  13170. if(url.port == 0)
  13171. {
  13172. if(strcmp(OcppProtocol, "wss") == 0)
  13173. OcppPort = 443;
  13174. else
  13175. OcppPort = 80;
  13176. }
  13177. else
  13178. OcppPort = url.port;
  13179. result = TRUE;
  13180. }
  13181. }
  13182. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13183. {
  13184. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13185. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13186. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13187. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13188. if(yuarel_parse(&url, urlStr) != -1)
  13189. {
  13190. sprintf(OcppProtocol, "%s", url.scheme);
  13191. sprintf(OcppHost, "%s", url.host);
  13192. if(url.path == NULL)
  13193. OcppTempPath[0] = '\0';
  13194. else
  13195. sprintf(OcppTempPath, "%s", url.path);
  13196. if(url.port == 0)
  13197. {
  13198. if(strcmp(OcppProtocol, "wss") == 0)
  13199. OcppPort = 443;
  13200. else
  13201. OcppPort = 80;
  13202. }
  13203. else
  13204. OcppPort = url.port;
  13205. result = TRUE;
  13206. }
  13207. }
  13208. else
  13209. {
  13210. strcpy(OcppHost,"");
  13211. }
  13212. return result;
  13213. }
  13214. int GetOcppPath()
  13215. {
  13216. int result = FALSE;
  13217. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13218. {
  13219. if(OcppTempPath == NULL)
  13220. {
  13221. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13222. }
  13223. else
  13224. {
  13225. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13226. }
  13227. result = TRUE;
  13228. goto End;
  13229. }
  13230. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13231. {
  13232. if(OcppTempPath == NULL)
  13233. {
  13234. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13235. }
  13236. else
  13237. {
  13238. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13239. }
  13240. result = TRUE;
  13241. goto End;
  13242. }
  13243. else
  13244. {
  13245. strcpy(OcppPath,"");
  13246. }
  13247. End:
  13248. return result;
  13249. }
  13250. int GetOcppPort()
  13251. {
  13252. return OcppPort;
  13253. }
  13254. int GetOcppConnStatus(void)
  13255. {
  13256. return ShmOCPP16Data->OcppConnStatus;
  13257. }
  13258. void SetOcppConnStatus(uint8_t status)
  13259. {
  13260. ShmOCPP16Data->OcppConnStatus = status;
  13261. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13262. }
  13263. int GetHeartBeatWithNOResponse(void)
  13264. {
  13265. return HeartBeatWithNOResponse;
  13266. }
  13267. void SetHeartBeatWithNOResponse(void)
  13268. {
  13269. HeartBeatWithNOResponse = 0;
  13270. }
  13271. void GetStartTransactionIdTag(int gun_index)
  13272. {
  13273. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13274. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13275. }
  13276. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13277. {
  13278. char ch;
  13279. FILE *fptr1;
  13280. int temptransactionId;
  13281. char str[100]={0};
  13282. temptransactionId = 0;
  13283. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  13284. {
  13285. DEBUG_INFO("IdTag is empty.\n");
  13286. return temptransactionId;
  13287. }
  13288. /*------ Read the file ----------------*/
  13289. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13290. if (!fptr1)
  13291. {
  13292. DEBUG_INFO("QueueTransactionId file open error.\n");
  13293. //printf(" File not found or unable to open the input file!!\n");
  13294. return temptransactionId;
  13295. }
  13296. ch=fgetc(fptr1);
  13297. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13298. rewind(fptr1);
  13299. if(ch!=EOF)
  13300. {
  13301. // printf("%c",ch);
  13302. while (fgets(str, 100, fptr1) != NULL)
  13303. {
  13304. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13305. if(str[0]=='\0')
  13306. {
  13307. break;
  13308. }
  13309. char *revbuf[8] = {0}; // Variable store string split
  13310. int num = 0;// Quantity after string split
  13311. DEBUG_INFO("Transaction queue data= %s\n", str);
  13312. splitstring(str,",",revbuf,&num); // String split
  13313. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13314. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13315. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13316. DEBUG_INFO("------------------------------\n");
  13317. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13318. {
  13319. if(isStopTransaction)
  13320. {
  13321. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13322. {
  13323. temptransactionId = atoi(revbuf[2]);
  13324. break;
  13325. }
  13326. }
  13327. else
  13328. {
  13329. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13330. {
  13331. temptransactionId = atoi(revbuf[2]);
  13332. break;
  13333. }
  13334. }
  13335. }
  13336. }
  13337. }
  13338. else
  13339. DEBUG_INFO("EOF\n");
  13340. fclose(fptr1);
  13341. /*------- End of reading ---------------*/
  13342. return temptransactionId;
  13343. }
  13344. void SetTransactionIdZero(int transactionId)
  13345. {
  13346. char ch;
  13347. FILE *fptr1, *fptr2;
  13348. int temptransactionId = 0;
  13349. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13350. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13351. if (!fptr1)
  13352. {
  13353. //printf(" File not found or unable to open the input file!!\n");
  13354. return ;
  13355. }
  13356. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13357. if (!fptr2)
  13358. {
  13359. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13360. fclose(fptr1);
  13361. return ;
  13362. }
  13363. ch=fgetc(fptr1);
  13364. rewind(fptr1);
  13365. if(ch!=EOF)
  13366. {
  13367. // copy all contents to the temporary file except the specific line
  13368. while (fgets(str, 100, fptr1) != NULL)
  13369. {
  13370. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13371. if(str[0]=='\0')
  13372. {
  13373. break;
  13374. }
  13375. char *revbuf[8] = {0};
  13376. int num = 0;
  13377. strcpy(strtemp, str);
  13378. splitstring(str,",",revbuf,&num);
  13379. if(revbuf[2][0] != '\0')
  13380. {
  13381. temptransactionId = atoi(revbuf[2]);
  13382. if(transactionId != temptransactionId)
  13383. {
  13384. fprintf(fptr2, "%s\n", strtemp);
  13385. }
  13386. }
  13387. }
  13388. }
  13389. fclose(fptr1);
  13390. fclose(fptr2);
  13391. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13392. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13393. /*------ Read the file ----------------*/
  13394. }
  13395. int InternetDisconnect(void)
  13396. {
  13397. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13398. }
  13399. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13400. void storeTempStopTransaction(int gun_index)
  13401. {
  13402. char guid[37]={0};
  13403. int tempIndex = 0;
  13404. char TempStopTransaction[256];
  13405. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13406. DEBUG_INFO("storeTempStopTransaction...\n");
  13407. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13408. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13409. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13410. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13411. if(gunType[gun_index] == 'J')
  13412. {
  13413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13414. {
  13415. tempIndex = ((gun_index==2) ? 1: 0);
  13416. }
  13417. else
  13418. {
  13419. tempIndex = gun_index;
  13420. }
  13421. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13422. {
  13423. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13424. {
  13425. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13426. }
  13427. }// END OF CHAdeMO_QUANTITY
  13428. }
  13429. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13430. {
  13431. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13432. {
  13433. tempIndex = ((gun_index==2) ? 1: 0);
  13434. }
  13435. else
  13436. {
  13437. tempIndex = gun_index;
  13438. }
  13439. for (int index = 0; index < CCS_QUANTITY; index++)
  13440. {
  13441. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13442. {
  13443. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13444. }
  13445. }// END OF CCS_QUANTITY
  13446. }
  13447. else if(gunType[gun_index] == 'G')
  13448. {
  13449. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13450. {
  13451. tempIndex = ((gun_index==2) ? 1: 0);
  13452. }
  13453. else
  13454. {
  13455. tempIndex = gun_index;
  13456. }
  13457. for (int index = 0; index < GB_QUANTITY; index++)
  13458. {
  13459. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13460. {
  13461. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13462. }
  13463. }// END OF GB_QUANTITY
  13464. }
  13465. else if(gunType[gun_index] == 'O')
  13466. {
  13467. tempIndex = gun_index;
  13468. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13469. {
  13470. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13471. {
  13472. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13473. }
  13474. }
  13475. }
  13476. else
  13477. {
  13478. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13479. {
  13480. tempIndex = 2;
  13481. }
  13482. else
  13483. {
  13484. tempIndex = gun_index;
  13485. }
  13486. for (int index = 0; index < AC_QUANTITY; index++)
  13487. {
  13488. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13489. {
  13490. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13491. }
  13492. }// END OF AC_QUANTITY
  13493. }
  13494. //Stop Transaction Time
  13495. struct timeval tmnow;
  13496. struct tm *tm;
  13497. char buf[28];//, usec_buf[6];
  13498. gettimeofday(&tmnow, NULL);
  13499. time_t t;
  13500. t = time(NULL);
  13501. /*UTC time and date*/
  13502. tm = gmtime(&t);
  13503. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13505. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13507. random_uuid(guid);
  13508. /***********************************transactionData******************************************************/
  13509. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13511. //=================================
  13512. //1. Transaction_Begin
  13513. //=================================
  13514. //============================== Energy.Active.Import.Interval ===========================================
  13515. //idx_sample=0;
  13516. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13519. 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*/]);
  13520. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13521. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13522. {
  13523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13524. }
  13525. else
  13526. {
  13527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13528. }
  13529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13531. //=================================
  13532. //2. Transaction_End
  13533. //=================================
  13534. //2.1====================================== Current.Import L1 ==============================================
  13535. //idx_sample=1;
  13536. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13537. if(gunType[gun_index] == 'J')
  13538. {
  13539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13540. {
  13541. tempIndex = ((gun_index==2) ? 1: 0);
  13542. }
  13543. else
  13544. {
  13545. tempIndex = gun_index;
  13546. }
  13547. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13548. {
  13549. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13550. {
  13551. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13552. }
  13553. }// End of for CHAdeMO_QUANTITY
  13554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13555. }
  13556. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13557. {
  13558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13559. {
  13560. tempIndex = ((gun_index==2) ? 1: 0);
  13561. }
  13562. else
  13563. {
  13564. tempIndex = gun_index;
  13565. }
  13566. for (int index = 0; index < CCS_QUANTITY; index++)
  13567. {
  13568. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13569. {
  13570. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13571. }
  13572. }// End of for CCS_QUANTITY
  13573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13574. }
  13575. else if(gunType[gun_index] == 'G')
  13576. {
  13577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13578. {
  13579. tempIndex = ((gun_index==2) ? 1: 0);
  13580. }
  13581. else
  13582. {
  13583. tempIndex = gun_index;
  13584. }
  13585. for (int index = 0; index < GB_QUANTITY; index++)
  13586. {
  13587. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13588. {
  13589. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13590. }
  13591. }// End of for GB_QUANTITY
  13592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13593. }
  13594. else if(gunType[gun_index] == 'O')
  13595. {
  13596. tempIndex = gun_index;
  13597. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13598. {
  13599. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13600. {
  13601. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13602. }
  13603. }
  13604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13605. }
  13606. else
  13607. {
  13608. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13609. {
  13610. tempIndex = 2;
  13611. }
  13612. else
  13613. {
  13614. tempIndex = gun_index;
  13615. }
  13616. for (int index = 0; index < AC_QUANTITY; index++)
  13617. {
  13618. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13619. {
  13620. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13621. }
  13622. }// End of for AC_QUANTITY
  13623. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13624. }
  13625. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13626. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13628. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13631. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13632. //idx_sample=2;
  13633. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13634. if(gunType[gun_index] == 'J')
  13635. {
  13636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13637. {
  13638. tempIndex = ((gun_index==2) ? 1: 0);
  13639. }
  13640. else
  13641. {
  13642. tempIndex = gun_index;
  13643. }
  13644. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13645. {
  13646. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13647. {
  13648. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13649. }
  13650. }// END OF CHAdeMO_QUANTITY
  13651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13652. }
  13653. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13654. {
  13655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13656. {
  13657. tempIndex = ((gun_index==2) ? 1: 0);
  13658. }
  13659. else
  13660. {
  13661. tempIndex = gun_index;
  13662. }
  13663. for (int index = 0; index < CCS_QUANTITY; index++)
  13664. {
  13665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13666. {
  13667. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13668. }
  13669. }// END OF CCS_QUANTITY
  13670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13671. }
  13672. else if(gunType[gun_index] == 'G')
  13673. {
  13674. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13675. {
  13676. tempIndex = ((gun_index==2) ? 1: 0);
  13677. }
  13678. else
  13679. {
  13680. tempIndex = gun_index;
  13681. }
  13682. for (int index = 0; index < GB_QUANTITY; index++)
  13683. {
  13684. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13685. {
  13686. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13687. }
  13688. }// END OF GB_QUANTITY
  13689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13690. }
  13691. else if(gunType[gun_index] == 'O')
  13692. {
  13693. tempIndex = gun_index;
  13694. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13695. {
  13696. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13697. {
  13698. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13699. }
  13700. }
  13701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13702. }
  13703. else
  13704. {
  13705. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13706. {
  13707. tempIndex = 2;
  13708. }
  13709. else
  13710. {
  13711. tempIndex = gun_index;
  13712. }
  13713. for (int index = 0; index < AC_QUANTITY; index++)
  13714. {
  13715. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13716. {
  13717. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13718. }
  13719. }// END OF AC_QUANTITY
  13720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13721. }
  13722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13725. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13728. //2.3====================================== Power.Active.Import =========================================
  13729. //idx_sample=3;
  13730. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13731. if(gunType[gun_index] == 'J')
  13732. {
  13733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13734. {
  13735. tempIndex = ((gun_index==2) ? 1: 0);
  13736. }
  13737. else
  13738. {
  13739. tempIndex = gun_index;
  13740. }
  13741. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13742. {
  13743. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13744. {
  13745. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13746. }
  13747. } // End for CHAdeMO_QUANTITY
  13748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13749. }
  13750. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13751. {
  13752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13753. {
  13754. tempIndex = ((gun_index==2) ? 1: 0);
  13755. }
  13756. else
  13757. {
  13758. tempIndex = gun_index;
  13759. }
  13760. for (int index = 0; index < CCS_QUANTITY; index++)
  13761. {
  13762. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13763. {
  13764. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13765. }
  13766. } // END for CCS_QUANTITY
  13767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13768. }
  13769. else if(gunType[gun_index] == 'G')
  13770. {
  13771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13772. {
  13773. tempIndex = ((gun_index==2) ? 1: 0);
  13774. }
  13775. else
  13776. {
  13777. tempIndex = gun_index;
  13778. }
  13779. for (int index = 0; index < GB_QUANTITY; index++)
  13780. {
  13781. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13782. {
  13783. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13784. }
  13785. }// END for GB_QUANTITY
  13786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13787. }
  13788. else if(gunType[gun_index] == 'O')
  13789. {
  13790. tempIndex = gun_index;
  13791. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13792. {
  13793. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13794. {
  13795. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13796. }
  13797. }
  13798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13799. }
  13800. else
  13801. {
  13802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13803. {
  13804. tempIndex = 2;
  13805. }
  13806. else
  13807. {
  13808. tempIndex = gun_index;
  13809. }
  13810. for (int index = 0; index < AC_QUANTITY; index++)
  13811. {
  13812. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13813. {
  13814. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13815. }
  13816. } // END for AC_QUANTITY
  13817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13818. }
  13819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13822. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13823. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13825. //2.4====================================== Voltage L1 ====================================================
  13826. //idx_sample=4;
  13827. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13828. if(gunType[gun_index] == 'J')
  13829. {
  13830. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13831. {
  13832. tempIndex = ((gun_index==2) ? 1: 0);
  13833. }
  13834. else
  13835. {
  13836. tempIndex = gun_index;
  13837. }
  13838. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13839. {
  13840. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13841. {
  13842. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13843. }
  13844. } // END OF FOR CHAdeMO_QUANTITY
  13845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13846. }
  13847. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13848. {
  13849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13850. {
  13851. tempIndex = ((gun_index==2) ? 1: 0);
  13852. }
  13853. else
  13854. {
  13855. tempIndex = gun_index;
  13856. }
  13857. for (int index = 0; index < CCS_QUANTITY; index++)
  13858. {
  13859. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13860. {
  13861. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13862. }
  13863. } // END OF FOR CCS_QUANTITY
  13864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13865. }
  13866. else if(gunType[gun_index] == 'G')
  13867. {
  13868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13869. {
  13870. tempIndex = ((gun_index==2) ? 1: 0);
  13871. }
  13872. else
  13873. {
  13874. tempIndex = gun_index;
  13875. }
  13876. for (int index = 0; index < GB_QUANTITY; index++)
  13877. {
  13878. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13879. {
  13880. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13881. }
  13882. } // END OF FOR GB_QUANTITY
  13883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13884. }
  13885. else if(gunType[gun_index] == 'O')
  13886. {
  13887. tempIndex = gun_index;
  13888. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13889. {
  13890. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13891. {
  13892. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13893. }
  13894. }
  13895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13896. }
  13897. else
  13898. {
  13899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13900. {
  13901. tempIndex = 2;
  13902. }
  13903. else
  13904. {
  13905. tempIndex = gun_index;
  13906. }
  13907. for (int index = 0; index < AC_QUANTITY; index++)
  13908. {
  13909. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13910. {
  13911. 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
  13912. }
  13913. } // END OF FOR AC_QUANTITY
  13914. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13915. }
  13916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13918. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13919. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13922. //2.5============================================== End SoC =========================================================
  13923. //idx_sample=5;
  13924. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13925. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  13926. {
  13927. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  13928. {
  13929. tempIndex = ((gun_index==2) ? 1: 0);
  13930. }
  13931. else
  13932. {
  13933. tempIndex = gun_index;
  13934. }
  13935. if(gunType[gun_index] == 'J')
  13936. {
  13937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13938. {
  13939. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13940. {
  13941. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13942. }
  13943. }
  13944. }
  13945. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13946. {
  13947. for (int index = 0; index < CCS_QUANTITY; index++)
  13948. {
  13949. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13950. {
  13951. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13952. }
  13953. }
  13954. }
  13955. else if(gunType[gun_index] == 'G')
  13956. {
  13957. for (int index = 0; index < GB_QUANTITY; index++)
  13958. {
  13959. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13960. {
  13961. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13962. }
  13963. }
  13964. }
  13965. else if(gunType[gun_index] == 'O')
  13966. {
  13967. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13968. {
  13969. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13970. {
  13971. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  13972. }
  13973. }
  13974. }
  13975. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13976. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  13980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13981. } // END FOR DC CASE
  13982. //2.6====================================== Current.Import L2 ==============================================
  13983. // idx_sample=6;
  13984. // AC 3 phase L2 current
  13985. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13986. {
  13987. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13988. {
  13989. tempIndex = 2;
  13990. }
  13991. else
  13992. {
  13993. tempIndex = gun_index;
  13994. }
  13995. for (int index = 0; index < AC_QUANTITY; index++)
  13996. {
  13997. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13998. {
  13999. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14000. }
  14001. }// End of for AC_QUANTITY
  14002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14003. }
  14004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14009. //2.7====================================== Current.Import L3 ==============================================
  14010. // idx_sample=7;
  14011. // AC 3 phase L3 current
  14012. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14013. {
  14014. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14015. {
  14016. tempIndex = 2;
  14017. }
  14018. else
  14019. {
  14020. tempIndex = gun_index;
  14021. }
  14022. for (int index = 0; index < AC_QUANTITY; index++)
  14023. {
  14024. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14025. {
  14026. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14027. }
  14028. }// End of for AC_QUANTITY
  14029. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14030. }
  14031. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14032. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14036. //2.9====================================== Voltage L2 ====================================================
  14037. //idx_sample=8;
  14038. // AC 3 phase L2 volatge
  14039. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14040. {
  14041. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14042. {
  14043. tempIndex = 2;
  14044. }
  14045. else
  14046. {
  14047. tempIndex = gun_index;
  14048. }
  14049. for (int index = 0; index < AC_QUANTITY; index++)
  14050. {
  14051. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14052. {
  14053. 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
  14054. }
  14055. } // END OF FOR AC_QUANTITY
  14056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14057. }
  14058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14063. //2.10====================================== Voltage L3 ====================================================
  14064. //idx_sample=9;
  14065. // AC 3 phase L3 volatge
  14066. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14067. {
  14068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14069. {
  14070. tempIndex = 2;
  14071. }
  14072. else
  14073. {
  14074. tempIndex = gun_index;
  14075. }
  14076. for (int index = 0; index < AC_QUANTITY; index++)
  14077. {
  14078. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14079. {
  14080. 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
  14081. }
  14082. } // END OF FOR AC_QUANTITY
  14083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14084. }
  14085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14090. //====================== Start SoC ================================
  14091. //idx_sample=10;
  14092. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14093. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  14094. {
  14095. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  14096. {
  14097. tempIndex = ((gun_index==2) ? 1: 0);
  14098. }
  14099. else
  14100. {
  14101. tempIndex = gun_index;
  14102. }
  14103. if(gunType[gun_index] == 'J')
  14104. {
  14105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14106. {
  14107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14108. {
  14109. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14110. }
  14111. }
  14112. }
  14113. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  14114. {
  14115. for (int index = 0; index < CCS_QUANTITY; index++)
  14116. {
  14117. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14118. {
  14119. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14120. }
  14121. }
  14122. }
  14123. else if(gunType[gun_index] == 'G')
  14124. {
  14125. for (int index = 0; index < GB_QUANTITY; index++)
  14126. {
  14127. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14128. {
  14129. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14130. }
  14131. }
  14132. }
  14133. else if(gunType[gun_index] == 'O')
  14134. {
  14135. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14136. {
  14137. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14138. {
  14139. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14140. }
  14141. }
  14142. }
  14143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14149. } // END FOR DC CASE
  14150. //======================================== Message create ==============================================
  14151. json_object *StopTransaction = json_object_new_object();
  14152. json_object *transactionDatas = json_object_new_array();
  14153. json_object *sampledValues = json_object_new_array();
  14154. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14155. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14156. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14157. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14158. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14159. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  14160. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14161. {
  14162. json_object *transactionData = json_object_new_object();
  14163. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14164. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14165. {
  14166. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14167. {
  14168. json_object *sampledValue = json_object_new_object();
  14169. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14170. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14171. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14172. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14173. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14174. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14175. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14176. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14177. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14178. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14179. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14180. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14181. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14182. json_object_array_add(sampledValues, sampledValue);
  14183. }
  14184. }
  14185. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14186. json_object_array_add(transactionDatas, transactionData);
  14187. }
  14188. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14189. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14190. ,MESSAGE_TYPE_CALL
  14191. ,guid
  14192. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14193. json_object_put(StopTransaction);
  14194. // Check File "TempStopTransaction" Exist
  14195. if((access(TempStopTransaction,F_OK))!=-1)
  14196. {
  14197. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14198. fclose(fopen(TempStopTransaction, "w"));
  14199. }
  14200. else
  14201. {
  14202. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14203. FILE *log = fopen(TempStopTransaction, "w+");
  14204. if(log == NULL)
  14205. {
  14206. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14207. return ;
  14208. }
  14209. else
  14210. {
  14211. fclose(log);
  14212. }
  14213. }
  14214. //Add TempStopTransaction | Update TempStopTransaction
  14215. // open file for writing
  14216. FILE *outfile;
  14217. outfile = fopen (TempStopTransaction, "a");
  14218. //DEBUG_INFO("data = %s\n", queuedata);
  14219. fputs(queuedata, outfile);
  14220. fputs("\n", outfile);
  14221. fclose (outfile);
  14222. }
  14223. void checkTempStopTransaction(int gun_index)
  14224. {
  14225. FILE *fptr1;
  14226. char ch;
  14227. char str[QUEUE_MESSAGE_LENGTH]={0};
  14228. char guid[37]={0};
  14229. char tempdata[65]={0};
  14230. char connectorStr[2]={0};
  14231. char TempStopTransaction[256];
  14232. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14233. fptr1 = fopen(TempStopTransaction, "r");
  14234. //TempStopTransaction格式: 槍號,StopTransaction封包
  14235. if (!fptr1)
  14236. {
  14237. //printf(" File not found or unable to open the input file!!\n");
  14238. return ;
  14239. }
  14240. ch=fgetc(fptr1);
  14241. //printf(" Now the content of the file %s is : \n",fname);
  14242. rewind(fptr1);
  14243. if(ch!=EOF)
  14244. {
  14245. // copy all contents to the temporary file except the specific line
  14246. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14247. {
  14248. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14249. if(str[0]=='\0')
  14250. {
  14251. break;
  14252. }
  14253. //TempStopTransaction格式: 槍號,StopTransaction封包
  14254. strncpy(connectorStr, str, 1);
  14255. if(atoi(connectorStr) != (gun_index+1))
  14256. {
  14257. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14258. fclose(fptr1);
  14259. return ;
  14260. }
  14261. //random_uuid(guid);
  14262. strncpy(guid, str+6, 36); //copy guid
  14263. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14264. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14265. {
  14266. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14267. }
  14268. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14269. memset(str,0,ARRAY_SIZE(str));
  14270. }
  14271. }
  14272. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14273. fclose(fptr1);
  14274. remove(TempStopTransaction); // remove the original file
  14275. }
  14276. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14277. {
  14278. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14279. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14280. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14281. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14282. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14283. }
  14284. int GetWebSocketPingInterval(void)
  14285. {
  14286. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14287. }
  14288. int GetServerSign(void)
  14289. {
  14290. return server_sign;
  14291. }
  14292. uint8_t GetOcppSecurityProfile()
  14293. {
  14294. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14295. }
  14296. void GetOcppChargerBoxId(uint8_t *data)
  14297. {
  14298. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14299. }
  14300. void GetOcppSecurityPassword(uint8_t *data)
  14301. {
  14302. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14303. }
  14304. void SetOcppVersion(uint8_t *version)
  14305. {
  14306. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  14307. DEBUG_INFO("ocpp version: %s\n", version);
  14308. if(strstr((char*)version, "ocpp1.6") != NULL)
  14309. {
  14310. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  14311. }
  14312. else if(strstr((char*)version, "ocpp2.0") != NULL)
  14313. {
  14314. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  14315. system("pkill OcppBackend");
  14316. }
  14317. }
  14318. void SetServerSign(int value)
  14319. {
  14320. server_sign = value;
  14321. }
  14322. int GetBootNotificationInterval(void)
  14323. {
  14324. return BootNotificationInterval;
  14325. }
  14326. int GetInternetConn(void)
  14327. {
  14328. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14329. }
  14330. void InitialSystemValue(void)
  14331. {
  14332. int connectorIndex = 0;
  14333. //int valueASCII = 0;
  14334. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14335. gunTotalNumber=0;
  14336. SystemInitial = 0;
  14337. localversion=0;
  14338. BootNotificationInterval = 0;
  14339. authorizeRetryTimes = 0;
  14340. GunStatusInterval = 10;
  14341. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14342. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14343. //Hear Beat
  14344. HeartBeatWithNOResponse = 0;
  14345. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14346. FirstHeartBeat = 0;
  14347. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14348. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14349. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14350. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14351. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14352. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14353. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14354. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14355. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14356. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14357. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14358. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14359. memset(gunType, 0, ARRAY_SIZE(gunType));
  14360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14361. {
  14362. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14363. {
  14364. // DO series
  14365. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14366. {
  14367. SystemInitial = SystemInitial + 1;
  14368. gunTotalNumber = gunTotalNumber + 1;
  14369. gunType[connectorIndex] = 'O';
  14370. connectorIndex = connectorIndex + 1;
  14371. }
  14372. }
  14373. else
  14374. {
  14375. // DM, DW, DS series
  14376. //check connector / socket type (index: 8, 9, 10)
  14377. for(int index=7; index <10 ; index++)
  14378. {
  14379. if(index != 8)
  14380. {
  14381. // DC Connector
  14382. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14383. {
  14384. SystemInitial = SystemInitial + 1;
  14385. gunTotalNumber = gunTotalNumber + 1;
  14386. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14387. connectorIndex = connectorIndex + 1;
  14388. }
  14389. }
  14390. else
  14391. {
  14392. // AC Connector
  14393. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14394. {
  14395. SystemInitial = SystemInitial + 1;
  14396. gunTotalNumber = gunTotalNumber + 1;
  14397. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14398. connectorIndex = connectorIndex + 1;
  14399. }
  14400. }
  14401. }
  14402. }
  14403. //DEBUG_INFO("DC ...\n");
  14404. }
  14405. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14406. {
  14407. //check connector / socket type (index: 8, 9, 10)
  14408. for(int index=7; index <10 ; index++)
  14409. {
  14410. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14411. {
  14412. SystemInitial = SystemInitial + 1;
  14413. gunTotalNumber = gunTotalNumber + 1;
  14414. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14415. connectorIndex = connectorIndex + 1;
  14416. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14417. }
  14418. }
  14419. }
  14420. //Status && ConnectorPlugIn Setting
  14421. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14422. {
  14423. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14424. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14425. }
  14426. for (int index = 0; index < CCS_QUANTITY; index++)
  14427. {
  14428. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14429. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14430. }
  14431. for (int index = 0; index < GB_QUANTITY; index++)
  14432. {
  14433. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14434. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14435. }
  14436. for (int index = 0; index < AC_QUANTITY; index++)
  14437. {
  14438. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14439. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14440. }
  14441. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14442. {
  14443. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14444. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14445. }
  14446. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14447. {
  14448. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14449. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14450. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14451. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14452. }
  14453. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14454. clientTime.Heartbeat=time((time_t*)NULL);
  14455. sleep(1);
  14456. }
  14457. void LWS_Send(char * str)
  14458. {
  14459. //=====================================================
  14460. // Check InternetConn 0: disconnected, 1: connected
  14461. //====================================================
  14462. if(GetOcppConnStatus() == 0)
  14463. {
  14464. DEBUG_INFO("offline now !!!\n");
  14465. return;
  14466. }
  14467. pthread_mutex_lock(&lock_send);
  14468. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14469. sprintf((char *)SendBuffer, "%s", str);
  14470. SendBufLen = strlen(str);
  14471. pthread_mutex_unlock(&lock_send);
  14472. lws_callback_on_writable(wsi_client);
  14473. //lws_service(context, 0);
  14474. //sleep(1);
  14475. }
  14476. void LWS_SendNow(char * str)
  14477. {
  14478. //=====================================================
  14479. // Check InternetConn 0: disconnected, 1: connected
  14480. //====================================================
  14481. if(GetOcppConnStatus() == 0)
  14482. {
  14483. DEBUG_INFO("offline now !!!\n");
  14484. return;
  14485. }
  14486. pthread_mutex_lock(&lock_send);
  14487. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14488. sprintf((char *)SendBuffer, "%s", str);
  14489. SendBufLen = strlen(str);
  14490. pthread_mutex_unlock(&lock_send);
  14491. lws_callback_on_writable(wsi_client);
  14492. lws_service(context, 0);
  14493. //sleep(1);
  14494. }