MessageHandler.c 969 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226
  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: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  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. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  54. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //=============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. extern sqlite3 *db;
  90. int TransactionMessageAttemptsGet(void);
  91. int TransactionMessageRetryIntervalGet(void);
  92. int GetOcppConnStatus(void);
  93. void SetOcppConnStatus(uint8_t status);
  94. int setKeyValue(char *key, char *value);
  95. void OCPP_get_TableAuthlocalAllData(void);
  96. void processUnkownKey(void);
  97. struct InterLock
  98. {
  99. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  100. unsigned char isGetDiagnosticGoing:1;
  101. unsigned char isUpdateFirmwareGoing:1;
  102. }interLock;
  103. struct ClientTime
  104. {
  105. struct timespec Heartbeat;
  106. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  107. struct timespec StartTransaction;
  108. struct timespec StopTransaction;
  109. struct timespec MeterValues[CONNECTOR_QUANTITY];
  110. struct timespec RemoteStartWait;
  111. struct timespec TcciQueryDeduct;
  112. }clientTime;
  113. typedef union
  114. {
  115. //Operations Initiated by Central System
  116. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  117. struct
  118. {
  119. //CsMsgValue[0]
  120. unsigned char StatusNotificationReq:1; //bit 0,
  121. unsigned char StatusNotificationConf:1; //bit 1,
  122. unsigned char TriggerMeterValue:1; //bit 2,
  123. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  124. unsigned char isOnCharging:1; //bit 4,
  125. unsigned char :3; //bit5~7
  126. }bits[CONNECTOR_QUANTITY];
  127. }CpinitiateMsg;
  128. CpinitiateMsg cpinitateMsg;
  129. //GetConfiguration Array
  130. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  133. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  134. #if 0
  135. static char *ChargePointErrorCodeStr[] = {
  136. MACROSTR(ConnectorLockFailure),
  137. MACROSTR(EVCommunicationError),
  138. MACROSTR(GroundFailure),
  139. MACROSTR(HighTemperature),
  140. MACROSTR(InternalError),
  141. MACROSTR(LocalListConflict),
  142. MACROSTR(NoError),
  143. MACROSTR(OtherError),
  144. MACROSTR(OverCurrentFailure),
  145. MACROSTR(OverVoltage),
  146. MACROSTR(PowerMeterFailure),
  147. MACROSTR(PowerSwitchFailure),
  148. MACROSTR(ReaderFailure),
  149. MACROSTR(ResetFailure),
  150. MACROSTR(UnderVoltage),
  151. MACROSTR(WeakSignal)
  152. };
  153. #endif
  154. static char * ChargePointStatusStr[] = {
  155. MACROSTR(Available),
  156. MACROSTR(Preparing),
  157. MACROSTR(Charging),
  158. MACROSTR(SuspendedEVSE),
  159. MACROSTR(SuspendedEV),
  160. MACROSTR(Finishing),
  161. MACROSTR(Reserved),
  162. MACROSTR(Unavailable),
  163. MACROSTR(Faulted)
  164. };
  165. static char *RegistrationStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Pending),
  168. MACROSTR(Rejected)
  169. };
  170. static char *AvailabilityTypeStr[] = {
  171. MACROSTR(Inoperative),
  172. MACROSTR(Operative)
  173. };
  174. static char *AvailabilityStatusStr[] = {
  175. MACROSTR(Accepted),
  176. MACROSTR(Rejected),
  177. MACROSTR(Scheduled)
  178. };
  179. static char *ConfigurationStatusStr[] = {
  180. MACROSTR(Accepted),
  181. MACROSTR(Rejected),
  182. MACROSTR(RebootRequired),
  183. MACROSTR(NotSupported)
  184. };
  185. static char *ClearCacheStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected)
  188. };
  189. static char *ChargingProfilePurposeTypeStr[] = {
  190. MACROSTR(ChargePointMaxProfile),
  191. MACROSTR(TxDefaultProfile),
  192. MACROSTR(TxProfile)
  193. };
  194. static char *ChargingProfileStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected),
  197. MACROSTR(NotSupported)
  198. };
  199. static char *ClearChargingProfileStatusStr[] = {
  200. MACROSTR(Accepted),
  201. MACROSTR(Unknown)
  202. };
  203. static char *GetCompositeScheduleStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Rejected)
  206. };
  207. static char *UpdateTypeStr[] = {
  208. MACROSTR(Differential),
  209. MACROSTR(Full)
  210. };
  211. static char *UpdateStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Failed),
  214. MACROSTR(NotSupported),
  215. MACROSTR(VersionMismatch)
  216. };
  217. static char *RemoteStartStopStatusStr[] = {
  218. MACROSTR(Accepted),
  219. MACROSTR(Rejected)
  220. };
  221. static char *ReservationStatusStr[] = {
  222. MACROSTR(Accepted),
  223. MACROSTR(Faulted),
  224. MACROSTR(Occupied),
  225. MACROSTR(Rejected),
  226. MACROSTR(Unavailable)
  227. };
  228. static char *ResetTypeStr[] = {
  229. MACROSTR(Hard),
  230. MACROSTR(Soft)
  231. };
  232. static char *ResetStatusStr[] = {
  233. MACROSTR(Accepted),
  234. MACROSTR(Rejected)
  235. };
  236. static char * DiagnosticsStatusStr[] = {
  237. MACROSTR(Idle),
  238. MACROSTR(Uploaded),
  239. MACROSTR(UploadFailed),
  240. MACROSTR(Uploading)
  241. };
  242. static char * FirmwareStatusStr[] = {
  243. MACROSTR(Downloaded),
  244. MACROSTR(DownloadFailed),
  245. MACROSTR(Downloading),
  246. MACROSTR(Idle),
  247. MACROSTR(InstallationFailed),
  248. MACROSTR(Installing),
  249. MACROSTR(Installed)
  250. };
  251. static char * MessageTriggerStr[] = {
  252. MACROSTR(BootNotification),
  253. MACROSTR(DiagnosticsStatusNotification),
  254. MACROSTR(FirmwareStatusNotification),
  255. MACROSTR(Heartbeat),
  256. MACROSTR(MeterValues),
  257. MACROSTR(StatusNotification)
  258. };
  259. static char * TriggerMessageStatusStr[] = {
  260. MACROSTR(Accepted),
  261. MACROSTR(Rejected),
  262. MACROSTR(NotImplemented)
  263. };
  264. static char * UnlockStatusStr[] = {
  265. MACROSTR(Unlocked),
  266. MACROSTR(UnlockFailed),
  267. MACROSTR(NotSupported)
  268. };
  269. #if 0
  270. static char * StopTransactionReasonStr[] = {
  271. MACROSTR(EmergencyStop),
  272. MACROSTR(EVDisconnected),
  273. MACROSTR(HardReset),
  274. MACROSTR(Local),
  275. MACROSTR(Other),
  276. MACROSTR(PowerLoss),
  277. MACROSTR(Reboot),
  278. MACROSTR(Remote),
  279. MACROSTR(SoftReset),
  280. MACROSTR(UnlockCommand),
  281. MACROSTR(DeAuthorized)
  282. };
  283. #endif
  284. static char * CancelReservationStatusStr[] = {
  285. MACROSTR(Accepted),
  286. MACROSTR(Rejected)
  287. };
  288. static char * ReadingContextStr[] = {
  289. MACROSTR(Interruption.Begin),
  290. MACROSTR(Interruption.End),
  291. MACROSTR(Other),
  292. MACROSTR(Sample.Clock),
  293. MACROSTR(Sample.Periodic),
  294. MACROSTR(Transaction.Begin),
  295. MACROSTR(Transaction.End),
  296. MACROSTR(Trigger)
  297. };
  298. static char * ValueFormatStr[] = {
  299. MACROSTR(Raw),
  300. MACROSTR(SignedData)
  301. };
  302. static char * MeasurandStr[] = {
  303. MACROSTR(Current.Export),
  304. MACROSTR(Current.Import),
  305. MACROSTR(Current.Offered),
  306. MACROSTR(Energy.Active.Export.Register),
  307. MACROSTR(Energy.Active.Import.Register),
  308. MACROSTR(Energy.Reactive.Export.Register),
  309. MACROSTR(Energy.Reactive.Import.Register),
  310. MACROSTR(Energy.Active.Export.Interval),
  311. MACROSTR(Energy.Active.Import.Interval),
  312. MACROSTR(Energy.Reactive.Export.Interval),
  313. MACROSTR(Energy.Reactive.Import.Interval),
  314. MACROSTR(Frequency),
  315. MACROSTR(Power.Active.Export),
  316. MACROSTR(Power.Active.Import),
  317. MACROSTR(Power.Factor),
  318. MACROSTR(Power.Offered),
  319. MACROSTR(Power.Reactive.ExportMACROSTR),
  320. MACROSTR(Power.Reactive.Import),
  321. MACROSTR(RPM),
  322. MACROSTR(SoC),
  323. MACROSTR(Temperature),
  324. MACROSTR(Voltage)
  325. };
  326. static char * LocationStr[] = {
  327. MACROSTR(Body),
  328. MACROSTR(Cable),
  329. MACROSTR(EV),
  330. MACROSTR(Inlet),
  331. MACROSTR(Outlet)
  332. };
  333. static char * PhaseStr[] = {
  334. MACROSTR(L1),
  335. MACROSTR(L2),
  336. MACROSTR(L3),
  337. MACROSTR(N),
  338. MACROSTR(L1-N),
  339. MACROSTR(L2-N),
  340. MACROSTR(L3-N),
  341. MACROSTR(L1-L2),
  342. MACROSTR(L2-L3),
  343. MACROSTR(L3-L1)
  344. };
  345. static char * UnitOfMeasureStr[] = {
  346. MACROSTR(Wh),
  347. MACROSTR(kWh),
  348. MACROSTR(varh),
  349. MACROSTR(kvarh),
  350. MACROSTR(W),
  351. MACROSTR(kW),
  352. MACROSTR(VA),
  353. MACROSTR(kVA),
  354. MACROSTR(var),
  355. MACROSTR(kvar),
  356. MACROSTR(A),
  357. MACROSTR(V),
  358. MACROSTR(Celsius),
  359. MACROSTR(Fahrenheit),
  360. MACROSTR(K),
  361. MACROSTR(Percent)
  362. };
  363. //=========================================
  364. // TTIA routine
  365. //=========================================
  366. int sendTTIAInfo(uint8_t gun_index)
  367. {
  368. static int sn = 0;
  369. int result = FAIL;
  370. struct hostent *server;
  371. int udp_socket_fd;
  372. struct sockaddr_in dest_addr = {0};
  373. uint8_t tx_buf[80] = {0};
  374. uint8_t logBuf[256]= {0};
  375. uint8_t tx_len, tempIndex, socStart, socEnd;
  376. uint16_t PresentChargedEnergy;
  377. struct tm tmStart, tmEnd;
  378. DEBUG_INFO("sendTTIAInfo...\n");
  379. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  380. {
  381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  382. {
  383. tempIndex = ((gun_index==2) ? 1: 0);
  384. }
  385. else
  386. {
  387. tempIndex = gun_index;
  388. }
  389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  390. {
  391. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  392. {
  393. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  394. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  395. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  396. }
  397. }
  398. }
  399. else if(gunType[gun_index] == GUN_TYPE_CCS)
  400. {
  401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  402. {
  403. tempIndex = ((gun_index==2) ? 1: 0);
  404. }
  405. else
  406. {
  407. tempIndex = gun_index;
  408. }
  409. for (int index = 0; index < CCS_QUANTITY; index++)
  410. {
  411. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  412. {
  413. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  414. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  415. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  416. }
  417. }
  418. }
  419. else if(gunType[gun_index] == GUN_TYPE_GBT)
  420. {
  421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  422. {
  423. tempIndex = ((gun_index==2) ? 1: 0);
  424. }
  425. else
  426. {
  427. tempIndex = gun_index;
  428. }
  429. for (int index = 0; index < GB_QUANTITY; index++)
  430. {
  431. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  432. {
  433. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  434. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  435. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  436. }
  437. }
  438. }
  439. else if(gunType[gun_index] == GUN_TYPE_DO)
  440. {
  441. tempIndex = gun_index;
  442. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  443. {
  444. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  445. {
  446. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  447. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  448. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  449. }
  450. }
  451. }
  452. else
  453. {
  454. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  455. {
  456. tempIndex = 2;
  457. }
  458. else
  459. {
  460. tempIndex = gun_index;
  461. }
  462. for (int index = 0; index < AC_QUANTITY; index++)
  463. {
  464. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  465. {
  466. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  467. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  468. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  469. }
  470. }// END
  471. }
  472. // Message assembly
  473. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  474. tx_buf[4] = 0x02; // Protocol Version
  475. tx_buf[5] = 0xb0; // Message ID
  476. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  477. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  478. tx_buf[8] = 0x00; // CarID low byte
  479. tx_buf[9] = 0x00; // CarID high byte
  480. tx_buf[10] = 0x00; // ID Storage
  481. tx_buf[11] = 0x00; // Driver lowest byte
  482. tx_buf[12] = 0x00; // Driver 2nd byte
  483. tx_buf[13] = 0x00; // Driver 3rd byte
  484. tx_buf[14] = 0x00; // Driver highest byte
  485. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  486. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  487. tx_buf[17] = 0x00; // Reserve
  488. tx_buf[18] = 60 & 0xff; // Payload length low byte
  489. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  490. // EVSE provider
  491. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  492. // EVSE provider
  493. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  494. // EVSE id
  495. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  496. // Connector id
  497. tx_buf[37] = gun_index;
  498. // EVSE station
  499. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  500. // Vehicle SN
  501. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  502. // Mileage
  503. tx_buf[61] = 0x00; // lowest byte
  504. tx_buf[62] = 0x00; // 2nd byte
  505. tx_buf[63] = 0x00; // highest byte
  506. // Start date time 6 bytes
  507. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%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))
  508. {
  509. struct tm *tmTarget;
  510. struct timeb tbTarget;
  511. tmStart.tm_year -= 1900;
  512. tmStart.tm_mon -= 1;
  513. tmStart.tm_gmtoff = 0;
  514. tbTarget.time = mktime(&tmStart);
  515. tbTarget.timezone = 0;
  516. tbTarget.time += (8*3600);
  517. tmTarget = gmtime(&tbTarget.time);
  518. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  519. tx_buf[65] = (tmTarget->tm_mon+1);
  520. tx_buf[66] = tmTarget->tm_mday;
  521. tx_buf[67] = tmTarget->tm_hour;
  522. tx_buf[68] = tmTarget->tm_min;
  523. tx_buf[69] = tmTarget->tm_sec;
  524. }
  525. // Stop date time 6 bytes
  526. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  527. {
  528. struct tm *tmTarget;
  529. struct timeb tbTarget;
  530. tmEnd.tm_year -= 1900;
  531. tmEnd.tm_mon -= 1;
  532. tmEnd.tm_gmtoff = 0;
  533. tbTarget.time = mktime(&tmEnd);
  534. tbTarget.timezone = 0;
  535. tbTarget.time += (8*3600);
  536. tmTarget = gmtime(&tbTarget.time);
  537. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  538. tx_buf[71] = (tmTarget->tm_mon+1);
  539. tx_buf[72] = tmTarget->tm_mday;
  540. tx_buf[73] = tmTarget->tm_hour;
  541. tx_buf[74] = tmTarget->tm_min;
  542. tx_buf[75] = tmTarget->tm_sec;
  543. }
  544. // Session energy 2 bytes
  545. tx_buf[76] = PresentChargedEnergy & 0xff;
  546. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  547. // Start SOC 1 byte
  548. tx_buf[78] = socStart;
  549. // Stop SOC 1 byte
  550. tx_buf[79] = socEnd;
  551. // Open socket
  552. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  553. if(udp_socket_fd == -1)
  554. {
  555. DEBUG_ERROR("UDP socket create failed!\n");
  556. }
  557. else
  558. {
  559. // Get server DNS entry
  560. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  561. if (server == NULL)
  562. {
  563. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  564. }
  565. else
  566. {
  567. // Build the server's Internet address
  568. bzero((char *) &dest_addr, sizeof(dest_addr));
  569. dest_addr.sin_family = AF_INET;
  570. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  571. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  572. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  573. {
  574. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  575. {
  576. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  577. }
  578. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  579. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  580. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  581. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  582. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  583. DEBUG_TTIA_INFO("---------- Header ----------\n");
  584. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  585. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  586. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  587. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  588. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  589. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  590. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  591. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  592. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  593. DEBUG_TTIA_INFO("Len: 0x3C\n");
  594. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  595. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  596. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  597. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  598. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  599. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  600. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  601. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  602. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  603. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  604. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  605. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  606. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  607. DEBUG_TTIA_INFO("=========================================\n");
  608. sn++;
  609. result = PASS;
  610. }
  611. else
  612. {
  613. DEBUG_ERROR("UDP sent out fail.\n");
  614. }
  615. }
  616. }
  617. return result;
  618. }
  619. //=========================================
  620. // Save configuration
  621. //=========================================
  622. int runShellCmd(const char*cmd)
  623. {
  624. int result = FAIL;
  625. char buf[256];
  626. FILE *fp;
  627. fp = popen(cmd, "r");
  628. if(fp != NULL)
  629. {
  630. while(fgets(buf, sizeof(buf), fp) != NULL)
  631. {
  632. DEBUG_INFO("%s\n", buf);
  633. }
  634. result = PASS;
  635. }
  636. pclose(fp);
  637. return result;
  638. }
  639. int StoreUsrConfigData(struct SysConfigData *UsrData)
  640. {
  641. int result = PASS;
  642. int fd,wrd;
  643. unsigned int i,Chk;
  644. unsigned char *ptr, *BufTmp;
  645. int MtdBlockSize = 0x300000;
  646. Chk=0;
  647. ptr=(unsigned char *)UsrData;
  648. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  649. {
  650. memset(BufTmp,0,MtdBlockSize);
  651. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  652. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  653. Chk+=*(BufTmp+i);
  654. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  655. // Output configuration to file.
  656. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  657. if (fd < 0)
  658. {
  659. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  660. free(BufTmp);
  661. return 0;
  662. }
  663. wrd=write(fd, BufTmp, MtdBlockSize);
  664. close(fd);
  665. if(wrd<MtdBlockSize)
  666. {
  667. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  668. free(BufTmp);
  669. return 0;
  670. }
  671. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  672. DEBUG_INFO("Erase /dev/mtd10.\n");
  673. runShellCmd("flash_erase /dev/mtd10 0 0");
  674. DEBUG_INFO("Write /dev/mtd10.\n");
  675. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  676. DEBUG_INFO("Erase /dev/mtd11.\n");
  677. runShellCmd("flash_erase /dev/mtd11 0 0");
  678. DEBUG_INFO("Write /dev/mtd11.\n");
  679. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  680. system("rm -f /mnt/EvseConfig.bin");
  681. DEBUG_INFO("EvseConfig write to flash OK\n");
  682. }
  683. else
  684. {
  685. DEBUG_ERROR("alloc BlockSize NG\r\n");
  686. result = FAIL;
  687. }
  688. if(BufTmp!=NULL)
  689. free(BufTmp);
  690. return result;
  691. }
  692. //=========================================
  693. // Sqlite3 related function
  694. //=========================================
  695. static int selectSqlCount = 0;
  696. static int callback(void *data, int argc, char **argv, char **azColName){
  697. int i;
  698. //printf("%s: ", (const char*)data);
  699. selectSqlCount = argc;
  700. for(i = 0; i<argc; i++){
  701. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  702. }
  703. //printf("\n");
  704. return 0;
  705. }
  706. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  707. //int i;
  708. //printf("%s:\n", (const char*)data);
  709. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  710. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  711. return 0;
  712. }
  713. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  714. //printf("%s:\n", (const char*)data);
  715. //idTag
  716. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  717. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  718. //parentIdTag
  719. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  720. //expir_date
  721. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  722. //status
  723. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  724. //version
  725. if(columenCount > 5)
  726. idTagQuery.listVersionInt = atoi(columnValue[5]);
  727. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  728. return 0;
  729. }
  730. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  731. {
  732. // localversion = argv[5] ? atoi(argv[5]) : 0;
  733. // printf("localversion=%d\n", localversion);
  734. return 0;
  735. }
  736. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  737. {
  738. for (int i = 0; i < n_columns; i++)
  739. {
  740. DEBUG_INFO("%s\t", col_values[i]);
  741. }
  742. DEBUG_INFO("\n");
  743. return 0;
  744. }
  745. int OCPP_cleanLocalCache()
  746. {
  747. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  748. char *errMsg = 0;
  749. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  750. if (SQLITE_OK != rc)
  751. {
  752. DEBUG_INFO("SQL error: %s\n",errMsg);
  753. return FALSE;
  754. }
  755. return TRUE;
  756. }
  757. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  758. {
  759. int isSuccess = TRUE;
  760. int ret = 0;
  761. //const char* data = "Callback function called";
  762. char sql[300];
  763. char zErrMsg[200];
  764. memset(sql, 0, 300);
  765. memset(zErrMsg, 0, 200);
  766. 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);
  767. //* Execute SQL statement */
  768. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  769. if( ret != SQLITE_OK )
  770. {
  771. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  772. isSuccess = FALSE;
  773. }
  774. return isSuccess;
  775. }
  776. void OCPP_getIdTagFromLocalCache(char idTag[])
  777. {
  778. int rc = 0;
  779. char sql[100];
  780. char zErrMsg[100];
  781. memset(sql, 0, 100);
  782. memset(zErrMsg, 0, 100);
  783. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  784. memset(&idTagQuery, 0, sizeof(idTagQuery));
  785. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  786. /* Execute SQL statement */
  787. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  788. if( rc != SQLITE_OK )
  789. {
  790. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  791. }
  792. }
  793. void OCPP_getListVerion()
  794. {
  795. int rc = 0;
  796. // const char* data = "Callback function called";
  797. char sql[100];
  798. char zErrMsg[100];
  799. memset(sql, 0, 100);
  800. memset(zErrMsg, 0, 100);
  801. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  802. /* Execute SQL statement */
  803. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  804. if( rc != SQLITE_OK )
  805. {
  806. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  807. }
  808. }
  809. void OCPP_get_TableAuthlocalAllData(void)
  810. {
  811. int rc = 0;
  812. char sql[100];
  813. char zErrMsg[100];
  814. memset(sql, 0, 100);
  815. memset(zErrMsg, 0, 100);
  816. sprintf(sql,"select * from ocpp_auth_local ");
  817. /* Execute SQL statement */
  818. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  819. if( rc != SQLITE_OK )
  820. {
  821. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  822. }
  823. //return ver;
  824. }
  825. int OCPP_cleanLocalList()
  826. {
  827. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  828. char *errMsg = 0;
  829. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  830. if (SQLITE_OK != rc)
  831. {
  832. DEBUG_INFO("%s\n",errMsg);
  833. return FALSE;
  834. }
  835. return TRUE;
  836. }
  837. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  838. {
  839. int isSuccess = FALSE;
  840. int ret = 0;
  841. //const char* data = "Callback function called";
  842. char sql[300];
  843. char zErrMsg[200];
  844. memset(sql, 0, 300);
  845. memset(zErrMsg, 0, 200);
  846. 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);
  847. //* Execute SQL statement */
  848. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  849. if( ret != SQLITE_OK )
  850. {
  851. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  852. return isSuccess;
  853. }
  854. memset(sql, 0, 300);
  855. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  856. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  857. if( ret != SQLITE_OK )
  858. {
  859. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  860. return isSuccess;
  861. }
  862. isSuccess = TRUE;
  863. return isSuccess;
  864. }
  865. void OCPP_getIdTagFromLocalList(char idTag[])
  866. {
  867. int rc = 0;
  868. // const char* data = "Callback function called";
  869. char sql[100];
  870. char zErrMsg[100];
  871. memset(sql, 0, 100);
  872. memset(zErrMsg, 0, 100);
  873. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  874. memset(&idTagQuery, 0, sizeof(idTagQuery));
  875. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  876. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  877. /* Execute SQL statement */
  878. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  879. if( rc != SQLITE_OK )
  880. {
  881. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  882. }
  883. //return ver;
  884. }
  885. void OCPP_deleteIdTagFromLocalList(char idTag[])
  886. {
  887. //int ver = 0;
  888. //int isSuccess = FALSE;
  889. int rc = 0;
  890. char sql[100];
  891. char zErrMsg[100];
  892. memset(sql, 0, 100);
  893. memset(zErrMsg, 0, 100);
  894. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  895. //* Execute SQL statement */
  896. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  897. if( rc != SQLITE_OK )
  898. {
  899. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  900. }
  901. }
  902. int getCurrentYear()
  903. {
  904. int result = 0;
  905. time_t CurrentTime;
  906. struct tm *tm;
  907. CurrentTime = time(NULL);
  908. tm=localtime(&CurrentTime);
  909. result = (tm->tm_year + 1900);
  910. return result;
  911. }
  912. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  913. {
  914. int result = PASS;
  915. char* errMsg = NULL;
  916. char sqlStr[8192];
  917. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  918. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  919. {
  920. result = FAIL;
  921. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  922. }
  923. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  924. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  925. {
  926. result = FAIL;
  927. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  928. }
  929. return result;
  930. }
  931. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  932. {
  933. int isSuccess = TRUE;
  934. int tempIndex;
  935. json_object *EnergyDataTransfer = json_object_new_object();
  936. json_object *periodEnergys = json_object_new_object();
  937. char sql[1024];
  938. char zErrMsg[200];
  939. memset(sql, 0, ARRAY_SIZE(sql));
  940. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  941. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  942. {
  943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  944. {
  945. tempIndex = ((gun_index==2) ? 1: 0);
  946. }
  947. else
  948. {
  949. tempIndex = gun_index;
  950. }
  951. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  952. {
  953. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  954. {
  955. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  956. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  957. {
  958. uint8_t period[3];
  959. sprintf((char*)period, "%d", idxPeriod);
  960. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  961. }
  962. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  963. } //end of the same index
  964. }//end of for CHAdeMO_QUANTITY
  965. }
  966. else if(gunType[gun_index] == GUN_TYPE_CCS)
  967. {
  968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  969. {
  970. tempIndex = ((gun_index==2) ? 1: 0);
  971. }
  972. else
  973. {
  974. tempIndex = gun_index;
  975. }
  976. for (int index = 0; index < CCS_QUANTITY; index++)
  977. {
  978. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  979. {
  980. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  981. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  982. {
  983. uint8_t period[3];
  984. sprintf((char*)period, "%d", idxPeriod);
  985. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  986. }
  987. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  988. } //end of the same index
  989. } // end of for CCS_QUANTITY
  990. }
  991. else if(gunType[gun_index] == GUN_TYPE_GBT)
  992. {
  993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  994. {
  995. tempIndex = ((gun_index==2) ? 1: 0);
  996. }
  997. else
  998. {
  999. tempIndex = gun_index;
  1000. }
  1001. for (int index = 0; index < GB_QUANTITY; index++)
  1002. {
  1003. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1004. {
  1005. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1006. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1007. {
  1008. uint8_t period[3];
  1009. sprintf((char*)period, "%d", idxPeriod);
  1010. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1011. }
  1012. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1013. } //end of the same index
  1014. } // end of for GB_QUANTITY
  1015. }
  1016. else if(gunType[gun_index] == GUN_TYPE_DO)
  1017. {
  1018. tempIndex = gun_index;
  1019. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1020. {
  1021. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1022. {
  1023. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1024. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1025. {
  1026. uint8_t period[3];
  1027. sprintf((char*)period, "%d", idxPeriod);
  1028. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1029. }
  1030. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1031. } //end of the same index
  1032. }
  1033. }
  1034. else
  1035. {
  1036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1037. {
  1038. tempIndex = 2;
  1039. }
  1040. else
  1041. {
  1042. tempIndex = gun_index;
  1043. }
  1044. for (int index = 0; index < AC_QUANTITY; index++)
  1045. {
  1046. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1047. {
  1048. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1049. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1050. {
  1051. uint8_t period[3];
  1052. sprintf((char*)period, "%d", idxPeriod);
  1053. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1054. }
  1055. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1056. }//end of the same index
  1057. }//end of for AC_QUANTITY
  1058. }
  1059. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1060. json_object_put(EnergyDataTransfer);
  1061. //* Execute SQL statement */
  1062. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1063. {
  1064. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1065. isSuccess = FALSE;
  1066. }
  1067. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1068. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1069. {
  1070. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1071. isSuccess = FALSE;
  1072. }
  1073. return isSuccess;
  1074. }
  1075. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1076. {
  1077. int isSuccess = TRUE;
  1078. char sql[512];
  1079. char zErrMsg[200];
  1080. int rows, cols;
  1081. char **resultData;
  1082. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1083. /* Execute SQL statement */
  1084. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1085. {
  1086. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1087. isSuccess = FALSE;
  1088. }
  1089. else
  1090. {
  1091. if((rows > 0) && (atoi(resultData[4]) > 0))
  1092. {
  1093. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1094. }
  1095. else
  1096. {
  1097. DEBUG_WARN("There is not match transaction data.\n");
  1098. isSuccess = FALSE;
  1099. }
  1100. }
  1101. return isSuccess;
  1102. }
  1103. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1104. {
  1105. int result = PASS;
  1106. char* errMsg = NULL;
  1107. char sqlStr[8192];
  1108. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1109. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1110. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1111. {
  1112. result = FAIL;
  1113. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1114. }
  1115. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1116. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1117. {
  1118. result = FAIL;
  1119. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1120. }
  1121. return result;
  1122. }
  1123. int OCPP_update_deduct_info(int txId, char *creditNo)
  1124. {
  1125. int result = PASS;
  1126. char* errMsg = NULL;
  1127. char sqlStr[8192];
  1128. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1129. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1130. {
  1131. result = FAIL;
  1132. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1133. }
  1134. return result;
  1135. }
  1136. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1137. {
  1138. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1139. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1140. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1141. atoi(columnValue[1]),
  1142. columnValue[2],
  1143. atoi(columnValue[3])==1?"true":"false",
  1144. atoi(columnValue[4])==1?"true":"false",
  1145. columnValue[5],
  1146. columnValue[9]);
  1147. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1148. return 0;
  1149. }
  1150. void OCPP_query_deduct_info()
  1151. {
  1152. int rc = 0;
  1153. char sql[100];
  1154. char zErrMsg[100];
  1155. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1156. /* Execute SQL statement */
  1157. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1158. if( rc != SQLITE_OK )
  1159. {
  1160. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1161. }
  1162. }
  1163. void reportReaderStatus(int gun_index)
  1164. {
  1165. struct timeval tmnow;
  1166. struct tm *tm;
  1167. char buf[28];//, usec_buf[6];
  1168. gettimeofday(&tmnow, NULL);
  1169. time_t t;
  1170. t = time(NULL);
  1171. /*UTC time and date*/
  1172. tm = gmtime(&t);
  1173. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1174. #if 0 // remove temporally
  1175. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1176. strcat(buf,".");
  1177. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1178. strcat(buf,usec_buf);
  1179. #endif
  1180. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1181. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1182. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1183. (gun_index+1),
  1184. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1185. buf,
  1186. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1187. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1188. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1189. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1190. }
  1191. //==========================================
  1192. // Check time passed since today
  1193. //==========================================
  1194. long long DiffTimebWithNow(struct timeb ST)
  1195. {
  1196. //return milli-second
  1197. struct timeb ET;
  1198. long long StartTime,StopTime;
  1199. ftime(&ET);
  1200. StartTime=(long long)ST.time;
  1201. StopTime=(long long)ET.time;
  1202. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1203. }
  1204. int getTimePassSinceToday(uint8_t gun_index)
  1205. {
  1206. int result = -1;
  1207. static time_t lastTime[4];
  1208. time_t t;
  1209. struct tm *tmStartToday;
  1210. struct timeb tbStartToday;
  1211. t=time(NULL);
  1212. if(difftime(t, lastTime[gun_index])>0)
  1213. {
  1214. tmStartToday=localtime(&t);
  1215. tmStartToday->tm_hour = 0;
  1216. tmStartToday->tm_min = 0;
  1217. tmStartToday->tm_sec = 0;
  1218. tbStartToday.time = mktime(tmStartToday);
  1219. tbStartToday.millitm = 0;
  1220. result = DiffTimebWithNow(tbStartToday)/1000;
  1221. lastTime[gun_index] = t;
  1222. }
  1223. return result;
  1224. }
  1225. void getNowDatetime(uint8_t *data)
  1226. {
  1227. time_t t = time(NULL);
  1228. struct tm tm = *localtime(&t);
  1229. 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);
  1230. }
  1231. int syncDateTimeRTC(uint8_t *data)
  1232. {
  1233. struct ParsingResult
  1234. {
  1235. int result;
  1236. int scanedElement;
  1237. int year;
  1238. int month;
  1239. int mday;
  1240. int hour;
  1241. int min;
  1242. int sec;
  1243. int tz_hour;
  1244. int tz_min;
  1245. float minSec;
  1246. }result;
  1247. struct tm tmOrg;
  1248. struct tm *tmTarget;
  1249. struct timeb tbTarget;
  1250. char buf[128];
  1251. memset(&result, 0x00, sizeof(struct ParsingResult));
  1252. result.result = PASS;
  1253. if(strstr((char*)data, ".") != NULL)
  1254. {
  1255. // Original data with mini second
  1256. if(strstr((char*)data, "Z") != NULL)
  1257. {
  1258. // Original data with Z
  1259. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1260. &result.year,
  1261. &result.month,
  1262. &result.mday,
  1263. &result.hour,
  1264. &result.min,
  1265. &result.sec,
  1266. &result.minSec);
  1267. }
  1268. else
  1269. {
  1270. // Original data without Z
  1271. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1272. &result.year,
  1273. &result.month,
  1274. &result.mday,
  1275. &result.hour,
  1276. &result.min,
  1277. &result.sec,
  1278. &result.minSec,
  1279. &result.tz_hour,
  1280. &result.tz_min);
  1281. }
  1282. }
  1283. else
  1284. {
  1285. // Original data without mini second
  1286. if(strstr((char*)data, "Z") != NULL)
  1287. {
  1288. // Original data with Z
  1289. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1290. &result.year,
  1291. &result.month,
  1292. &result.mday,
  1293. &result.hour,
  1294. &result.min,
  1295. &result.sec);
  1296. }
  1297. else
  1298. {
  1299. // Original data without Z
  1300. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1301. &result.year,
  1302. &result.month,
  1303. &result.mday,
  1304. &result.hour,
  1305. &result.min,
  1306. &result.sec,
  1307. &result.tz_hour,
  1308. &result.tz_min);
  1309. }
  1310. }
  1311. tmOrg.tm_year = result.year - 1900;
  1312. tmOrg.tm_mon = result.month - 1;
  1313. tmOrg.tm_mday = result.mday;
  1314. tmOrg.tm_hour = result.hour;
  1315. tmOrg.tm_min = result.min;
  1316. tmOrg.tm_sec = result.sec;
  1317. tmOrg.tm_gmtoff = 0;
  1318. tbTarget.time = mktime(&tmOrg);
  1319. tbTarget.timezone = 0;
  1320. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1321. tmTarget = gmtime(&tbTarget.time);
  1322. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  1323. //DEBUG_INFO(" org date time: %s\n", data);
  1324. //DEBUG_INFO("parse date time: %s\n", buf);
  1325. system(buf);
  1326. system("/sbin/hwclock -w --systohc");
  1327. if(result.scanedElement < 6)
  1328. result.result = FAIL;
  1329. return result.result;
  1330. }
  1331. //==========================================
  1332. // GetCompositeSchedule logic related function
  1333. //==========================================
  1334. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1335. {
  1336. //return milli-second
  1337. unsigned int StartTime,StopTime;
  1338. StartTime=(unsigned int)ST.time;
  1339. StopTime=(unsigned int)ET.time;
  1340. return (StopTime-StartTime);
  1341. }
  1342. int DiffTimebWithNowSec(struct timeb ST)
  1343. {
  1344. //return milli-second
  1345. struct timeb ET;
  1346. unsigned int StartTime,StopTime;
  1347. ftime(&ET);
  1348. StartTime=(unsigned int)ST.time;
  1349. StopTime=(unsigned int)ET.time;
  1350. return (StopTime-StartTime);
  1351. }
  1352. int getStartStop(uint8_t *start, uint8_t *stop)
  1353. {
  1354. struct ParsingResult
  1355. {
  1356. int result;
  1357. int scanedElement;
  1358. int year;
  1359. int month;
  1360. int mday;
  1361. int hour;
  1362. int min;
  1363. int sec;
  1364. int tz_hour;
  1365. int tz_min;
  1366. float minSec;
  1367. };
  1368. struct ParsingResult parseStart;
  1369. struct ParsingResult parseStop;
  1370. int result = -1;
  1371. struct tm tmStart;
  1372. struct timeb tbStart;
  1373. struct tm tmStop;
  1374. struct timeb tbStop;
  1375. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1376. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1377. // Scan start & stop date time
  1378. if(strstr((char*)start, ".") != NULL)
  1379. {
  1380. // Original data with mini second
  1381. if(strstr((char*)start, "Z") != NULL)
  1382. {
  1383. // Original data with Z
  1384. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1385. &parseStart.year,
  1386. &parseStart.month,
  1387. &parseStart.mday,
  1388. &parseStart.hour,
  1389. &parseStart.min,
  1390. &parseStart.sec,
  1391. &parseStart.minSec);
  1392. }
  1393. else
  1394. {
  1395. // Original data without Z
  1396. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1397. &parseStart.year,
  1398. &parseStart.month,
  1399. &parseStart.mday,
  1400. &parseStart.hour,
  1401. &parseStart.min,
  1402. &parseStart.sec,
  1403. &parseStart.minSec,
  1404. &parseStart.tz_hour,
  1405. &parseStart.tz_min);
  1406. }
  1407. }
  1408. else
  1409. {
  1410. // Original data without mini second
  1411. if(strstr((char*)start, "Z") != NULL)
  1412. {
  1413. // Original data with Z
  1414. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1415. &parseStart.year,
  1416. &parseStart.month,
  1417. &parseStart.mday,
  1418. &parseStart.hour,
  1419. &parseStart.min,
  1420. &parseStart.sec);
  1421. }
  1422. else
  1423. {
  1424. // Original data without Z
  1425. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1426. &parseStart.year,
  1427. &parseStart.month,
  1428. &parseStart.mday,
  1429. &parseStart.hour,
  1430. &parseStart.min,
  1431. &parseStart.sec,
  1432. &parseStart.tz_hour,
  1433. &parseStart.tz_min);
  1434. }
  1435. }
  1436. if(strstr((char*)stop, ".") != NULL)
  1437. {
  1438. // Original data with mini second
  1439. if(strstr((char*)stop, "Z") != NULL)
  1440. {
  1441. // Original data with Z
  1442. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1443. &parseStop.year,
  1444. &parseStop.month,
  1445. &parseStop.mday,
  1446. &parseStop.hour,
  1447. &parseStop.min,
  1448. &parseStop.sec,
  1449. &parseStop.minSec);
  1450. }
  1451. else
  1452. {
  1453. // Original data without Z
  1454. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1455. &parseStop.year,
  1456. &parseStop.month,
  1457. &parseStop.mday,
  1458. &parseStop.hour,
  1459. &parseStop.min,
  1460. &parseStop.sec,
  1461. &parseStop.minSec,
  1462. &parseStop.tz_hour,
  1463. &parseStop.tz_min);
  1464. }
  1465. }
  1466. else
  1467. {
  1468. // Original data without mini second
  1469. if(strstr((char*)stop, "Z") != NULL)
  1470. {
  1471. // Original data with Z
  1472. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1473. &parseStop.year,
  1474. &parseStop.month,
  1475. &parseStop.mday,
  1476. &parseStop.hour,
  1477. &parseStop.min,
  1478. &parseStop.sec);
  1479. }
  1480. else
  1481. {
  1482. // Original data without Z
  1483. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1484. &parseStop.year,
  1485. &parseStop.month,
  1486. &parseStop.mday,
  1487. &parseStop.hour,
  1488. &parseStop.min,
  1489. &parseStop.sec,
  1490. &parseStop.tz_hour,
  1491. &parseStop.tz_min);
  1492. }
  1493. }
  1494. // Calculate date time difference
  1495. if((parseStart.scanedElement >=6) &&
  1496. (parseStop.scanedElement >=6))
  1497. {
  1498. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1499. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1500. tmStart.tm_year = parseStart.year - 1900;
  1501. tmStart.tm_mon = parseStart.month - 1;
  1502. tmStart.tm_mday = parseStart.mday;
  1503. tmStart.tm_hour = parseStart.hour;
  1504. tmStart.tm_min = parseStart.min;
  1505. tmStart.tm_sec = parseStart.sec;
  1506. tmStart.tm_gmtoff = 0;
  1507. tbStart.time = mktime(&tmStart);
  1508. tbStart.timezone = 0;
  1509. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1510. tmStop.tm_year = parseStop.year - 1900;
  1511. tmStop.tm_mon = parseStop.month - 1;
  1512. tmStop.tm_mday = parseStop.mday;
  1513. tmStop.tm_hour = parseStop.hour;
  1514. tmStop.tm_min = parseStop.min;
  1515. tmStop.tm_sec = parseStop.sec;
  1516. tmStop.tm_gmtoff = 0;
  1517. tbStop.time = mktime(&tmStop);
  1518. tbStop.timezone = 0;
  1519. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1520. result = DiffTimebSec(tbStart, tbStop);
  1521. //DEBUG_INFO("getStartStop(): %d\n", result);
  1522. }
  1523. else
  1524. {
  1525. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1526. }
  1527. return result;
  1528. }
  1529. int isOvertNow(uint8_t *start)
  1530. {
  1531. int result = NO;
  1532. struct ParsingResult
  1533. {
  1534. int result;
  1535. int scanedElement;
  1536. int year;
  1537. int month;
  1538. int mday;
  1539. int hour;
  1540. int min;
  1541. int sec;
  1542. int tz_hour;
  1543. int tz_min;
  1544. float minSec;
  1545. }parsingResult;
  1546. struct tm tmStart;
  1547. struct timeb tbStart;
  1548. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1549. if(strstr((char*)start, ".") != NULL)
  1550. {
  1551. // Original data with mini second
  1552. if(strstr((char*)start, "Z") != NULL)
  1553. {
  1554. // Original data with Z
  1555. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1556. &parsingResult.year,
  1557. &parsingResult.month,
  1558. &parsingResult.mday,
  1559. &parsingResult.hour,
  1560. &parsingResult.min,
  1561. &parsingResult.sec,
  1562. &parsingResult.minSec);
  1563. }
  1564. else
  1565. {
  1566. // Original data without Z
  1567. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1568. &parsingResult.year,
  1569. &parsingResult.month,
  1570. &parsingResult.mday,
  1571. &parsingResult.hour,
  1572. &parsingResult.min,
  1573. &parsingResult.sec,
  1574. &parsingResult.minSec,
  1575. &parsingResult.tz_hour,
  1576. &parsingResult.tz_min);
  1577. }
  1578. }
  1579. else
  1580. {
  1581. // Original data without mini second
  1582. if(strstr((char*)start, "Z") != NULL)
  1583. {
  1584. // Original data with Z
  1585. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1586. &parsingResult.year,
  1587. &parsingResult.month,
  1588. &parsingResult.mday,
  1589. &parsingResult.hour,
  1590. &parsingResult.min,
  1591. &parsingResult.sec);
  1592. }
  1593. else
  1594. {
  1595. // Original data without Z
  1596. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1597. &parsingResult.year,
  1598. &parsingResult.month,
  1599. &parsingResult.mday,
  1600. &parsingResult.hour,
  1601. &parsingResult.min,
  1602. &parsingResult.sec,
  1603. &parsingResult.tz_hour,
  1604. &parsingResult.tz_min);
  1605. }
  1606. }
  1607. if(parsingResult.scanedElement >= 6)
  1608. {
  1609. tmStart.tm_year = parsingResult.year - 1900;
  1610. tmStart.tm_mon = parsingResult.month - 1;
  1611. tmStart.tm_mday = parsingResult.mday;
  1612. tmStart.tm_hour = parsingResult.hour;
  1613. tmStart.tm_min = parsingResult.min;
  1614. tmStart.tm_sec = parsingResult.sec;
  1615. tmStart.tm_gmtoff = 0;
  1616. tbStart.time = mktime(&tmStart);
  1617. tbStart.timezone = 0;
  1618. tbStart.millitm = 0;
  1619. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1620. if(DiffTimebWithNowSec(tbStart) <= 0)
  1621. result = NO;
  1622. else
  1623. result = YES;
  1624. }
  1625. else
  1626. {
  1627. DEBUG_WARN("Start date parsing error.\n");
  1628. }
  1629. return result;
  1630. }
  1631. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1632. {
  1633. struct ParsingResult
  1634. {
  1635. int result;
  1636. int scanedElement;
  1637. int year;
  1638. int month;
  1639. int mday;
  1640. int hour;
  1641. int min;
  1642. int sec;
  1643. int tz_hour;
  1644. int tz_min;
  1645. float minSec;
  1646. };
  1647. struct ParsingResult parseStart;
  1648. struct ParsingResult parseStop;
  1649. int result = -1;
  1650. struct tm tmStart;
  1651. struct timeb tbStart;
  1652. struct tm tmStop;
  1653. struct timeb tbStop;
  1654. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1655. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1656. // Scan start & stop date time
  1657. if(strstr((char*)start, ".") != NULL)
  1658. {
  1659. // Original data with mini second
  1660. if(strstr((char*)start, "Z") != NULL)
  1661. {
  1662. // Original data with Z
  1663. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1664. &parseStart.year,
  1665. &parseStart.month,
  1666. &parseStart.mday,
  1667. &parseStart.hour,
  1668. &parseStart.min,
  1669. &parseStart.sec,
  1670. &parseStart.minSec);
  1671. }
  1672. else
  1673. {
  1674. // Original data without Z
  1675. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1676. &parseStart.year,
  1677. &parseStart.month,
  1678. &parseStart.mday,
  1679. &parseStart.hour,
  1680. &parseStart.min,
  1681. &parseStart.sec,
  1682. &parseStart.minSec,
  1683. &parseStart.tz_hour,
  1684. &parseStart.tz_min);
  1685. }
  1686. }
  1687. else
  1688. {
  1689. // Original data without mini second
  1690. if(strstr((char*)start, "Z") != NULL)
  1691. {
  1692. // Original data with Z
  1693. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1694. &parseStart.year,
  1695. &parseStart.month,
  1696. &parseStart.mday,
  1697. &parseStart.hour,
  1698. &parseStart.min,
  1699. &parseStart.sec);
  1700. }
  1701. else
  1702. {
  1703. // Original data without Z
  1704. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1705. &parseStart.year,
  1706. &parseStart.month,
  1707. &parseStart.mday,
  1708. &parseStart.hour,
  1709. &parseStart.min,
  1710. &parseStart.sec,
  1711. &parseStart.tz_hour,
  1712. &parseStart.tz_min);
  1713. }
  1714. }
  1715. if(strstr((char*)stop, ".") != NULL)
  1716. {
  1717. // Original data with mini second
  1718. if(strstr((char*)stop, "Z") != NULL)
  1719. {
  1720. // Original data with Z
  1721. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1722. &parseStop.year,
  1723. &parseStop.month,
  1724. &parseStop.mday,
  1725. &parseStop.hour,
  1726. &parseStop.min,
  1727. &parseStop.sec,
  1728. &parseStop.minSec);
  1729. }
  1730. else
  1731. {
  1732. // Original data without Z
  1733. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1734. &parseStop.year,
  1735. &parseStop.month,
  1736. &parseStop.mday,
  1737. &parseStop.hour,
  1738. &parseStop.min,
  1739. &parseStop.sec,
  1740. &parseStop.minSec,
  1741. &parseStop.tz_hour,
  1742. &parseStop.tz_min);
  1743. }
  1744. }
  1745. else
  1746. {
  1747. // Original data without mini second
  1748. if(strstr((char*)stop, "Z") != NULL)
  1749. {
  1750. // Original data with Z
  1751. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1752. &parseStop.year,
  1753. &parseStop.month,
  1754. &parseStop.mday,
  1755. &parseStop.hour,
  1756. &parseStop.min,
  1757. &parseStop.sec);
  1758. }
  1759. else
  1760. {
  1761. // Original data without Z
  1762. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1763. &parseStop.year,
  1764. &parseStop.month,
  1765. &parseStop.mday,
  1766. &parseStop.hour,
  1767. &parseStop.min,
  1768. &parseStop.sec,
  1769. &parseStop.tz_hour,
  1770. &parseStop.tz_min);
  1771. }
  1772. }
  1773. // Calculate date time difference
  1774. if((parseStart.scanedElement >=6) &&
  1775. (parseStop.scanedElement >=6))
  1776. {
  1777. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1778. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1779. tmStart.tm_year = parseStart.year - 1900;
  1780. tmStart.tm_mon = parseStart.month - 1;
  1781. tmStart.tm_mday = parseStart.mday;
  1782. tmStart.tm_hour = parseStart.hour;
  1783. tmStart.tm_min = parseStart.min;
  1784. tmStart.tm_sec = parseStart.sec;
  1785. tmStart.tm_gmtoff = 0;
  1786. tbStart.time = mktime(&tmStart);
  1787. tbStart.timezone = 0;
  1788. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1789. tmStop.tm_year = parseStop.year - 1900;
  1790. tmStop.tm_mon = parseStop.month - 1;
  1791. tmStop.tm_mday = parseStop.mday;
  1792. tmStop.tm_hour = parseStop.hour;
  1793. tmStop.tm_min = parseStop.min;
  1794. tmStop.tm_sec = parseStop.sec;
  1795. tmStop.tm_gmtoff = 0;
  1796. tbStop.time = mktime(&tmStop);
  1797. tbStop.timezone = 0;
  1798. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1799. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1800. //DEBUG_INFO("getStartStop(): %d\n", result);
  1801. }
  1802. else
  1803. {
  1804. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1805. }
  1806. return result;
  1807. }
  1808. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1809. {
  1810. FILE *fp;
  1811. char profileFileName[128];
  1812. char *line = NULL;
  1813. size_t len = 0;
  1814. time_t CurrentTime;
  1815. struct tm *tmComposite;
  1816. struct StructChargingProfile maxProfile;
  1817. struct StructChargingProfile compositeProfile;
  1818. uint8_t limitMax=0;
  1819. int compositePeriodIdx = 0;
  1820. CurrentTime = time(NULL);
  1821. tmComposite=localtime(&CurrentTime);
  1822. 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);
  1823. if(isUnitA)
  1824. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1825. else
  1826. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1827. compositeProfile.ChargingSchedule.Duration = durationReq;
  1828. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1829. {
  1830. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1831. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1832. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1833. }
  1834. compositeProfile.ChargingProfileId = 0;
  1835. compositeProfile.StackLevel = 99 ;
  1836. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1837. maxProfile.ChargingProfileId = -1;
  1838. maxProfile.ChargingSchedule.Duration = -1;
  1839. system("rm -f /tmp/*.json");
  1840. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1841. // Search max profile
  1842. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1843. if((access(profileFileName, F_OK))!=-1)
  1844. {
  1845. fp = fopen(profileFileName, "r");
  1846. while(getline(&line, &len, fp) != -1)
  1847. {
  1848. json_object *obj = NULL;
  1849. obj = json_tokener_parse(line);
  1850. if(is_error(obj))
  1851. {
  1852. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1853. }
  1854. else
  1855. {
  1856. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1857. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1858. )
  1859. {
  1860. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1861. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1862. )
  1863. {
  1864. struct tm tmFrom, tmTo;
  1865. struct timeb tbFrom, tbTo;
  1866. 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) &&
  1867. (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))
  1868. {
  1869. tmFrom.tm_year -= 1900;
  1870. tmFrom.tm_mon -= 1;
  1871. tbFrom.time = mktime(&tmFrom);
  1872. tmTo.tm_year -= 1900;
  1873. tmTo.tm_mon -= 1;
  1874. tbTo.time = mktime(&tmTo);
  1875. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1876. {
  1877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1878. {
  1879. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1880. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1881. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1882. }
  1883. if(maxProfile.ChargingProfileId == -1)
  1884. DEBUG_INFO("MaxProfile found.\n");
  1885. else
  1886. DEBUG_INFO("MaxProfile updated.\n");
  1887. // Required item
  1888. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1889. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1890. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1891. if(isUnitA)
  1892. {
  1893. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1894. 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++)
  1895. {
  1896. 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"));
  1897. 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?
  1898. 3:
  1899. 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")));
  1900. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1901. }
  1902. }
  1903. else
  1904. {
  1905. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1906. 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++)
  1907. {
  1908. 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"));
  1909. 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?
  1910. 3:
  1911. 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")));
  1912. 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")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1913. }
  1914. }
  1915. // Optional item
  1916. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1917. {
  1918. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1919. }
  1920. else
  1921. {
  1922. sprintf((char*)maxProfile.ValidFrom, " ");
  1923. }
  1924. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1925. {
  1926. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1927. }
  1928. else
  1929. {
  1930. sprintf((char*)maxProfile.ValidTo, " ");
  1931. }
  1932. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1933. {
  1934. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1935. }
  1936. else
  1937. {
  1938. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1939. }
  1940. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1941. {
  1942. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1943. }
  1944. else
  1945. {
  1946. maxProfile.TransactionId = -1;
  1947. }
  1948. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1949. {
  1950. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1951. }
  1952. else
  1953. {
  1954. maxProfile.ChargingSchedule.Duration = 86400;
  1955. }
  1956. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1957. {
  1958. 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")));
  1959. }
  1960. else
  1961. {
  1962. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1963. }
  1964. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1965. {
  1966. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1967. }
  1968. else
  1969. {
  1970. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1971. }
  1972. }
  1973. }
  1974. }
  1975. else
  1976. {
  1977. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1978. {
  1979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1980. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1981. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1982. }
  1983. if(maxProfile.ChargingProfileId == -1)
  1984. DEBUG_INFO("MaxProfile found.\n");
  1985. else
  1986. DEBUG_INFO("MaxProfile updated.\n");
  1987. // Required item
  1988. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1989. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1990. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1991. if(isUnitA)
  1992. {
  1993. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1994. 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++)
  1995. {
  1996. 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"));
  1997. 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?
  1998. 3:
  1999. 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")));
  2000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2001. }
  2002. }
  2003. else
  2004. {
  2005. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2006. 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++)
  2007. {
  2008. 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"));
  2009. 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?
  2010. 3:
  2011. 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")));
  2012. 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")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2013. }
  2014. }
  2015. // Optional item
  2016. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2017. {
  2018. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2019. }
  2020. else
  2021. {
  2022. sprintf((char*)maxProfile.ValidFrom, " ");
  2023. }
  2024. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2025. {
  2026. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2027. }
  2028. else
  2029. {
  2030. sprintf((char*)maxProfile.ValidTo, " ");
  2031. }
  2032. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2033. {
  2034. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2035. }
  2036. else
  2037. {
  2038. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2039. }
  2040. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2041. {
  2042. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2043. }
  2044. else
  2045. {
  2046. maxProfile.TransactionId = -1;
  2047. }
  2048. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2049. {
  2050. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2051. }
  2052. else
  2053. {
  2054. maxProfile.ChargingSchedule.Duration = 86400;
  2055. }
  2056. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2057. {
  2058. 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")));
  2059. }
  2060. else
  2061. {
  2062. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2063. }
  2064. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2065. {
  2066. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2067. }
  2068. else
  2069. {
  2070. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2071. }
  2072. }
  2073. }
  2074. }
  2075. json_object_put(obj);
  2076. }
  2077. fclose(fp);
  2078. /*
  2079. if(maxProfile.ChargingProfileId !=-1)
  2080. {
  2081. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2082. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2083. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2084. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2085. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2086. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2087. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2088. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2089. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2090. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2091. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2092. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2093. {
  2094. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2095. {
  2096. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2097. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2098. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2099. }
  2100. }
  2101. }
  2102. else
  2103. DEBUG_INFO("MaxProfile not found.\n");
  2104. DEBUG_INFO("------------------------------------\n");*/
  2105. }
  2106. if(maxProfile.ChargingProfileId != -1)
  2107. {
  2108. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2109. {
  2110. if(maxProfile.ChargingSchedule.Duration != -1)
  2111. {
  2112. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2113. 0:
  2114. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2115. }
  2116. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2117. {
  2118. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2119. {
  2120. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2121. 0:
  2122. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2123. if(idxPeriod > 0)
  2124. {
  2125. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2126. {
  2127. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2128. }
  2129. }
  2130. }
  2131. }
  2132. }
  2133. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2134. {
  2135. if(maxProfile.ChargingSchedule.Duration != -1)
  2136. {
  2137. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2138. }
  2139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2140. {
  2141. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2142. {
  2143. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2144. if(idxPeriod > 0)
  2145. {
  2146. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2147. {
  2148. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2149. }
  2150. }
  2151. }
  2152. }
  2153. }
  2154. else
  2155. {
  2156. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2157. {
  2158. if(maxProfile.ChargingSchedule.Duration != -1)
  2159. {
  2160. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2161. 0:
  2162. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2163. }
  2164. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2165. {
  2166. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2167. {
  2168. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2169. 0:
  2170. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2171. if(idxPeriod > 0)
  2172. {
  2173. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2174. {
  2175. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2176. }
  2177. }
  2178. }
  2179. }
  2180. }
  2181. else
  2182. {
  2183. if(maxProfile.ChargingSchedule.Duration != -1)
  2184. {
  2185. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2186. 0:
  2187. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2188. }
  2189. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2190. {
  2191. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2192. {
  2193. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2194. 0:
  2195. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2196. if(idxPeriod > 0)
  2197. {
  2198. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2199. {
  2200. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. /*
  2208. DEBUG_INFO("MaxProfile after align.\n");
  2209. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2210. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2211. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2212. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2213. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2214. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2215. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2216. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2217. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2218. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2219. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2220. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2221. {
  2222. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2223. {
  2224. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2225. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2226. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2227. }
  2228. }
  2229. DEBUG_INFO("------------------------------------\n");*/
  2230. }
  2231. // Find each profile period quantity
  2232. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2233. {
  2234. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2235. limitMax = idx+1;
  2236. }
  2237. if(maxProfile.ChargingProfileId != -1)
  2238. {
  2239. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2240. {
  2241. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2242. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2243. (maxProfile.ChargingSchedule.Duration > 0))
  2244. {
  2245. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2246. {
  2247. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2248. compositePeriodIdx++;
  2249. }
  2250. else
  2251. {
  2252. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2253. }
  2254. }
  2255. }
  2256. }
  2257. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2258. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2259. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2260. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2261. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2262. {
  2263. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2264. {
  2265. compositeProfile.ChargingProfileId = 1;
  2266. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2267. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2268. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2269. }
  2270. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2271. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2272. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2273. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2274. }
  2275. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2276. if(line)
  2277. free(line);
  2278. }
  2279. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2280. {
  2281. FILE *fp;
  2282. char profileFileName[128];
  2283. char *line = NULL;
  2284. size_t len = 0;
  2285. time_t CurrentTime;
  2286. struct tm *tmComposite;
  2287. struct StructChargingProfile maxProfile;
  2288. struct StructChargingProfile defaultTxProfile;
  2289. struct StructChargingProfile txProfile;
  2290. struct StructChargingProfile compositeProfile;
  2291. struct StructChargingSchedulePeriod tmpPeriod;
  2292. uint8_t limitMax=0;
  2293. uint8_t limitDef=0;
  2294. uint8_t limitTx=0;
  2295. int compositePeriodIdx = 0;
  2296. CurrentTime = time(NULL);
  2297. tmComposite=localtime(&CurrentTime);
  2298. 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);
  2299. if(isUnitA)
  2300. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2301. else
  2302. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2303. compositeProfile.ChargingSchedule.Duration = durationReq;
  2304. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2305. {
  2306. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2307. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2308. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2309. }
  2310. compositeProfile.ChargingProfileId = 0;
  2311. compositeProfile.StackLevel = 99 ;
  2312. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2313. maxProfile.ChargingProfileId = -1;
  2314. defaultTxProfile.ChargingProfileId = -1;
  2315. txProfile.ChargingProfileId = -1;
  2316. maxProfile.ChargingSchedule.Duration = -1;
  2317. defaultTxProfile.ChargingSchedule.Duration = -1;
  2318. txProfile.ChargingSchedule.Duration = -1;
  2319. system("rm -f /tmp/*.json");
  2320. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2321. /*
  2322. * Search valid charging profile
  2323. */
  2324. //DEBUG_INFO("====================================\n");
  2325. // Search tx profile
  2326. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2327. if((access(profileFileName, F_OK))!=-1)
  2328. {
  2329. fp = fopen(profileFileName, "r");
  2330. while(getline(&line, &len, fp) != -1)
  2331. {
  2332. json_object *obj = NULL;
  2333. obj = json_tokener_parse(line);
  2334. if(is_error(obj))
  2335. {
  2336. DEBUG_ERROR("Parse txProfile from file error.\n");
  2337. }
  2338. else
  2339. {
  2340. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2341. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2342. )
  2343. {
  2344. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2345. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2346. )
  2347. {
  2348. struct tm tmFrom, tmTo;
  2349. struct timeb tbFrom, tbTo;
  2350. 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) &&
  2351. (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))
  2352. {
  2353. tmFrom.tm_year -= 1900;
  2354. tmFrom.tm_mon -= 1;
  2355. tbFrom.time = mktime(&tmFrom);
  2356. tmTo.tm_year -= 1900;
  2357. tmTo.tm_mon -= 1;
  2358. tbTo.time = mktime(&tmTo);
  2359. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2360. {
  2361. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2362. {
  2363. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2364. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2365. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2366. }
  2367. if(txProfile.ChargingProfileId == -1)
  2368. DEBUG_INFO("TxProfile found.\n");
  2369. else
  2370. DEBUG_INFO("TxProfile updated.\n");
  2371. // Required item
  2372. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2373. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2374. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2375. if(isUnitA)
  2376. {
  2377. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2378. 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++)
  2379. {
  2380. 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"));
  2381. 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?
  2382. 3:
  2383. 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")));
  2384. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2385. }
  2386. }
  2387. else
  2388. {
  2389. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2390. 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++)
  2391. {
  2392. 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"));
  2393. 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?
  2394. 3:
  2395. 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")));
  2396. 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")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2397. }
  2398. }
  2399. // Optional item
  2400. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2401. {
  2402. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2403. }
  2404. else
  2405. {
  2406. sprintf((char*)txProfile.ValidFrom, " ");
  2407. }
  2408. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2409. {
  2410. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2411. }
  2412. else
  2413. {
  2414. sprintf((char*)txProfile.ValidTo, " ");
  2415. }
  2416. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2417. {
  2418. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2419. }
  2420. else
  2421. {
  2422. sprintf((char*)txProfile.RecurrencyKind, " ");
  2423. }
  2424. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2425. {
  2426. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2427. }
  2428. else
  2429. {
  2430. txProfile.TransactionId = -1;
  2431. }
  2432. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2433. {
  2434. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2435. }
  2436. else
  2437. {
  2438. txProfile.ChargingSchedule.Duration = 86400;
  2439. }
  2440. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2441. {
  2442. 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")));
  2443. }
  2444. else
  2445. {
  2446. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2447. }
  2448. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2449. {
  2450. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2451. }
  2452. else
  2453. {
  2454. txProfile.ChargingSchedule.MinChargingRate = -1;
  2455. }
  2456. }
  2457. }
  2458. }
  2459. else
  2460. {
  2461. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2462. {
  2463. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2464. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2465. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2466. }
  2467. if(txProfile.ChargingProfileId == -1)
  2468. DEBUG_INFO("TxProfile found.\n");
  2469. else
  2470. DEBUG_INFO("TxProfile updated.\n");
  2471. // Required item
  2472. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2473. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2474. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2475. if(isUnitA)
  2476. {
  2477. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2478. 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++)
  2479. {
  2480. 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"));
  2481. 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?
  2482. 3:
  2483. 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")));
  2484. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2485. }
  2486. }
  2487. else
  2488. {
  2489. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2490. 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++)
  2491. {
  2492. 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"));
  2493. 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?
  2494. 3:
  2495. 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")));
  2496. 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")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2497. }
  2498. }
  2499. // Optional item
  2500. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2501. {
  2502. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2503. }
  2504. else
  2505. {
  2506. sprintf((char*)txProfile.ValidFrom, " ");
  2507. }
  2508. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2509. {
  2510. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2511. }
  2512. else
  2513. {
  2514. sprintf((char*)txProfile.ValidTo, " ");
  2515. }
  2516. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2517. {
  2518. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2519. }
  2520. else
  2521. {
  2522. sprintf((char*)txProfile.RecurrencyKind, " ");
  2523. }
  2524. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2525. {
  2526. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2527. }
  2528. else
  2529. {
  2530. txProfile.TransactionId = -1;
  2531. }
  2532. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2533. {
  2534. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2535. }
  2536. else
  2537. {
  2538. txProfile.ChargingSchedule.Duration = 86400;
  2539. }
  2540. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2541. {
  2542. 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")));
  2543. }
  2544. else
  2545. {
  2546. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2547. }
  2548. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2549. {
  2550. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2551. }
  2552. else
  2553. {
  2554. txProfile.ChargingSchedule.MinChargingRate = -1;
  2555. }
  2556. }
  2557. }
  2558. }
  2559. json_object_put(obj);
  2560. }
  2561. fclose(fp);
  2562. /*
  2563. if(txProfile.ChargingProfileId != -1)
  2564. {
  2565. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2566. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2567. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2568. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2569. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2570. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2571. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2572. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2573. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2574. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2575. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2576. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2577. {
  2578. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2579. {
  2580. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2581. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2582. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2583. }
  2584. }
  2585. }
  2586. else
  2587. DEBUG_INFO("TxProfile not found.\n");*/
  2588. }
  2589. // Search default tx profile
  2590. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2591. if((access(profileFileName, F_OK))==-1)
  2592. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2593. if((access(profileFileName, F_OK))!=-1)
  2594. {
  2595. fp = fopen(profileFileName, "r");
  2596. while(getline(&line, &len, fp) != -1)
  2597. {
  2598. json_object *obj = NULL;
  2599. obj = json_tokener_parse(line);
  2600. if(is_error(obj))
  2601. {
  2602. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2603. }
  2604. else
  2605. {
  2606. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2607. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2608. )
  2609. {
  2610. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2611. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2612. )
  2613. {
  2614. struct tm tmFrom, tmTo;
  2615. struct timeb tbFrom, tbTo;
  2616. 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) &&
  2617. (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))
  2618. {
  2619. tmFrom.tm_year -= 1900;
  2620. tmFrom.tm_mon -= 1;
  2621. tbFrom.time = mktime(&tmFrom);
  2622. tmTo.tm_year -= 1900;
  2623. tmTo.tm_mon -= 1;
  2624. tbTo.time = mktime(&tmTo);
  2625. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2626. {
  2627. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2628. {
  2629. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2630. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2631. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2632. }
  2633. if(defaultTxProfile.ChargingProfileId == -1)
  2634. DEBUG_INFO("TxDefaultProfile found.\n");
  2635. else
  2636. DEBUG_INFO("TxDefaultProfile updated.\n");
  2637. // Required item
  2638. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2639. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2640. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2641. if(isUnitA)
  2642. {
  2643. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2644. 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++)
  2645. {
  2646. 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"));
  2647. 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?
  2648. 3:
  2649. 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")));
  2650. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2651. }
  2652. }
  2653. else
  2654. {
  2655. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2656. 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++)
  2657. {
  2658. 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"));
  2659. 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?
  2660. 3:
  2661. 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")));
  2662. 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")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2663. }
  2664. }
  2665. // Optional item
  2666. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2667. {
  2668. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2669. }
  2670. else
  2671. {
  2672. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2673. }
  2674. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2675. {
  2676. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2677. }
  2678. else
  2679. {
  2680. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2681. }
  2682. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2683. {
  2684. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2685. }
  2686. else
  2687. {
  2688. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2689. }
  2690. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2691. {
  2692. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2693. }
  2694. else
  2695. {
  2696. defaultTxProfile.TransactionId = -1;
  2697. }
  2698. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2699. {
  2700. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2701. }
  2702. else
  2703. {
  2704. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2705. }
  2706. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2707. {
  2708. 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")));
  2709. }
  2710. else
  2711. {
  2712. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2713. }
  2714. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2715. {
  2716. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2717. }
  2718. else
  2719. {
  2720. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2721. }
  2722. }
  2723. }
  2724. }
  2725. else
  2726. {
  2727. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2728. {
  2729. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2730. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2731. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2732. }
  2733. if(defaultTxProfile.ChargingProfileId == -1)
  2734. DEBUG_INFO("TxDefaultProfile found.\n");
  2735. else
  2736. DEBUG_INFO("TxDefaultProfile updated.\n");
  2737. // Required item
  2738. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2739. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2740. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2741. if(isUnitA)
  2742. {
  2743. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2744. 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++)
  2745. {
  2746. 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"));
  2747. 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?
  2748. 3:
  2749. 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")));
  2750. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2751. }
  2752. }
  2753. else
  2754. {
  2755. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2756. 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++)
  2757. {
  2758. 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"));
  2759. 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?
  2760. 3:
  2761. 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")));
  2762. 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")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2763. }
  2764. }
  2765. // Optional item
  2766. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2767. {
  2768. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2769. }
  2770. else
  2771. {
  2772. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2773. }
  2774. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2775. {
  2776. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2777. }
  2778. else
  2779. {
  2780. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2781. }
  2782. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2783. {
  2784. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2785. }
  2786. else
  2787. {
  2788. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2789. }
  2790. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2791. {
  2792. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2793. }
  2794. else
  2795. {
  2796. defaultTxProfile.TransactionId = -1;
  2797. }
  2798. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2799. {
  2800. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2801. }
  2802. else
  2803. {
  2804. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2805. }
  2806. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2807. {
  2808. 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")));
  2809. }
  2810. else
  2811. {
  2812. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2813. }
  2814. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2815. {
  2816. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2817. }
  2818. else
  2819. {
  2820. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2821. }
  2822. }
  2823. }
  2824. }
  2825. json_object_put(obj);
  2826. }
  2827. fclose(fp);
  2828. /*
  2829. if(defaultTxProfile.ChargingProfileId != -1)
  2830. {
  2831. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2832. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2833. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2834. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2835. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2836. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2837. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2838. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2839. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2840. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2841. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2842. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2843. {
  2844. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2845. {
  2846. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2847. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2848. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2849. }
  2850. }
  2851. }
  2852. else
  2853. DEBUG_INFO("TxDefaultProfile not found.\n");
  2854. DEBUG_INFO("------------------------------------\n");*/
  2855. }
  2856. // Search max profile
  2857. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2858. if((access(profileFileName, F_OK))!=-1)
  2859. {
  2860. fp = fopen(profileFileName, "r");
  2861. while(getline(&line, &len, fp) != -1)
  2862. {
  2863. json_object *obj = NULL;
  2864. obj = json_tokener_parse(line);
  2865. if(is_error(obj))
  2866. {
  2867. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2868. }
  2869. else
  2870. {
  2871. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2872. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2873. )
  2874. {
  2875. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2876. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2877. )
  2878. {
  2879. struct tm tmFrom, tmTo;
  2880. struct timeb tbFrom, tbTo;
  2881. 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) &&
  2882. (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))
  2883. {
  2884. tmFrom.tm_year -= 1900;
  2885. tmFrom.tm_mon -= 1;
  2886. tbFrom.time = mktime(&tmFrom);
  2887. tmTo.tm_year -= 1900;
  2888. tmTo.tm_mon -= 1;
  2889. tbTo.time = mktime(&tmTo);
  2890. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2891. {
  2892. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2893. {
  2894. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2895. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2896. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2897. }
  2898. if(maxProfile.ChargingProfileId == -1)
  2899. DEBUG_INFO("MaxProfile found.\n");
  2900. else
  2901. DEBUG_INFO("MaxProfile updated.\n");
  2902. // Required item
  2903. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2904. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2905. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2906. if(isUnitA)
  2907. {
  2908. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2909. 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++)
  2910. {
  2911. 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"));
  2912. 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?
  2913. 3:
  2914. 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")));
  2915. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2916. }
  2917. }
  2918. else
  2919. {
  2920. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2921. 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++)
  2922. {
  2923. 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"));
  2924. 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?
  2925. 3:
  2926. 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")));
  2927. 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")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2928. }
  2929. }
  2930. // Optional item
  2931. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2932. {
  2933. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2934. }
  2935. else
  2936. {
  2937. sprintf((char*)maxProfile.ValidFrom, " ");
  2938. }
  2939. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2940. {
  2941. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2942. }
  2943. else
  2944. {
  2945. sprintf((char*)maxProfile.ValidTo, " ");
  2946. }
  2947. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2948. {
  2949. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2950. }
  2951. else
  2952. {
  2953. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2954. }
  2955. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2956. {
  2957. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2958. }
  2959. else
  2960. {
  2961. maxProfile.TransactionId = -1;
  2962. }
  2963. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2964. {
  2965. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2966. }
  2967. else
  2968. {
  2969. maxProfile.ChargingSchedule.Duration = 86400;
  2970. }
  2971. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2972. {
  2973. 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")));
  2974. }
  2975. else
  2976. {
  2977. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2978. }
  2979. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2980. {
  2981. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2982. }
  2983. else
  2984. {
  2985. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2986. }
  2987. }
  2988. }
  2989. }
  2990. else
  2991. {
  2992. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2993. {
  2994. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2995. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2996. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2997. }
  2998. if(maxProfile.ChargingProfileId == -1)
  2999. DEBUG_INFO("MaxProfile found.\n");
  3000. else
  3001. DEBUG_INFO("MaxProfile updated.\n");
  3002. // Required item
  3003. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3004. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3005. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3006. if(isUnitA)
  3007. {
  3008. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3009. 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++)
  3010. {
  3011. 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"));
  3012. 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?
  3013. 3:
  3014. 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")));
  3015. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3016. }
  3017. }
  3018. else
  3019. {
  3020. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3021. 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++)
  3022. {
  3023. 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"));
  3024. 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?
  3025. 3:
  3026. 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")));
  3027. 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")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  3028. }
  3029. }
  3030. // Optional item
  3031. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3032. {
  3033. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3034. }
  3035. else
  3036. {
  3037. sprintf((char*)maxProfile.ValidFrom, " ");
  3038. }
  3039. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3040. {
  3041. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3042. }
  3043. else
  3044. {
  3045. sprintf((char*)maxProfile.ValidTo, " ");
  3046. }
  3047. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3048. {
  3049. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3050. }
  3051. else
  3052. {
  3053. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3054. }
  3055. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3056. {
  3057. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3058. }
  3059. else
  3060. {
  3061. maxProfile.TransactionId = -1;
  3062. }
  3063. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3064. {
  3065. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3066. }
  3067. else
  3068. {
  3069. maxProfile.ChargingSchedule.Duration = 86400;
  3070. }
  3071. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3072. {
  3073. 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")));
  3074. }
  3075. else
  3076. {
  3077. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3078. }
  3079. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3080. {
  3081. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3082. }
  3083. else
  3084. {
  3085. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3086. }
  3087. }
  3088. }
  3089. }
  3090. json_object_put(obj);
  3091. }
  3092. fclose(fp);
  3093. /*
  3094. if(maxProfile.ChargingProfileId !=-1)
  3095. {
  3096. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3097. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3098. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3099. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3100. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3101. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3102. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3103. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3104. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3105. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3106. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3107. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3108. {
  3109. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3110. {
  3111. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3112. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3113. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3114. }
  3115. }
  3116. }
  3117. else
  3118. DEBUG_INFO("MaxProfile not found.\n");
  3119. DEBUG_INFO("------------------------------------\n");*/
  3120. }
  3121. /*
  3122. * Align found profile start schedule & periods
  3123. */
  3124. //DEBUG_INFO("====================================\n");
  3125. /*
  3126. // For local test usage, force modify found profile start schedule info
  3127. 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);
  3128. 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);
  3129. 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);
  3130. */
  3131. if(txProfile.ChargingProfileId != -1)
  3132. {
  3133. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3134. {
  3135. if(txProfile.ChargingSchedule.Duration != -1)
  3136. {
  3137. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3138. 0:
  3139. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3140. }
  3141. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3142. {
  3143. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3144. {
  3145. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3146. 0:
  3147. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3148. if(idxPeriod > 0)
  3149. {
  3150. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3151. {
  3152. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3153. }
  3154. }
  3155. }
  3156. }
  3157. }
  3158. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3159. {
  3160. if(txProfile.ChargingSchedule.Duration != -1)
  3161. {
  3162. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3163. 0:
  3164. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3165. }
  3166. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3167. {
  3168. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3169. {
  3170. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3171. 0:
  3172. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3173. if(idxPeriod > 0)
  3174. {
  3175. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3176. {
  3177. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3178. }
  3179. }
  3180. }
  3181. }
  3182. }
  3183. else
  3184. {
  3185. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3186. {
  3187. if(txProfile.ChargingSchedule.Duration != -1)
  3188. {
  3189. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3190. 0:
  3191. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3192. }
  3193. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3194. {
  3195. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3196. {
  3197. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3198. 0:
  3199. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3200. if(idxPeriod > 0)
  3201. {
  3202. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3203. {
  3204. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3205. }
  3206. }
  3207. }
  3208. }
  3209. }
  3210. else
  3211. {
  3212. if(txProfile.ChargingSchedule.Duration != -1)
  3213. {
  3214. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3215. 0:
  3216. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3217. }
  3218. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3219. {
  3220. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3221. {
  3222. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3223. 0:
  3224. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3225. if(idxPeriod > 0)
  3226. {
  3227. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3228. {
  3229. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3230. }
  3231. }
  3232. }
  3233. }
  3234. }
  3235. }
  3236. /*
  3237. DEBUG_INFO("txProfile after align.\n");
  3238. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3239. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3240. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3241. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3242. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3243. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3244. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3245. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3246. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3247. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3248. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3249. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3250. {
  3251. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3252. {
  3253. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3254. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3255. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3256. }
  3257. }*/
  3258. }
  3259. if(defaultTxProfile.ChargingProfileId != -1)
  3260. {
  3261. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3262. {
  3263. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3264. {
  3265. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3266. 0:
  3267. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3268. }
  3269. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3270. {
  3271. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3272. {
  3273. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3274. 0:
  3275. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3276. if(idxPeriod > 0)
  3277. {
  3278. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3279. {
  3280. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3281. }
  3282. }
  3283. }
  3284. }
  3285. }
  3286. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3287. {
  3288. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3289. {
  3290. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3291. 0:
  3292. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3293. }
  3294. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3295. {
  3296. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3297. {
  3298. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3299. 0:
  3300. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3301. if(idxPeriod > 0)
  3302. {
  3303. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3304. {
  3305. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3306. }
  3307. }
  3308. }
  3309. }
  3310. }
  3311. else
  3312. {
  3313. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3314. {
  3315. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3316. {
  3317. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3318. 0:
  3319. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3320. }
  3321. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3322. {
  3323. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3324. {
  3325. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3326. 0:
  3327. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3328. if(idxPeriod > 0)
  3329. {
  3330. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3331. {
  3332. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3333. }
  3334. }
  3335. }
  3336. }
  3337. }
  3338. else
  3339. {
  3340. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3341. {
  3342. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3343. 0:
  3344. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3345. }
  3346. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3347. {
  3348. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3349. {
  3350. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3351. 0:
  3352. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3353. if(idxPeriod > 0)
  3354. {
  3355. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3356. {
  3357. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3358. }
  3359. }
  3360. }
  3361. }
  3362. }
  3363. }
  3364. /*
  3365. DEBUG_INFO("defaultTxProfile after align.\n");
  3366. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3367. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3368. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3369. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3370. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3371. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3372. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3373. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3374. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3375. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3376. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3377. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3378. {
  3379. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3380. {
  3381. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3382. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3383. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3384. }
  3385. }
  3386. DEBUG_INFO("------------------------------------\n");*/
  3387. }
  3388. if(maxProfile.ChargingProfileId != -1)
  3389. {
  3390. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3391. {
  3392. if(maxProfile.ChargingSchedule.Duration != -1)
  3393. {
  3394. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3395. 0:
  3396. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3397. }
  3398. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3399. {
  3400. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3401. {
  3402. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3403. 0:
  3404. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3405. if(idxPeriod > 0)
  3406. {
  3407. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3408. {
  3409. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3410. }
  3411. }
  3412. }
  3413. }
  3414. }
  3415. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3416. {
  3417. if(maxProfile.ChargingSchedule.Duration != -1)
  3418. {
  3419. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3420. 0:
  3421. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3422. }
  3423. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3424. {
  3425. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3426. {
  3427. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3428. 0:
  3429. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3430. if(idxPeriod > 0)
  3431. {
  3432. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3433. {
  3434. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3435. }
  3436. }
  3437. }
  3438. }
  3439. }
  3440. else
  3441. {
  3442. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3443. {
  3444. if(maxProfile.ChargingSchedule.Duration != -1)
  3445. {
  3446. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3447. 0:
  3448. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3449. }
  3450. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3451. {
  3452. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3453. {
  3454. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3455. 0:
  3456. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3457. if(idxPeriod > 0)
  3458. {
  3459. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3460. {
  3461. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3462. }
  3463. }
  3464. }
  3465. }
  3466. }
  3467. else
  3468. {
  3469. if(maxProfile.ChargingSchedule.Duration != -1)
  3470. {
  3471. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3472. 0:
  3473. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3474. }
  3475. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3476. {
  3477. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3478. {
  3479. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3480. 0:
  3481. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3482. if(idxPeriod > 0)
  3483. {
  3484. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3485. {
  3486. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3487. }
  3488. }
  3489. }
  3490. }
  3491. }
  3492. }
  3493. /*
  3494. DEBUG_INFO("MaxProfile after align.\n");
  3495. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3496. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3497. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3498. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3499. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3500. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3501. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3502. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3503. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3504. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3505. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3506. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3507. {
  3508. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3509. {
  3510. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3511. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3512. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3513. }
  3514. }
  3515. DEBUG_INFO("------------------------------------\n");*/
  3516. }
  3517. /*
  3518. * Merge to conposite schedule
  3519. */
  3520. //DEBUG_INFO("====================================\n");
  3521. // Find each profile period quantity
  3522. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3523. {
  3524. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3525. limitMax = idx+1;
  3526. }
  3527. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3528. {
  3529. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3530. limitDef = idx+1;
  3531. }
  3532. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3533. {
  3534. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3535. limitTx = idx+1;
  3536. }
  3537. // TxProfile found, composite schedule based on it
  3538. if(txProfile.ChargingProfileId != -1)
  3539. {
  3540. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3541. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3542. {
  3543. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3544. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3545. (txProfile.ChargingSchedule.Duration > 0))
  3546. {
  3547. if(maxProfile.ChargingProfileId != -1)
  3548. {
  3549. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3550. {
  3551. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3552. {
  3553. if((maxProfile.ChargingSchedule.Duration > 0))
  3554. {
  3555. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3556. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3557. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3558. }
  3559. else
  3560. {
  3561. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3562. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3563. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3564. }
  3565. }
  3566. if(idxMaxPeriod == (limitMax-1))
  3567. {
  3568. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3569. {
  3570. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3571. {
  3572. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3573. compositePeriodIdx++;
  3574. }
  3575. else
  3576. {
  3577. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3578. }
  3579. }
  3580. }
  3581. }
  3582. }
  3583. else
  3584. {
  3585. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3586. {
  3587. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3588. compositePeriodIdx++;
  3589. }
  3590. else
  3591. {
  3592. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3593. }
  3594. }
  3595. }
  3596. if(idxTxPeriod == (limitTx-1))
  3597. {
  3598. if(defaultTxProfile.ChargingProfileId != -1)
  3599. {
  3600. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3601. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3602. {
  3603. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3604. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3605. (defaultTxProfile.ChargingSchedule.Duration>0))
  3606. {
  3607. if(maxProfile.ChargingProfileId != -1)
  3608. {
  3609. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3610. {
  3611. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3612. {
  3613. if((maxProfile.ChargingSchedule.Duration > 0))
  3614. {
  3615. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3616. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3617. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3618. }
  3619. else
  3620. {
  3621. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3622. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3623. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3624. }
  3625. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3626. {
  3627. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3628. {
  3629. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3630. compositePeriodIdx++;
  3631. }
  3632. else
  3633. {
  3634. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3635. }
  3636. }
  3637. // Delete duplicate period
  3638. if(compositePeriodIdx > 1)
  3639. {
  3640. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3641. {
  3642. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3643. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3644. compositePeriodIdx -= 1;
  3645. }
  3646. }
  3647. }
  3648. else
  3649. {
  3650. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3651. {
  3652. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3653. compositePeriodIdx++;
  3654. }
  3655. else
  3656. {
  3657. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3658. }
  3659. break;
  3660. }
  3661. }
  3662. }
  3663. else
  3664. {
  3665. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3666. {
  3667. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3668. compositePeriodIdx++;
  3669. }
  3670. else
  3671. {
  3672. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3673. }
  3674. }
  3675. }
  3676. }
  3677. }
  3678. }
  3679. }
  3680. }
  3681. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3682. else if(defaultTxProfile.ChargingProfileId != -1)
  3683. {
  3684. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3685. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3686. {
  3687. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3688. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3689. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3690. {
  3691. if(maxProfile.ChargingProfileId != -1)
  3692. {
  3693. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3694. {
  3695. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3696. {
  3697. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3698. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3699. if((maxProfile.ChargingSchedule.Duration > 0))
  3700. {
  3701. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3702. }
  3703. else
  3704. {
  3705. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3706. }
  3707. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3708. {
  3709. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3710. {
  3711. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3712. compositePeriodIdx++;
  3713. }
  3714. else
  3715. {
  3716. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3717. }
  3718. }
  3719. // Delete duplicate period
  3720. if(compositePeriodIdx > 1)
  3721. {
  3722. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3723. {
  3724. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3725. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3726. compositePeriodIdx -= 1;
  3727. }
  3728. }
  3729. }
  3730. else
  3731. {
  3732. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3733. {
  3734. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3735. compositePeriodIdx++;
  3736. }
  3737. else
  3738. {
  3739. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3740. }
  3741. break;
  3742. }
  3743. }
  3744. }
  3745. else
  3746. {
  3747. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3748. {
  3749. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3750. compositePeriodIdx++;
  3751. }
  3752. else
  3753. {
  3754. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3755. }
  3756. }
  3757. }
  3758. }
  3759. }
  3760. // Fill other period by MaxProfile
  3761. if(maxProfile.ChargingProfileId != -1)
  3762. {
  3763. if(compositePeriodIdx==0)
  3764. {
  3765. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3766. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3767. {
  3768. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3769. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3770. (maxProfile.ChargingSchedule.Duration > 0))
  3771. {
  3772. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3773. {
  3774. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3775. compositePeriodIdx++;
  3776. }
  3777. else
  3778. {
  3779. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3780. }
  3781. }
  3782. }
  3783. }
  3784. else
  3785. {
  3786. int lastCompositePeriodIdx = compositePeriodIdx;
  3787. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3788. {
  3789. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3790. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3791. (maxProfile.ChargingSchedule.Duration > 0))
  3792. {
  3793. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3794. {
  3795. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3796. {
  3797. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3798. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3799. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3800. }
  3801. else
  3802. {
  3803. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3804. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3805. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3806. }
  3807. }
  3808. if(tmpPeriod.Limit != -1)
  3809. {
  3810. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3811. {
  3812. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3813. {
  3814. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3815. compositePeriodIdx++;
  3816. }
  3817. else
  3818. {
  3819. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3820. }
  3821. }
  3822. // Delete duplicate period
  3823. if(compositePeriodIdx > 1)
  3824. {
  3825. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3826. {
  3827. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3828. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3829. compositePeriodIdx -= 1;
  3830. }
  3831. }
  3832. }
  3833. }
  3834. }
  3835. }
  3836. }
  3837. compositeProfile.ChargingSchedule.Duration = durationReq;
  3838. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3839. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3840. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3841. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3842. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3843. {
  3844. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3845. {
  3846. compositeProfile.ChargingProfileId = 1;
  3847. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3848. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3849. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3850. }
  3851. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3852. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3853. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3854. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3855. }
  3856. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3857. if(line)
  3858. free(line);
  3859. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3860. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3861. }
  3862. //==========================================
  3863. // Init all share memory
  3864. //==========================================
  3865. int InitShareMemory()
  3866. {
  3867. int result = PASS;
  3868. int MeterSMId;
  3869. //creat ShmSysConfigAndInfo
  3870. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3871. {
  3872. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3873. result = FAIL;
  3874. }
  3875. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3876. {
  3877. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3878. result = FAIL;
  3879. }
  3880. else
  3881. {}
  3882. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3883. {
  3884. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3885. result = FAIL;
  3886. }
  3887. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3888. {
  3889. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3890. result = FAIL;
  3891. }
  3892. else
  3893. {}
  3894. //creat ShmPsuData
  3895. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3896. {
  3897. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3898. result = FAIL;
  3899. }
  3900. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3901. {
  3902. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3903. result = FAIL;
  3904. }
  3905. else
  3906. {}
  3907. //creat ShmOCPP16Data
  3908. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3909. {
  3910. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3911. result = FAIL;
  3912. }
  3913. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3914. {
  3915. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3916. result = FAIL;
  3917. }
  3918. else
  3919. {}
  3920. /****************************** For Initial Settings************************************************/
  3921. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3922. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3923. // allocate Configuration memory address
  3924. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3925. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3926. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3927. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3928. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3929. //offline MeterValue Interval
  3930. TempMeterValueInterval = 0;
  3931. return result;
  3932. }
  3933. int ProcessShareMemory()
  3934. {
  3935. int result = PASS;
  3936. if(InitShareMemory() == FAIL)
  3937. {
  3938. DEBUG_ERROR("InitShareMemory NG\n");
  3939. if(ShmStatusCodeData!=NULL)
  3940. {
  3941. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3942. }
  3943. result = FAIL;
  3944. }
  3945. // Model name parsing
  3946. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3947. {
  3948. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3949. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3950. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3951. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3952. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3953. ) // 'D' means DC
  3954. {
  3955. // DO series
  3956. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3957. {
  3958. gunTotalNumber += 1;
  3959. gunType[gun_index] = GUN_TYPE_DO;
  3960. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3961. {
  3962. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3963. {
  3964. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3965. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3966. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3967. }
  3968. }
  3969. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3970. {
  3971. case Gun_Type_Chademo:
  3972. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3973. break;
  3974. case Gun_Type_CCS_2:
  3975. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3976. break;
  3977. case Gun_Type_GB:
  3978. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3979. break;
  3980. case Gun_Type_AC:
  3981. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3982. break;
  3983. default:
  3984. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3985. break;
  3986. }
  3987. }
  3988. }
  3989. else
  3990. {
  3991. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3992. {
  3993. gunTotalNumber += 1;
  3994. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3995. {
  3996. case Gun_Type_Chademo:
  3997. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3998. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3999. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4000. {
  4001. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4002. {
  4003. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4004. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4005. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4006. }
  4007. }
  4008. break;
  4009. case Gun_Type_CCS_2:
  4010. gunType[gun_index] = GUN_TYPE_CCS;
  4011. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4012. for (int index = 0; index < CCS_QUANTITY; index++)
  4013. {
  4014. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4015. {
  4016. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4017. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4018. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4019. }
  4020. }
  4021. break;
  4022. case Gun_Type_GB:
  4023. gunType[gun_index] = GUN_TYPE_GBT;
  4024. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4025. for (int index = 0; index < GB_QUANTITY; index++)
  4026. {
  4027. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4028. {
  4029. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4030. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4031. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4032. }
  4033. }
  4034. break;
  4035. case Gun_Type_AC:
  4036. gunType[gun_index] = GUN_TYPE_AC;
  4037. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4038. for (int index = 0; index < AC_QUANTITY; index++)
  4039. {
  4040. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4041. {
  4042. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4043. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4044. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4045. }
  4046. }
  4047. break;
  4048. default:
  4049. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4050. break;
  4051. }
  4052. }
  4053. }
  4054. }
  4055. else
  4056. {
  4057. DEBUG_ERROR("Model name parsing fail.\n");
  4058. result = FAIL;
  4059. }
  4060. if(result != PASS)sleep(5);
  4061. return result;
  4062. }
  4063. void checkRemoteStart(uint8_t connectorIdInt)
  4064. {
  4065. uint8_t tempIndex;
  4066. int result = PASS;
  4067. char cmdBuf[512];
  4068. //check Transaction active
  4069. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4070. {
  4071. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4072. {
  4073. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4074. }
  4075. else
  4076. {
  4077. tempIndex = connectorIdInt -1;
  4078. }
  4079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4080. {
  4081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4082. {
  4083. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4084. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4085. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4086. {
  4087. //Reserved
  4088. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4089. }
  4090. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4091. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4092. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4093. {
  4094. //Reserved
  4095. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4096. result = FAIL;
  4097. goto end;
  4098. }
  4099. else
  4100. {
  4101. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4102. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4103. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4104. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4105. {
  4106. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4107. result = FAIL;
  4108. goto end;
  4109. }
  4110. }//END FOR ELSE
  4111. }
  4112. }// END FOR CHAdeMO_QUANTITY
  4113. }
  4114. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4115. {
  4116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4117. {
  4118. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4119. }
  4120. else
  4121. {
  4122. tempIndex = connectorIdInt -1;
  4123. }
  4124. for (int index = 0; index < CCS_QUANTITY; index++)
  4125. {
  4126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4127. {
  4128. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4129. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4130. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4131. {
  4132. //Reserved
  4133. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4134. }
  4135. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4136. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4137. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4138. {
  4139. //Reserved
  4140. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4141. result = FAIL;
  4142. goto end;
  4143. }
  4144. else
  4145. {
  4146. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4147. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4148. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4149. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4150. {
  4151. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4152. result = FAIL;
  4153. goto end;
  4154. }
  4155. }// END FOR ELSE
  4156. }
  4157. }// END FOR CCS_QUANTITY
  4158. }
  4159. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4160. {
  4161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4162. {
  4163. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4164. }
  4165. else
  4166. {
  4167. tempIndex = connectorIdInt -1;
  4168. }
  4169. for (int index = 0; index < GB_QUANTITY; index++)
  4170. {
  4171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4172. {
  4173. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4174. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4175. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4176. {
  4177. //Reserved
  4178. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4179. }
  4180. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4181. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4182. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4183. {
  4184. //Reserved
  4185. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4186. result = FAIL;
  4187. goto end;
  4188. }
  4189. else
  4190. {
  4191. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4192. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4193. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4194. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4195. {
  4196. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4197. result = FAIL;
  4198. goto end;
  4199. }
  4200. }// END FOR ELSE
  4201. }
  4202. } // END FOR GB_QUANTITY
  4203. }
  4204. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4205. {
  4206. tempIndex = connectorIdInt -1;
  4207. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4208. {
  4209. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4210. {
  4211. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4212. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4213. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4214. {
  4215. //Reserved
  4216. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4217. }
  4218. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4219. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4220. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4221. {
  4222. //Reserved
  4223. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4224. result = FAIL;
  4225. goto end;
  4226. }
  4227. else
  4228. {
  4229. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4230. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4231. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4232. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4233. {
  4234. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4235. result = FAIL;
  4236. goto end;
  4237. }
  4238. }// END FOR ELSE
  4239. }
  4240. } // END FOR GB_QUANTITY
  4241. }
  4242. else
  4243. {
  4244. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4245. {
  4246. tempIndex = 2;
  4247. }
  4248. else
  4249. {
  4250. tempIndex = connectorIdInt -1;
  4251. }
  4252. for (int index = 0; index < AC_QUANTITY; index++)
  4253. {
  4254. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4255. {
  4256. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4257. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4258. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4259. {
  4260. //Reserved
  4261. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4262. }
  4263. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4264. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4265. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4266. {
  4267. //Reserved
  4268. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4269. result = FAIL;
  4270. goto end;
  4271. }
  4272. else
  4273. {
  4274. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4275. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4276. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4277. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4278. {
  4279. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4280. result = FAIL;
  4281. goto end;
  4282. }
  4283. }//END FOR ELSE
  4284. }
  4285. }// END FOR AC_QUANTITY
  4286. }
  4287. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4288. {
  4289. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4290. {
  4291. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4292. {
  4293. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4294. system(cmdBuf);
  4295. }
  4296. }
  4297. else
  4298. {
  4299. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4300. result = FAIL;
  4301. }
  4302. }
  4303. end:
  4304. if(result == PASS)
  4305. {
  4306. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4307. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4308. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4309. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4310. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4311. }
  4312. }
  4313. void CheckSystemValue(void)
  4314. {
  4315. char filenmae[100]={0};
  4316. char str[100]={0};
  4317. int tempIndex = 0;
  4318. //===============================
  4319. // send Heartbeat
  4320. //===============================
  4321. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4322. {
  4323. //parameter for test
  4324. sendHeartbeatRequest(0);
  4325. //===========================
  4326. // Reset Waiting Time
  4327. //===========================
  4328. HeartBeatWithNOResponse += 1;
  4329. }
  4330. //===============================
  4331. // Credit deduct report
  4332. //===============================
  4333. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4334. {
  4335. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4336. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4337. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4338. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4339. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4340. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4341. }
  4342. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4343. {
  4344. OCPP_query_deduct_info();
  4345. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4346. }
  4347. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4348. {
  4349. // ClockAlign MeterValue
  4350. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4351. {
  4352. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4353. {
  4354. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4355. {
  4356. tempIndex = ((gun_index==2) ? 1: 0);
  4357. }
  4358. else
  4359. {
  4360. tempIndex = gun_index;
  4361. }
  4362. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4363. {
  4364. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4365. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4366. {
  4367. reqClockAlignMeter[gun_index] = 1;
  4368. }
  4369. }// End for CHAdeMO
  4370. }
  4371. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4372. {
  4373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4374. {
  4375. tempIndex = ((gun_index==2) ? 1: 0);
  4376. }
  4377. else
  4378. {
  4379. tempIndex = gun_index;
  4380. }
  4381. for (int index = 0; index < CCS_QUANTITY; index++)
  4382. {
  4383. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4384. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4385. {
  4386. reqClockAlignMeter[gun_index] = 1;
  4387. }
  4388. } // End for CCS
  4389. }
  4390. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4391. {
  4392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4393. {
  4394. tempIndex = ((gun_index==2) ? 1: 0);
  4395. }
  4396. else
  4397. {
  4398. tempIndex = gun_index;
  4399. }
  4400. for (int index = 0; index < GB_QUANTITY; index++)
  4401. {
  4402. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4403. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4404. {
  4405. reqClockAlignMeter[gun_index] = 1;
  4406. }
  4407. }// End for GB
  4408. }
  4409. else if(gunType[gun_index] == GUN_TYPE_DO)
  4410. {
  4411. tempIndex = gun_index;
  4412. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4413. {
  4414. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4415. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4416. {
  4417. reqClockAlignMeter[gun_index] = 1;
  4418. }
  4419. }
  4420. }
  4421. else
  4422. {
  4423. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4424. {
  4425. tempIndex = 2;
  4426. }
  4427. else
  4428. {
  4429. tempIndex = gun_index;
  4430. }
  4431. for (int index = 0; index < AC_QUANTITY; index++)
  4432. {
  4433. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4434. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4435. {
  4436. reqClockAlignMeter[gun_index] = 1;
  4437. }
  4438. }//End for AC
  4439. }
  4440. }
  4441. }
  4442. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4443. {
  4444. //==========================================
  4445. // Check remote start without connector id
  4446. //==========================================
  4447. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4448. {
  4449. int connectorIdInt = -1;
  4450. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4451. {
  4452. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4453. {
  4454. connectorIdInt = (gun_index+1);
  4455. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4456. checkRemoteStart(connectorIdInt);
  4457. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4458. break;
  4459. }
  4460. }
  4461. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4462. {
  4463. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4464. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4465. }
  4466. }
  4467. //==========================================
  4468. // csu trigger DataTransferReq
  4469. //==========================================
  4470. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4471. {
  4472. sendDataTransferRequest(gun_index);
  4473. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4474. }
  4475. //==========================================
  4476. // CSU Trigger Authorize Request
  4477. //==========================================
  4478. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4479. {
  4480. sendAuthorizeRequest(0);
  4481. authorizeRetryTimes = authorizeRetryTimes + 1;
  4482. if(authorizeRetryTimes < 3)
  4483. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4484. }
  4485. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4486. {
  4487. authorizeRetryTimes = 0;
  4488. SetOcppConnStatus(FALSE);
  4489. server_sign = FALSE;
  4490. }
  4491. 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))
  4492. {
  4493. sendAuthorizeRequest(0);
  4494. }
  4495. //==========================================
  4496. // Charger start transaction
  4497. //==========================================
  4498. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4499. {
  4500. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4501. sendStartTransactionRequest(gun_index);
  4502. refreshStartTimer(&clientTime.StartTransaction);
  4503. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4504. storeTempStopTransaction(gun_index);
  4505. }
  4506. //==========================================
  4507. // Charger stop transaction
  4508. //==========================================
  4509. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4510. {
  4511. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4512. sendStopTransactionRequest(gun_index);
  4513. OCPP_updatePeriodEnergy(gun_index);
  4514. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4515. refreshStartTimer(&clientTime.StopTransaction);
  4516. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4517. }
  4518. //==========================================
  4519. // Charger status report
  4520. //==========================================
  4521. //--- Check Mode Change ---//
  4522. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4523. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4524. {
  4525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4526. {
  4527. tempIndex = ((gun_index==2) ? 1: 0);
  4528. }
  4529. else
  4530. {
  4531. tempIndex = gun_index;
  4532. }
  4533. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4534. {
  4535. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4536. {
  4537. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4538. {
  4539. // Sent unplug message for California pricing logic
  4540. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4541. {
  4542. uint8_t ts[36];
  4543. getNowDatetime(ts);
  4544. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4545. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4546. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4547. sendUnplugByDataTransferRequest(gun_index);
  4548. interLock.isSentUnplug[gun_index] = 1;
  4549. }
  4550. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4551. {
  4552. interLock.isSentUnplug[gun_index] = 0;
  4553. }
  4554. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4555. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4556. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4557. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4558. {
  4559. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4560. if((access(filenmae,F_OK))!=-1)
  4561. {
  4562. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4563. sprintf(str,"rm -f %s",filenmae);
  4564. system(str);
  4565. }
  4566. }
  4567. }
  4568. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4569. #if 1 // for TempStopTransaction
  4570. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4571. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4572. {
  4573. checkTempStopTransaction(gun_index);
  4574. }
  4575. #endif
  4576. }
  4577. }
  4578. }
  4579. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4580. {
  4581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4582. {
  4583. tempIndex = ((gun_index==2) ? 1: 0);
  4584. }
  4585. else
  4586. {
  4587. tempIndex = gun_index;
  4588. }
  4589. for (int index = 0; index < CCS_QUANTITY; index++)
  4590. {
  4591. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4592. {
  4593. if((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]*/ )
  4594. {
  4595. // Sent unplug message for California pricing logic
  4596. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4597. {
  4598. uint8_t ts[36];
  4599. getNowDatetime(ts);
  4600. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4601. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4602. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4603. sendUnplugByDataTransferRequest(gun_index);
  4604. interLock.isSentUnplug[gun_index] = 1;
  4605. }
  4606. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4607. {
  4608. interLock.isSentUnplug[gun_index] = 0;
  4609. }
  4610. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4611. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4612. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4613. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4614. {
  4615. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4616. if((access(filenmae,F_OK))!=-1)
  4617. {
  4618. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4619. sprintf(str,"rm -f %s",filenmae);
  4620. system(str);
  4621. }
  4622. }
  4623. }
  4624. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4625. #if 1 // for TempStopTransaction
  4626. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4627. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4628. {
  4629. checkTempStopTransaction(gun_index);
  4630. }
  4631. #endif
  4632. }
  4633. }
  4634. }
  4635. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4636. {
  4637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4638. {
  4639. tempIndex = ((gun_index==2) ? 1: 0);
  4640. }
  4641. else
  4642. {
  4643. tempIndex = gun_index;
  4644. }
  4645. for (int index = 0; index < GB_QUANTITY; index++)
  4646. {
  4647. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4648. {
  4649. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4650. {
  4651. // Sent unplug message for California pricing logic
  4652. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4653. {
  4654. uint8_t ts[36];
  4655. getNowDatetime(ts);
  4656. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4657. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4658. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4659. sendUnplugByDataTransferRequest(gun_index);
  4660. interLock.isSentUnplug[gun_index] = 1;
  4661. }
  4662. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4663. {
  4664. interLock.isSentUnplug[gun_index] = 0;
  4665. }
  4666. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4667. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4668. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4669. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4670. {
  4671. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4672. if((access(filenmae,F_OK))!=-1)
  4673. {
  4674. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4675. sprintf(str,"rm -f %s",filenmae);
  4676. system(str);
  4677. }
  4678. }
  4679. }
  4680. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4681. #if 1 // for TempStopTransaction
  4682. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4683. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4684. {
  4685. checkTempStopTransaction(gun_index);
  4686. }
  4687. #endif
  4688. }
  4689. }
  4690. }
  4691. else if(gunType[gun_index] == GUN_TYPE_DO)
  4692. {
  4693. tempIndex = gun_index;
  4694. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4695. {
  4696. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4697. {
  4698. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4699. {
  4700. // Sent unplug message for California pricing logic
  4701. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4702. {
  4703. uint8_t ts[36];
  4704. getNowDatetime(ts);
  4705. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4706. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4707. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4708. sendUnplugByDataTransferRequest(gun_index);
  4709. interLock.isSentUnplug[gun_index] = 1;
  4710. }
  4711. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4712. {
  4713. interLock.isSentUnplug[gun_index] = 0;
  4714. }
  4715. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4716. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4717. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4718. 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_IDLE))) // complete
  4719. {
  4720. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4721. if((access(filenmae,F_OK))!=-1)
  4722. {
  4723. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4724. sprintf(str,"rm -f %s",filenmae);
  4725. system(str);
  4726. }
  4727. }
  4728. }
  4729. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4730. #if 1 // for TempStopTransaction
  4731. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4732. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4733. {
  4734. checkTempStopTransaction(gun_index);
  4735. }
  4736. #endif
  4737. }
  4738. }
  4739. }
  4740. else
  4741. {
  4742. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4743. {
  4744. tempIndex = 2;
  4745. }
  4746. else
  4747. {
  4748. tempIndex = gun_index;
  4749. }
  4750. for (int index = 0; index < AC_QUANTITY; index++)
  4751. {
  4752. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4753. {
  4754. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4755. {
  4756. // Sent unplug message for California pricing logic
  4757. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4758. {
  4759. uint8_t ts[36];
  4760. getNowDatetime(ts);
  4761. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4762. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4763. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4764. sendUnplugByDataTransferRequest(gun_index);
  4765. interLock.isSentUnplug[gun_index] = 1;
  4766. }
  4767. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4768. {
  4769. interLock.isSentUnplug[gun_index] = 0;
  4770. }
  4771. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4772. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4773. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4774. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4775. {
  4776. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4777. if((access(filenmae,F_OK))!=-1)
  4778. {
  4779. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4780. sprintf(str,"rm -f %s",filenmae);
  4781. system(str);
  4782. }
  4783. }
  4784. }
  4785. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4786. #if 1 // for TempStopTransaction
  4787. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4788. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4789. {
  4790. checkTempStopTransaction(gun_index);
  4791. }
  4792. #endif
  4793. }
  4794. }// END
  4795. }
  4796. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4797. (
  4798. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4799. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4800. )
  4801. )
  4802. {
  4803. sendStatusNotificationRequest(gun_index);
  4804. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4805. }
  4806. //==============================================
  4807. // TCCI reader status report
  4808. //==============================================
  4809. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4810. {
  4811. reportReaderStatus(gun_index);
  4812. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4813. }
  4814. //==============================================
  4815. // CSU Trigger Smart Charging Profile
  4816. //==============================================
  4817. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4818. {
  4819. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4820. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4821. }
  4822. //==============================================
  4823. // Meter report
  4824. //==============================================
  4825. // Trigger MeterValue
  4826. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4827. {
  4828. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4829. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4830. }
  4831. // Clock-aligned Meter value
  4832. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4833. {
  4834. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4835. reqClockAlignMeter[gun_index] = 0;
  4836. }
  4837. // Sample period MeterValue
  4838. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4839. {
  4840. //check Transaction active
  4841. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4842. {
  4843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4844. {
  4845. tempIndex = ((gun_index==2) ? 1: 0);
  4846. }
  4847. else
  4848. {
  4849. tempIndex = gun_index;
  4850. }
  4851. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4852. {
  4853. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4854. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4855. {
  4856. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4857. {
  4858. reqSampleMeter[gun_index] = 1;
  4859. }
  4860. }
  4861. }// End for CHAdeMO
  4862. }
  4863. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4864. {
  4865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4866. {
  4867. tempIndex = ((gun_index==2) ? 1: 0);
  4868. }
  4869. else
  4870. {
  4871. tempIndex = gun_index;
  4872. }
  4873. for (int index = 0; index < CCS_QUANTITY; index++)
  4874. {
  4875. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4876. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4877. {
  4878. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4879. {
  4880. reqSampleMeter[gun_index] = 1;
  4881. }
  4882. }
  4883. } // End for CCS
  4884. }
  4885. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4886. {
  4887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4888. {
  4889. tempIndex = ((gun_index==2) ? 1: 0);
  4890. }
  4891. else
  4892. {
  4893. tempIndex = gun_index;
  4894. }
  4895. for (int index = 0; index < GB_QUANTITY; index++)
  4896. {
  4897. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4898. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4899. {
  4900. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4901. {
  4902. reqSampleMeter[gun_index] = 1;
  4903. }
  4904. }
  4905. }// End for GB
  4906. }
  4907. else if(gunType[gun_index] == GUN_TYPE_DO)
  4908. {
  4909. tempIndex = gun_index;
  4910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4911. {
  4912. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4913. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4914. {
  4915. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4916. {
  4917. reqSampleMeter[gun_index] = 1;
  4918. }
  4919. }
  4920. }
  4921. }
  4922. else
  4923. {
  4924. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4925. {
  4926. tempIndex = 2;
  4927. }
  4928. else
  4929. {
  4930. tempIndex = gun_index;
  4931. }
  4932. for (int index = 0; index < AC_QUANTITY; index++)
  4933. {
  4934. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4935. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4936. {
  4937. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4938. {
  4939. reqSampleMeter[gun_index] = 1;
  4940. }
  4941. }
  4942. }//End for AC
  4943. }
  4944. if(reqSampleMeter[gun_index] == 1)
  4945. {
  4946. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4947. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4948. storeTempStopTransaction(gun_index);
  4949. reqSampleMeter[gun_index] = 0;
  4950. }
  4951. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4952. }
  4953. //==============================================
  4954. // Check Connector reserved
  4955. //==============================================
  4956. //===============================
  4957. // Check if Reserve is expired
  4958. //===============================
  4959. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4960. {
  4961. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4962. {
  4963. DEBUG_INFO("reserve expired.\n");
  4964. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4965. }
  4966. }//END OF Check if Reserve is expired
  4967. //==========================================
  4968. // csu trigger FirmwareStatusNotificationReq
  4969. //==========================================
  4970. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4971. {
  4972. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4973. }
  4974. //==========================================
  4975. // csu trigger DiagnosticsStatusNotificationReq
  4976. //==========================================
  4977. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4978. {
  4979. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4980. }
  4981. //==========================================
  4982. // csu trigger CancelReservationConf
  4983. //==========================================
  4984. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4985. {
  4986. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4987. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4988. }
  4989. //==========================================
  4990. // csu trigger ChangeAvailabilityConf
  4991. //==========================================
  4992. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4993. {
  4994. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4995. }
  4996. //==========================================
  4997. // csu trigger UnlockConnectorConf
  4998. //==========================================
  4999. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5000. {
  5001. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5002. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5003. }
  5004. //==========================================
  5005. // csu trigger ReserveNowConf
  5006. //==========================================
  5007. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5008. {
  5009. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5010. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5011. }
  5012. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  5013. {
  5014. sendSignCertificateRequest();
  5015. }
  5016. }
  5017. }
  5018. //==========================================
  5019. // send request routine
  5020. //==========================================
  5021. int sendAuthorizeRequest(int gun_index)
  5022. {
  5023. mtrace();
  5024. int result = FAIL;
  5025. char message[100]={0};
  5026. char guid[37];
  5027. char tempdata[65]={0};
  5028. DEBUG_INFO("sendAuthorizeRequest...\n");
  5029. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5030. //Local Authorize
  5031. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5032. {
  5033. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5034. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5035. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5036. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5037. result = PASS;
  5038. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5039. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5040. authorizeRetryTimes = 0;
  5041. return result;
  5042. }
  5043. 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))||
  5044. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5045. {
  5046. // Query from cache
  5047. DEBUG_INFO("Authorize from cache.\n");
  5048. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5049. // Query from list
  5050. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5051. {
  5052. DEBUG_INFO("Authorize from list.\n");
  5053. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5054. }
  5055. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5056. {
  5057. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5058. {
  5059. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5060. }
  5061. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5062. {
  5063. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5064. }
  5065. if(!GetOcppConnStatus())
  5066. {
  5067. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5068. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5069. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5070. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5071. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5072. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5073. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5074. authorizeRetryTimes = 0;
  5075. return result;
  5076. }
  5077. }
  5078. else
  5079. {
  5080. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5081. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5082. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5083. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5084. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5085. else
  5086. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5087. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5088. result = PASS;
  5089. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5090. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5091. authorizeRetryTimes = 0;
  5092. return result;
  5093. }
  5094. }
  5095. //initialize struct Authorize
  5096. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5097. //get data from shared memory
  5098. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5099. random_uuid(guid);
  5100. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5101. LWS_Send(message);
  5102. sprintf(tempdata, "Authorize,%d", gun_index);
  5103. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5104. {
  5105. result = PASS;
  5106. DEBUG_INFO("Authorize mapItem pass\n");
  5107. }
  5108. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5109. return result;
  5110. }
  5111. int sendBootNotificationRequest(void)
  5112. {
  5113. mtrace();
  5114. int result = FAIL;
  5115. char message[500]={0}, payload[700]={0};
  5116. char guid[37]={0};
  5117. char tempdata[65]={0};
  5118. // Fill BootNotification fields
  5119. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5120. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5121. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5122. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5123. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5124. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5125. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5126. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5127. ShmOCPP16Data->ChargeBoxId
  5128. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5129. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5130. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5131. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5132. ,ShmOCPP16Data->BootNotification.CpIccid
  5133. ,ShmOCPP16Data->BootNotification.CpImsi);
  5134. random_uuid(guid);
  5135. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5136. LWS_Send(message);
  5137. sprintf(tempdata, "BootNotification,0");
  5138. 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*/)
  5139. {
  5140. result = PASS;
  5141. }
  5142. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5143. strcpy(queuedata,message);
  5144. return result;
  5145. }
  5146. int sendDataTransferRequest(int gun_index)
  5147. {
  5148. mtrace();
  5149. char message[1000]={0};
  5150. char guid[37]={0};
  5151. char tempdata[65]={0};
  5152. int result = FAIL;
  5153. random_uuid(guid);
  5154. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5155. MESSAGE_TYPE_CALL,
  5156. guid,
  5157. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5158. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5159. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5160. LWS_Send(message);
  5161. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5162. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5163. {
  5164. result = PASS;
  5165. DEBUG_INFO("DataTransfer mapItem pass\n");
  5166. }
  5167. return result;
  5168. }
  5169. int sendUnplugByDataTransferRequest(int gun_index)
  5170. {
  5171. mtrace();
  5172. char message[1000]={0};
  5173. char guid[37]={0};
  5174. char tempdata[65]={0};
  5175. int result = FAIL;
  5176. random_uuid(guid);
  5177. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5178. (gun_index+1),
  5179. MESSAGE_TYPE_CALL,
  5180. guid,
  5181. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5182. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5183. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5184. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5185. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5186. {
  5187. result = PASS;
  5188. DEBUG_INFO("DataTransfer mapItem pass\n");
  5189. }
  5190. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5191. return result;
  5192. }
  5193. int sendDiagnosticsStatusNotificationRequest(char *status)
  5194. {
  5195. mtrace();
  5196. int result = FAIL;
  5197. char message[110]={0};
  5198. char guid[37]={0};
  5199. char tempdata[65]={0};
  5200. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5201. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5202. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5203. random_uuid(guid);
  5204. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5205. LWS_SendNow(message);
  5206. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5207. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5208. {
  5209. result = PASS;
  5210. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5211. }
  5212. //#ifdef SystemLogMessage
  5213. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5214. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5215. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5216. //#endif
  5217. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5218. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5219. //record status
  5220. if(strcmp(status,"Idle")==0)
  5221. {
  5222. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5223. }
  5224. else if(strcmp(status,"Uploaded")==0)
  5225. {
  5226. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5227. }
  5228. else if(strcmp(status,"UploadFailed")==0)
  5229. {
  5230. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5231. }
  5232. else if(strcmp(status,"Uploading")==0)
  5233. {
  5234. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5235. }
  5236. return result;
  5237. }
  5238. int sendFirmwareStatusNotificationRequest(char *status)
  5239. {
  5240. mtrace();
  5241. int result = FAIL;
  5242. char message[110]={0};
  5243. char guid[37]={0};
  5244. char tempdata[65]={0};
  5245. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5246. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5247. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5248. random_uuid(guid);
  5249. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5250. LWS_SendNow(message);
  5251. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5252. 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*/)
  5253. {
  5254. result = PASS;
  5255. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5256. }
  5257. //#ifdef SystemLogMessage
  5258. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5259. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5260. //#endif
  5261. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5262. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5263. //record status
  5264. if(strcmp(status,"Downloaded")==0)
  5265. {
  5266. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5267. }
  5268. else if(strcmp(status,"DownloadFailed")==0)
  5269. {
  5270. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5271. }
  5272. else if(strcmp(status,"Downloading")==0)
  5273. {
  5274. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5275. }
  5276. else if(strcmp(status,"Idle")==0)
  5277. {
  5278. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5279. }
  5280. else if(strcmp(status,"InstallationFailed")==0)
  5281. {
  5282. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5283. }
  5284. else if(strcmp(status,"Installing")==0)
  5285. {
  5286. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5287. }
  5288. else if(strcmp(status,"Installed")==0)
  5289. {
  5290. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5291. }
  5292. return result;
  5293. }
  5294. int sendHeartbeatRequest(int gun_index)
  5295. {
  5296. mtrace();
  5297. int result = FAIL;
  5298. char message[80]={0};
  5299. char guid[37]={0};
  5300. char tempdata[65]={0};
  5301. random_uuid(guid);
  5302. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5303. , MESSAGE_TYPE_CALL
  5304. , guid );
  5305. LWS_Send(message);
  5306. sprintf(tempdata, "Heartbeat,%d", 0);
  5307. 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*/)
  5308. {
  5309. result = PASS;
  5310. }
  5311. return result;
  5312. }
  5313. int sendStartTransactionRequest(int gun_index)
  5314. {
  5315. mtrace();
  5316. int result = FAIL;
  5317. char message[250]={0};
  5318. char guid[37]={0};
  5319. struct timeval tmnow;
  5320. struct tm *tm;
  5321. char buf[28];//, usec_buf[6];
  5322. char tempdata[65]={0};
  5323. int tempIndex = 0;
  5324. DEBUG_INFO("sendStartTransactionRequest...\n");
  5325. gettimeofday(&tmnow, NULL);
  5326. time_t t;
  5327. t = time(NULL);
  5328. /*UTC time and date*/
  5329. tm = gmtime(&t);
  5330. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5331. #if 0 // remove temporally
  5332. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5333. strcat(buf,".");
  5334. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5335. strcat(buf,usec_buf);
  5336. #endif
  5337. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5338. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5339. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5340. // clear StartTransaction Response
  5341. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5342. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5343. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5344. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5345. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5346. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5347. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5348. {
  5349. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5350. {
  5351. tempIndex = ((gun_index==2) ? 1: 0);
  5352. }
  5353. else
  5354. {
  5355. tempIndex = gun_index;
  5356. }
  5357. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5358. {
  5359. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5360. {
  5361. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5362. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5363. }
  5364. }
  5365. }
  5366. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5367. {
  5368. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5369. {
  5370. tempIndex = ((gun_index==2) ? 1: 0);
  5371. }
  5372. else
  5373. {
  5374. tempIndex = gun_index;
  5375. }
  5376. for (int index = 0; index < CCS_QUANTITY; index++)
  5377. {
  5378. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5379. {
  5380. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5381. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5382. }
  5383. }
  5384. }
  5385. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5386. {
  5387. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5388. {
  5389. tempIndex = ((gun_index==2) ? 1: 0);
  5390. }
  5391. else
  5392. {
  5393. tempIndex = gun_index;
  5394. }
  5395. for (int index = 0; index < GB_QUANTITY; index++)
  5396. {
  5397. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5398. {
  5399. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5400. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5401. }
  5402. }
  5403. }
  5404. else if(gunType[gun_index] == GUN_TYPE_DO)
  5405. {
  5406. tempIndex = gun_index;
  5407. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5408. {
  5409. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5410. {
  5411. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5412. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5413. }
  5414. }
  5415. }
  5416. else
  5417. {
  5418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5419. {
  5420. tempIndex = 2;
  5421. }
  5422. else
  5423. {
  5424. tempIndex = gun_index;
  5425. }
  5426. for (int index = 0; index < AC_QUANTITY; index++)
  5427. {
  5428. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5429. {
  5430. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5431. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5432. }
  5433. }
  5434. }
  5435. random_uuid(guid);
  5436. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5437. {
  5438. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5439. , gun_index +1
  5440. , MESSAGE_TYPE_CALL
  5441. , guid
  5442. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5443. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5444. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5445. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5446. }
  5447. else
  5448. {
  5449. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5450. , gun_index +1
  5451. , MESSAGE_TYPE_CALL
  5452. , guid
  5453. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5454. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5455. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5456. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5457. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5458. }
  5459. #if 1
  5460. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5461. 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*/)
  5462. {
  5463. result = PASS;
  5464. }
  5465. #endif
  5466. strcpy(queuedata, message);
  5467. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5468. OCPP_insert_transaction_msg(YES, queuedata);
  5469. return result;
  5470. }
  5471. int sendStatusNotificationRequest(int gun_index)
  5472. {
  5473. mtrace();
  5474. int result = FAIL;
  5475. char message[600]={0};
  5476. char guid[37];
  5477. int currentStatus = 0;
  5478. struct timeval tmnow;
  5479. struct tm *tm;
  5480. char buf[28];//, usec_buf[6];
  5481. char tempdata[65]={0};
  5482. int tempIndex = 0;
  5483. uint8_t isStateChanged = TRUE;
  5484. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5485. gettimeofday(&tmnow, NULL);
  5486. time_t t;
  5487. t = time(NULL);
  5488. /*UTC time and date*/
  5489. tm = gmtime(&t);
  5490. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5491. #if 0 // remove temporally
  5492. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5493. strcat(buf,".");
  5494. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5495. strcat(buf,usec_buf);
  5496. #endif
  5497. //printf("%s",buf);
  5498. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5499. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5500. // it's option
  5501. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5502. /*
  5503. enum _SYSTEM_STATUS
  5504. {
  5505. S_BOOTING = 0,
  5506. S_IDLE, = 1
  5507. S_AUTHORIZING, =2
  5508. S_REASSIGN_CHECK, =3
  5509. S_REASSIGN, =4
  5510. S_PRECHARGE, =5
  5511. S_PREPARING_FOR_EV, =6
  5512. S_PREPARING_FOR_EVSE, =7
  5513. S_CHARGING, =8
  5514. S_TERMINATING, =9
  5515. S_COMPLETE, =10
  5516. S_ALARM, =11
  5517. S_FAULT =12
  5518. }
  5519. */
  5520. //check Transaction active
  5521. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5522. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5523. {
  5524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5525. {
  5526. tempIndex = ((gun_index==2) ? 1: 0);
  5527. }
  5528. else
  5529. {
  5530. tempIndex = gun_index;
  5531. }
  5532. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5533. {
  5534. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5535. {
  5536. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5537. {
  5538. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5539. {
  5540. currentStatus = Preparing; //OCPP Status: Preparing
  5541. }
  5542. else
  5543. {
  5544. currentStatus = Available; //OCPP Status: Available
  5545. }
  5546. }
  5547. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5548. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5549. ) //S_PRECHARGE
  5550. {
  5551. currentStatus = Preparing; //OCPP Status: Preparing
  5552. }
  5553. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5554. {
  5555. currentStatus = Charging; //OCPP Status: Charging
  5556. }
  5557. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5558. {
  5559. currentStatus = Finishing; //OCPP Status: Finishing
  5560. }
  5561. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5562. {
  5563. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5564. }
  5565. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (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
  5566. {
  5567. currentStatus = Unavailable; //OCPP Status: Unavailable
  5568. }
  5569. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5570. {
  5571. currentStatus = Faulted; //OCPP Status: Faulted
  5572. }
  5573. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5574. {
  5575. currentStatus = Reserved; //OCPP Status: Reserved
  5576. }
  5577. } //end of the same index
  5578. }//end of for CHAdeMO_QUANTITY
  5579. }
  5580. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5581. {
  5582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5583. {
  5584. tempIndex = ((gun_index==2) ? 1: 0);
  5585. }
  5586. else
  5587. {
  5588. tempIndex = gun_index;
  5589. }
  5590. for (int index = 0; index < CCS_QUANTITY; index++)
  5591. {
  5592. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5593. {
  5594. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5595. {
  5596. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5597. {
  5598. currentStatus = Preparing; //OCPP Status: Preparing
  5599. }
  5600. else
  5601. {
  5602. currentStatus = Available; //OCPP Status: Available
  5603. }
  5604. }
  5605. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5606. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5607. ) //S_PRECHARGE
  5608. {
  5609. currentStatus = Preparing; //OCPP Status: Preparing
  5610. }
  5611. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5612. {
  5613. currentStatus = Charging; //OCPP Status: Charging
  5614. }
  5615. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5616. {
  5617. currentStatus = Finishing; //OCPP Status: Finishing
  5618. }
  5619. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5620. {
  5621. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5622. }
  5623. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (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
  5624. {
  5625. currentStatus = Unavailable; //OCPP Status : Unavailable
  5626. }
  5627. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5628. {
  5629. currentStatus = Faulted; //OCPP Status: Faulted
  5630. }
  5631. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5632. {
  5633. currentStatus = Reserved; //OCPP Status: Reserved
  5634. }
  5635. } //end of the same index
  5636. } // end of for CCS_QUANTITY
  5637. }
  5638. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5639. {
  5640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5641. {
  5642. tempIndex = ((gun_index==2) ? 1: 0);
  5643. }
  5644. else
  5645. {
  5646. tempIndex = gun_index;
  5647. }
  5648. for (int index = 0; index < GB_QUANTITY; index++)
  5649. {
  5650. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5651. {
  5652. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5653. {
  5654. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5655. {
  5656. currentStatus = Preparing; //OCPP Status: Preparing
  5657. }
  5658. else
  5659. {
  5660. currentStatus = Available; //OCPP Status: Available
  5661. }
  5662. }
  5663. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5664. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5665. ) //S_PRECHARGE
  5666. {
  5667. currentStatus = Preparing; //OCPP Status: Preparing
  5668. }
  5669. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5670. {
  5671. currentStatus = Charging; //OCPP Status: Charging
  5672. }
  5673. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5674. {
  5675. currentStatus = Finishing; //OCPP Status: Finishing
  5676. }
  5677. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5678. {
  5679. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5680. }
  5681. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (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
  5682. {
  5683. currentStatus = Unavailable; //OCPP Status: Unavailable
  5684. }
  5685. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5686. {
  5687. currentStatus = Faulted; //OCPP Status: Faulted
  5688. }
  5689. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5690. {
  5691. currentStatus = Reserved; //OCPP Status: Reserved
  5692. }
  5693. } //end of the same index
  5694. } // end of for GB_QUANTITY
  5695. }
  5696. else if(gunType[gun_index] == GUN_TYPE_DO)
  5697. {
  5698. tempIndex = gun_index;
  5699. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5700. {
  5701. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5702. {
  5703. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5704. {
  5705. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5706. {
  5707. currentStatus = Preparing; //OCPP Status: Preparing
  5708. }
  5709. else
  5710. {
  5711. currentStatus = Available; //OCPP Status: Available
  5712. }
  5713. }
  5714. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5715. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5716. ) //S_PRECHARGE
  5717. {
  5718. currentStatus = Preparing; //OCPP Status: Preparing
  5719. }
  5720. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5721. {
  5722. currentStatus = Charging; //OCPP Status: Charging
  5723. }
  5724. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5725. {
  5726. currentStatus = Finishing; //OCPP Status: Finishing
  5727. }
  5728. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5729. {
  5730. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5731. }
  5732. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (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
  5733. {
  5734. currentStatus = Unavailable; //OCPP Status: Unavailable
  5735. }
  5736. 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
  5737. {
  5738. currentStatus = Faulted; //OCPP Status: Faulted
  5739. }
  5740. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5741. {
  5742. currentStatus = Reserved; //OCPP Status: Reserved
  5743. }
  5744. } //end of the same index
  5745. }
  5746. }
  5747. else
  5748. {
  5749. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5750. {
  5751. tempIndex = 2;
  5752. }
  5753. else
  5754. {
  5755. tempIndex = gun_index;
  5756. }
  5757. for (int index = 0; index < AC_QUANTITY; index++)
  5758. {
  5759. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5760. {
  5761. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5762. {
  5763. 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))
  5764. {
  5765. currentStatus = Preparing; //OCPP Status: Preparing
  5766. }
  5767. else
  5768. {
  5769. currentStatus = Available; //OCPP Status: Available
  5770. }
  5771. }
  5772. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5773. {
  5774. currentStatus = Preparing; //OCPP Status: Preparing
  5775. }
  5776. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5777. {
  5778. currentStatus = Charging; //OCPP Status: Charging
  5779. }
  5780. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5781. {
  5782. currentStatus = Finishing; //OCPP Status: Finishing
  5783. }
  5784. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5785. {
  5786. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5787. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5788. else
  5789. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5790. }
  5791. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (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
  5792. {
  5793. currentStatus = Unavailable; //OCPP Status: Unavailable
  5794. }
  5795. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5796. {
  5797. currentStatus = Faulted; //OCPP Status: Faulted
  5798. }
  5799. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5800. {
  5801. currentStatus = Reserved; //OCPP Status: Reserved
  5802. }
  5803. }//end of the same index
  5804. }//end of for AC_QUANTITY
  5805. }
  5806. //it's option
  5807. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5808. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5809. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5810. {
  5811. isStateChanged = FALSE;
  5812. }
  5813. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5814. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5815. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5816. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5817. random_uuid(guid);
  5818. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5819. , MESSAGE_TYPE_CALL
  5820. , guid
  5821. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5822. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5823. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5824. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5825. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5826. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5827. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5828. if((server_sign == TRUE) && isStateChanged)
  5829. {
  5830. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5831. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5832. LWS_Send(message);
  5833. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5834. 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*/)
  5835. {
  5836. //DEBUG_ERROR("statusNotification mapitem pass");
  5837. result = PASS;
  5838. }
  5839. }
  5840. else
  5841. {
  5842. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5843. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5844. result = PASS;
  5845. }
  5846. return result;
  5847. }
  5848. int sendStopTransactionRequest(int gun_index)
  5849. {
  5850. mtrace();
  5851. int result = FAIL;
  5852. //char message[1500]={0};
  5853. char guid[37]={0};
  5854. char tempdata[65]={0};
  5855. int tempIndex = 0;
  5856. char TempStopTransaction[256];
  5857. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5858. //int idx_sample=0;
  5859. DEBUG_INFO("sendStopTransactionRequest \n");
  5860. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5861. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5862. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5863. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5865. {
  5866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5867. {
  5868. tempIndex = ((gun_index==2) ? 1: 0);
  5869. }
  5870. else
  5871. {
  5872. tempIndex = gun_index;
  5873. }
  5874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5875. {
  5876. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5877. {
  5878. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5879. }
  5880. }// END OF CHAdeMO_QUANTITY
  5881. }
  5882. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5883. {
  5884. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5885. {
  5886. tempIndex = ((gun_index==2) ? 1: 0);
  5887. }
  5888. else
  5889. {
  5890. tempIndex = gun_index;
  5891. }
  5892. for (int index = 0; index < CCS_QUANTITY; index++)
  5893. {
  5894. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5895. {
  5896. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5897. }
  5898. }// END OF CCS_QUANTITY
  5899. }
  5900. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5901. {
  5902. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5903. {
  5904. tempIndex = ((gun_index==2) ? 1: 0);
  5905. }
  5906. else
  5907. {
  5908. tempIndex = gun_index;
  5909. }
  5910. for (int index = 0; index < GB_QUANTITY; index++)
  5911. {
  5912. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5913. {
  5914. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5915. }
  5916. }// END OF GB_QUANTITY
  5917. }
  5918. else if(gunType[gun_index] == GUN_TYPE_DO)
  5919. {
  5920. tempIndex = gun_index;
  5921. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5922. {
  5923. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5924. {
  5925. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5926. }
  5927. }// END OF GB_QUANTITY
  5928. }
  5929. else
  5930. {
  5931. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5932. {
  5933. tempIndex = 2;
  5934. }
  5935. else
  5936. {
  5937. tempIndex = gun_index;
  5938. }
  5939. for (int index = 0; index < AC_QUANTITY; index++)
  5940. {
  5941. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5942. {
  5943. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5944. }
  5945. }// END OF AC_QUANTITY
  5946. }
  5947. //====================================== Stop Transaction Time =====================================================
  5948. struct timeval tmnow;
  5949. struct tm *tm;
  5950. char buf[28];//, usec_buf[6];
  5951. gettimeofday(&tmnow, NULL);
  5952. time_t t;
  5953. t = time(NULL);
  5954. /*UTC time and date*/
  5955. tm = gmtime(&t);
  5956. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5958. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5959. random_uuid(guid);
  5960. /***********************************transactionData******************************************************/
  5961. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5963. //=================================
  5964. // Transaction_Begin
  5965. //=================================
  5966. //=================================
  5967. // Transaction_End
  5968. //=================================
  5969. // ================================= Current.Import L1 ===============================================
  5970. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5971. {
  5972. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5973. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5974. {
  5975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5976. {
  5977. tempIndex = ((gun_index==2) ? 1: 0);
  5978. }
  5979. else
  5980. {
  5981. tempIndex = gun_index;
  5982. }
  5983. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5984. {
  5985. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5986. {
  5987. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5988. }
  5989. }// End of for CHAdeMO_QUANTITY
  5990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5991. }
  5992. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5993. {
  5994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5995. {
  5996. tempIndex = ((gun_index==2) ? 1: 0);
  5997. }
  5998. else
  5999. {
  6000. tempIndex = gun_index;
  6001. }
  6002. for (int index = 0; index < CCS_QUANTITY; index++)
  6003. {
  6004. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6005. {
  6006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6007. }
  6008. }// End of for CCS_QUANTITY
  6009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6010. }
  6011. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6012. {
  6013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6014. {
  6015. tempIndex = ((gun_index==2) ? 1: 0);
  6016. }
  6017. else
  6018. {
  6019. tempIndex = gun_index;
  6020. }
  6021. for (int index = 0; index < GB_QUANTITY; index++)
  6022. {
  6023. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6024. {
  6025. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6026. }
  6027. }// End of for GB_QUANTITY
  6028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6029. }
  6030. else if(gunType[gun_index] == GUN_TYPE_DO)
  6031. {
  6032. tempIndex = gun_index;
  6033. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6034. {
  6035. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6036. {
  6037. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6038. }
  6039. }
  6040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6041. }
  6042. else
  6043. {
  6044. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6045. {
  6046. tempIndex = 2;
  6047. }
  6048. else
  6049. {
  6050. tempIndex = gun_index;
  6051. }
  6052. for (int index = 0; index < AC_QUANTITY; index++)
  6053. {
  6054. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6055. {
  6056. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6057. }
  6058. }// End of for AC_QUANTITY
  6059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6060. }
  6061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6066. }
  6067. // ================================= Energy.Active.Import.Interval ==============================================
  6068. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6069. {
  6070. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6071. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6072. {
  6073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6074. {
  6075. tempIndex = ((gun_index==2) ? 1: 0);
  6076. }
  6077. else
  6078. {
  6079. tempIndex = gun_index;
  6080. }
  6081. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6082. {
  6083. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6084. {
  6085. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6086. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6087. }
  6088. }// END OF CHAdeMO_QUANTITY
  6089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6090. }
  6091. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6092. {
  6093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6094. {
  6095. tempIndex = ((gun_index==2) ? 1: 0);
  6096. }
  6097. else
  6098. {
  6099. tempIndex = gun_index;
  6100. }
  6101. for (int index = 0; index < CCS_QUANTITY; index++)
  6102. {
  6103. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6104. {
  6105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6106. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6107. }
  6108. }// END OF CCS_QUANTITY
  6109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6110. }
  6111. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6112. {
  6113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6114. {
  6115. tempIndex = ((gun_index==2) ? 1: 0);
  6116. }
  6117. else
  6118. {
  6119. tempIndex = gun_index;
  6120. }
  6121. for (int index = 0; index < GB_QUANTITY; index++)
  6122. {
  6123. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6124. {
  6125. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6126. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6127. }
  6128. }// END OF GB_QUANTITY
  6129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6130. }
  6131. else if(gunType[gun_index] == GUN_TYPE_DO)
  6132. {
  6133. tempIndex = gun_index;
  6134. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6135. {
  6136. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6137. {
  6138. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6139. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6140. }
  6141. }
  6142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6143. }
  6144. else
  6145. {
  6146. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6147. {
  6148. tempIndex = 2;
  6149. }
  6150. else
  6151. {
  6152. tempIndex = gun_index;
  6153. }
  6154. for (int index = 0; index < AC_QUANTITY; index++)
  6155. {
  6156. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6157. {
  6158. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6159. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6160. }
  6161. }// END OF AC_QUANTITY
  6162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6163. }
  6164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6169. }
  6170. //=================================== Power.Active.Import ==================================================
  6171. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6172. {
  6173. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6174. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6175. {
  6176. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6177. {
  6178. tempIndex = ((gun_index==2) ? 1: 0);
  6179. }
  6180. else
  6181. {
  6182. tempIndex = gun_index;
  6183. }
  6184. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6185. {
  6186. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6187. {
  6188. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6189. }
  6190. } // End for CHAdeMO_QUANTITY
  6191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6192. }
  6193. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6194. {
  6195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6196. {
  6197. tempIndex = ((gun_index==2) ? 1: 0);
  6198. }
  6199. else
  6200. {
  6201. tempIndex = gun_index;
  6202. }
  6203. for (int index = 0; index < CCS_QUANTITY; index++)
  6204. {
  6205. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6206. {
  6207. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6208. }
  6209. } // END for CCS_QUANTITY
  6210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6211. }
  6212. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6213. {
  6214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6215. {
  6216. tempIndex = ((gun_index==2) ? 1: 0);
  6217. }
  6218. else
  6219. {
  6220. tempIndex = gun_index;
  6221. }
  6222. for (int index = 0; index < GB_QUANTITY; index++)
  6223. {
  6224. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6225. {
  6226. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6227. }
  6228. }// END for GB_QUANTITY
  6229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6230. }
  6231. else if(gunType[gun_index] == GUN_TYPE_DO)
  6232. {
  6233. tempIndex = gun_index;
  6234. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6235. {
  6236. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6237. {
  6238. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6239. }
  6240. }
  6241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6242. }
  6243. else
  6244. {
  6245. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6246. {
  6247. tempIndex = 2;
  6248. }
  6249. else
  6250. {
  6251. tempIndex = gun_index;
  6252. }
  6253. for (int index = 0; index < AC_QUANTITY; index++)
  6254. {
  6255. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6256. {
  6257. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6258. }
  6259. } // END for AC_QUANTITY
  6260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6261. }
  6262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6267. }
  6268. //============================ Voltage L1 ====================================
  6269. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6270. {
  6271. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6272. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6273. {
  6274. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6275. {
  6276. tempIndex = ((gun_index==2) ? 1: 0);
  6277. }
  6278. else
  6279. {
  6280. tempIndex = gun_index;
  6281. }
  6282. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6283. {
  6284. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6285. {
  6286. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6287. }
  6288. } // END OF FOR CHAdeMO_QUANTITY
  6289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6290. }
  6291. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6292. {
  6293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6294. {
  6295. tempIndex = ((gun_index==2) ? 1: 0);
  6296. }
  6297. else
  6298. {
  6299. tempIndex = gun_index;
  6300. }
  6301. for (int index = 0; index < CCS_QUANTITY; index++)
  6302. {
  6303. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6304. {
  6305. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6306. }
  6307. } // END OF FOR CCS_QUANTITY
  6308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6309. }
  6310. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6311. {
  6312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6313. {
  6314. tempIndex = ((gun_index==2) ? 1: 0);
  6315. }
  6316. else
  6317. {
  6318. tempIndex = gun_index;
  6319. }
  6320. for (int index = 0; index < GB_QUANTITY; index++)
  6321. {
  6322. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6323. {
  6324. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6325. }
  6326. } // END OF FOR GB_QUANTITY
  6327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6328. }
  6329. else if(gunType[gun_index] == GUN_TYPE_DO)
  6330. {
  6331. tempIndex = gun_index;
  6332. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6333. {
  6334. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6335. {
  6336. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6337. }
  6338. }
  6339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6340. }
  6341. else
  6342. {
  6343. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6344. {
  6345. tempIndex = 2;
  6346. }
  6347. else
  6348. {
  6349. tempIndex = gun_index;
  6350. }
  6351. for (int index = 0; index < AC_QUANTITY; index++)
  6352. {
  6353. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6354. {
  6355. 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
  6356. }
  6357. } // END OF FOR AC_QUANTITY
  6358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6359. }
  6360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6365. }
  6366. //====================== End SoC ================================
  6367. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6368. {
  6369. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6370. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6371. {
  6372. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6373. {
  6374. tempIndex = ((gun_index==2) ? 1: 0);
  6375. }
  6376. else
  6377. {
  6378. tempIndex = gun_index;
  6379. }
  6380. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6381. {
  6382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6383. {
  6384. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6385. {
  6386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6387. }
  6388. }
  6389. }
  6390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6391. {
  6392. for (int index = 0; index < CCS_QUANTITY; index++)
  6393. {
  6394. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6395. {
  6396. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6397. }
  6398. }
  6399. }
  6400. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6401. {
  6402. for (int index = 0; index < GB_QUANTITY; index++)
  6403. {
  6404. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6405. {
  6406. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6407. }
  6408. }
  6409. }
  6410. else if(gunType[gun_index] == GUN_TYPE_DO)
  6411. {
  6412. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6413. {
  6414. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6415. {
  6416. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6417. }
  6418. }
  6419. }
  6420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6426. } // END FOR DC CASE
  6427. }
  6428. // ================================= Current.Import L2 ===============================================
  6429. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6430. {
  6431. // AC 3 phse L2 current
  6432. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6433. {
  6434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6435. {
  6436. tempIndex = 2;
  6437. }
  6438. else
  6439. {
  6440. tempIndex = gun_index;
  6441. }
  6442. for (int index = 0; index < AC_QUANTITY; index++)
  6443. {
  6444. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6445. {
  6446. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6447. }
  6448. }// End of for AC_QUANTITY
  6449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6450. }
  6451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6456. }
  6457. // ================================= Current.Import L3 ===============================================
  6458. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6459. {
  6460. // AC 3 phse L3 current
  6461. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6462. {
  6463. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6464. {
  6465. tempIndex = 2;
  6466. }
  6467. else
  6468. {
  6469. tempIndex = gun_index;
  6470. }
  6471. for (int index = 0; index < AC_QUANTITY; index++)
  6472. {
  6473. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6474. {
  6475. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6476. }
  6477. }// End of for AC_QUANTITY
  6478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6479. }
  6480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6485. }
  6486. //============================ Voltage L2 ====================================
  6487. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6488. {
  6489. // AC 3 phse L2 voltage
  6490. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6491. {
  6492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6493. {
  6494. tempIndex = 2;
  6495. }
  6496. else
  6497. {
  6498. tempIndex = gun_index;
  6499. }
  6500. for (int index = 0; index < AC_QUANTITY; index++)
  6501. {
  6502. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6503. {
  6504. 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
  6505. }
  6506. } // END OF FOR AC_QUANTITY
  6507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6508. }
  6509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6514. }
  6515. //============================ Voltage L3 ====================================
  6516. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6517. {
  6518. // AC 3 phse L3 voltage
  6519. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6520. {
  6521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6522. {
  6523. tempIndex = 2;
  6524. }
  6525. else
  6526. {
  6527. tempIndex = gun_index;
  6528. }
  6529. for (int index = 0; index < AC_QUANTITY; index++)
  6530. {
  6531. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6532. {
  6533. 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
  6534. }
  6535. } // END OF FOR AC_QUANTITY
  6536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6537. }
  6538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6543. }
  6544. //====================== Start SoC ================================
  6545. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6546. {
  6547. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6548. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6549. {
  6550. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6551. {
  6552. tempIndex = ((gun_index==2) ? 1: 0);
  6553. }
  6554. else
  6555. {
  6556. tempIndex = gun_index;
  6557. }
  6558. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6559. {
  6560. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6561. {
  6562. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6563. {
  6564. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6565. }
  6566. }
  6567. }
  6568. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6569. {
  6570. for (int index = 0; index < CCS_QUANTITY; index++)
  6571. {
  6572. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6573. {
  6574. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6575. }
  6576. }
  6577. }
  6578. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6579. {
  6580. for (int index = 0; index < GB_QUANTITY; index++)
  6581. {
  6582. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6583. {
  6584. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6585. }
  6586. }
  6587. }
  6588. else if(gunType[gun_index] == GUN_TYPE_DO)
  6589. {
  6590. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6591. {
  6592. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6593. {
  6594. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6595. }
  6596. }
  6597. }
  6598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6604. } // END FOR DC CASE
  6605. }
  6606. //================================================ Message create ====================================================
  6607. json_object *StopTransaction = json_object_new_object();
  6608. json_object *transactionDatas = json_object_new_array();
  6609. json_object *sampledValues = json_object_new_array();
  6610. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6611. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6612. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6613. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6614. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6615. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6616. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6617. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6618. {
  6619. json_object *transactionData = json_object_new_object();
  6620. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6621. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6622. {
  6623. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6624. {
  6625. json_object *sampledValue = json_object_new_object();
  6626. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6627. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6628. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6629. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6630. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6631. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6632. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6633. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6634. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6635. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6636. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6637. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6638. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6639. json_object_array_add(sampledValues, sampledValue);
  6640. }
  6641. }
  6642. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6643. json_object_array_add(transactionDatas, transactionData);
  6644. }
  6645. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6646. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6647. ,MESSAGE_TYPE_CALL
  6648. ,guid
  6649. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6650. json_object_put(StopTransaction);
  6651. #if 1 // for TempStopTransaction
  6652. //Delete TempStopTransaction
  6653. if((access(TempStopTransaction,F_OK))!=-1)
  6654. {
  6655. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6656. }
  6657. #endif
  6658. #if 1
  6659. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6660. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6661. {
  6662. result = PASS;
  6663. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6664. }
  6665. #endif
  6666. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6667. OCPP_insert_transaction_msg(NO, queuedata);
  6668. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6669. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6670. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6671. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6672. {
  6673. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6674. }
  6675. //for test
  6676. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6677. return result;
  6678. }
  6679. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6680. {
  6681. mtrace();
  6682. int result = FAIL;
  6683. char guid[37]={0};
  6684. char tempdata[65]={0};
  6685. int tempIndex = 0;
  6686. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6687. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6688. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6689. //set value
  6690. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6691. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6692. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6693. -1);
  6694. random_uuid(guid);
  6695. //UTC Date time
  6696. struct timeval tmnow;
  6697. struct tm *tm;
  6698. char buf[28];//, usec_buf[6];
  6699. gettimeofday(&tmnow, NULL);
  6700. time_t t;
  6701. t = time(NULL);
  6702. /*UTC time and date*/
  6703. tm = gmtime(&t);
  6704. if(dataType == ReadingContext_Sample_Clock)
  6705. {
  6706. struct tm *tmTarget;
  6707. struct timeb tbTarget;
  6708. tbTarget.time = mktime(tm);
  6709. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6710. tmTarget = gmtime(&tbTarget.time);
  6711. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6712. }
  6713. else
  6714. {
  6715. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6716. }
  6717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6718. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6719. //********************************(1)Current.Import L1************************************************/
  6720. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6721. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6722. (dataType == ReadingContext_Trigger))
  6723. {
  6724. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6725. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6726. {
  6727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6728. {
  6729. tempIndex = ((gun_index==2) ? 1: 0);
  6730. }
  6731. else
  6732. {
  6733. tempIndex = gun_index;
  6734. }
  6735. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6736. {
  6737. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6738. {
  6739. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6740. }
  6741. }
  6742. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6743. }
  6744. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6745. {
  6746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6747. {
  6748. tempIndex = ((gun_index==2) ? 1: 0);
  6749. }
  6750. else
  6751. {
  6752. tempIndex = gun_index;
  6753. }
  6754. for (int index = 0; index < CCS_QUANTITY; index++)
  6755. {
  6756. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6757. {
  6758. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6759. }
  6760. }
  6761. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6762. }
  6763. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6764. {
  6765. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6766. {
  6767. tempIndex = ((gun_index==2) ? 1: 0);
  6768. }
  6769. else
  6770. {
  6771. tempIndex = gun_index;
  6772. }
  6773. for (int index = 0; index < GB_QUANTITY; index++)
  6774. {
  6775. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6776. {
  6777. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6778. }
  6779. }
  6780. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6781. }
  6782. else if(gunType[gun_index] == GUN_TYPE_DO)
  6783. {
  6784. tempIndex = gun_index;
  6785. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6786. {
  6787. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6788. {
  6789. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6790. }
  6791. }
  6792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6793. }
  6794. else
  6795. {
  6796. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6797. {
  6798. tempIndex = 2;
  6799. }
  6800. else
  6801. {
  6802. tempIndex = gun_index;
  6803. }
  6804. for (int index = 0; index < AC_QUANTITY; index++)
  6805. {
  6806. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6807. {
  6808. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6809. }
  6810. }
  6811. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6812. }
  6813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6815. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6816. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6818. }
  6819. //********************************(2)Energy.Active.Import.Register ************************************************/
  6820. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6821. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6822. (dataType == ReadingContext_Trigger))
  6823. {
  6824. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6825. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6826. {
  6827. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6828. {
  6829. tempIndex = ((gun_index==2) ? 1: 0);
  6830. }
  6831. else
  6832. {
  6833. tempIndex = gun_index;
  6834. }
  6835. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6836. {
  6837. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6838. {
  6839. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6840. }
  6841. }
  6842. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6843. }
  6844. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6845. {
  6846. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6847. {
  6848. tempIndex = ((gun_index==2) ? 1: 0);
  6849. }
  6850. else
  6851. {
  6852. tempIndex = gun_index;
  6853. }
  6854. for (int index = 0; index < CCS_QUANTITY; index++)
  6855. {
  6856. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6857. {
  6858. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6859. }
  6860. }
  6861. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6862. }
  6863. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6864. {
  6865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6866. {
  6867. tempIndex = ((gun_index==2) ? 1: 0);
  6868. }
  6869. else
  6870. {
  6871. tempIndex = gun_index;
  6872. }
  6873. for (int index = 0; index < GB_QUANTITY; index++)
  6874. {
  6875. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6876. {
  6877. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6878. }
  6879. }
  6880. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6881. }
  6882. else if(gunType[gun_index] == GUN_TYPE_DO)
  6883. {
  6884. tempIndex = gun_index;
  6885. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6886. {
  6887. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6888. {
  6889. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6890. }
  6891. }
  6892. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6893. }
  6894. else
  6895. {
  6896. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6897. {
  6898. tempIndex = 2;
  6899. }
  6900. else
  6901. {
  6902. tempIndex = gun_index;
  6903. }
  6904. for (int index = 0; index < AC_QUANTITY; index++)
  6905. {
  6906. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6907. {
  6908. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6909. }
  6910. }
  6911. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6912. }
  6913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6918. }
  6919. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6920. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6921. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6922. (dataType == ReadingContext_Trigger))
  6923. {
  6924. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6925. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6926. {
  6927. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6928. {
  6929. tempIndex = ((gun_index==2) ? 1: 0);
  6930. }
  6931. else
  6932. {
  6933. tempIndex = gun_index;
  6934. }
  6935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6936. {
  6937. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6938. {
  6939. if(dataType == ReadingContext_Sample_Clock)
  6940. {
  6941. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6942. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6943. }
  6944. else if(dataType == ReadingContext_Sample_Periodic)
  6945. {
  6946. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6947. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6948. }
  6949. else
  6950. {
  6951. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6952. }
  6953. }
  6954. } // END OF FOR CHAdeMO_QUANTITY
  6955. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6956. }
  6957. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6958. {
  6959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6960. {
  6961. tempIndex = ((gun_index==2) ? 1: 0);
  6962. }
  6963. else
  6964. {
  6965. tempIndex = gun_index;
  6966. }
  6967. for (int index = 0; index < CCS_QUANTITY; index++)
  6968. {
  6969. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6970. {
  6971. if(dataType == ReadingContext_Sample_Clock)
  6972. {
  6973. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6974. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6975. }
  6976. else if(dataType == ReadingContext_Sample_Periodic)
  6977. {
  6978. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6979. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6980. }
  6981. else
  6982. {
  6983. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6984. }
  6985. }
  6986. } // END OF CCS_QUANTITY
  6987. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6988. }
  6989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6990. {
  6991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6992. {
  6993. tempIndex = ((gun_index==2) ? 1: 0);
  6994. }
  6995. else
  6996. {
  6997. tempIndex = gun_index;
  6998. }
  6999. for (int index = 0; index < GB_QUANTITY; index++)
  7000. {
  7001. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7002. {
  7003. if(dataType == ReadingContext_Sample_Clock)
  7004. {
  7005. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7006. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7007. }
  7008. else if(dataType == ReadingContext_Sample_Periodic)
  7009. {
  7010. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7011. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7012. }
  7013. else
  7014. {
  7015. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7016. }
  7017. }
  7018. } // END OF GB_QUANTITY
  7019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7020. }
  7021. else if(gunType[gun_index] == GUN_TYPE_DO)
  7022. {
  7023. tempIndex = gun_index;
  7024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7025. {
  7026. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7027. {
  7028. if(dataType == ReadingContext_Sample_Clock)
  7029. {
  7030. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7031. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7032. }
  7033. else if(dataType == ReadingContext_Sample_Periodic)
  7034. {
  7035. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7036. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7037. }
  7038. else
  7039. {
  7040. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7041. }
  7042. }
  7043. }
  7044. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7045. }
  7046. else
  7047. {
  7048. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7049. {
  7050. tempIndex = 2;
  7051. }
  7052. else
  7053. {
  7054. tempIndex = gun_index;
  7055. }
  7056. for (int index = 0; index < AC_QUANTITY; index++)
  7057. {
  7058. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7059. {
  7060. if(dataType == ReadingContext_Sample_Clock)
  7061. {
  7062. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7063. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7064. }
  7065. else if(dataType == ReadingContext_Sample_Periodic)
  7066. {
  7067. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7068. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7069. }
  7070. else
  7071. {
  7072. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7073. }
  7074. }
  7075. }
  7076. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7077. }
  7078. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7079. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7080. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7081. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7082. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7083. }
  7084. //********************************(4)Power.Active.Import************************************************/
  7085. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7086. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7087. (dataType == ReadingContext_Trigger))
  7088. {
  7089. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7090. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7091. {
  7092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7093. {
  7094. tempIndex = ((gun_index==2) ? 1: 0);
  7095. }
  7096. else
  7097. {
  7098. tempIndex = gun_index;
  7099. }
  7100. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7101. {
  7102. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7103. {
  7104. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7105. }
  7106. } // END OF FOR
  7107. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7108. }
  7109. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7110. {
  7111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7112. {
  7113. tempIndex = ((gun_index==2) ? 1: 0);
  7114. }
  7115. else
  7116. {
  7117. tempIndex = gun_index;
  7118. }
  7119. for (int index = 0; index < CCS_QUANTITY; index++)
  7120. {
  7121. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7122. {
  7123. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7124. }
  7125. }
  7126. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7127. }
  7128. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7129. {
  7130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7131. {
  7132. tempIndex = ((gun_index==2) ? 1: 0);
  7133. }
  7134. else
  7135. {
  7136. tempIndex = gun_index;
  7137. }
  7138. for (int index = 0; index < GB_QUANTITY; index++)
  7139. {
  7140. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7141. {
  7142. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7143. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7144. }
  7145. }
  7146. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7147. }
  7148. else if(gunType[gun_index] == GUN_TYPE_DO)
  7149. {
  7150. tempIndex = gun_index;
  7151. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7152. {
  7153. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7154. {
  7155. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7156. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7157. }
  7158. }
  7159. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7160. }
  7161. else
  7162. {
  7163. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7164. {
  7165. tempIndex = 2;
  7166. }
  7167. else
  7168. {
  7169. tempIndex = gun_index;
  7170. }
  7171. for (int index = 0; index < AC_QUANTITY; index++)
  7172. {
  7173. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7174. {
  7175. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7176. }
  7177. }
  7178. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7179. }
  7180. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7182. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7184. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7185. }
  7186. //***********************************************(5)VOLTAGE L1******************************************************/
  7187. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7188. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7189. (dataType == ReadingContext_Trigger))
  7190. {
  7191. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7192. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7193. {
  7194. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7195. {
  7196. tempIndex = ((gun_index==2) ? 1: 0);
  7197. }
  7198. else
  7199. {
  7200. tempIndex = gun_index;
  7201. }
  7202. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7203. {
  7204. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7205. {
  7206. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7207. }
  7208. }
  7209. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7210. }
  7211. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7212. {
  7213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7214. {
  7215. tempIndex = ((gun_index==2) ? 1: 0);
  7216. }
  7217. else
  7218. {
  7219. tempIndex = gun_index;
  7220. }
  7221. for (int index = 0; index < CCS_QUANTITY; index++)
  7222. {
  7223. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7224. {
  7225. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7226. }
  7227. }
  7228. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7229. }
  7230. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7231. {
  7232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7233. {
  7234. tempIndex = ((gun_index==2) ? 1: 0);
  7235. }
  7236. else
  7237. {
  7238. tempIndex = gun_index;
  7239. }
  7240. for (int index = 0; index < GB_QUANTITY; index++)
  7241. {
  7242. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7243. {
  7244. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7245. }
  7246. }
  7247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7248. }
  7249. else if(gunType[gun_index] == GUN_TYPE_DO)
  7250. {
  7251. tempIndex = gun_index;
  7252. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7253. {
  7254. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7255. {
  7256. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7257. }
  7258. }
  7259. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7260. }
  7261. else
  7262. {
  7263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7264. {
  7265. tempIndex = 2;
  7266. }
  7267. else
  7268. {
  7269. tempIndex = gun_index;
  7270. }
  7271. for (int index = 0; index < AC_QUANTITY; index++)
  7272. {
  7273. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7274. {
  7275. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7276. }
  7277. }
  7278. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7279. }
  7280. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7281. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7284. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7285. }
  7286. //***********************************************(6)SOC******************************************************/
  7287. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7288. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7289. (dataType == ReadingContext_Trigger))
  7290. {
  7291. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  7292. {
  7293. //idx_sample=5;
  7294. //sampledValue = NULL;
  7295. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7296. {
  7297. tempIndex = ((gun_index==2) ? 1: 0);
  7298. }
  7299. else
  7300. {
  7301. tempIndex = gun_index;
  7302. }
  7303. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7304. {
  7305. //tempIndex = ((gun_index==2) ? 1: 0);
  7306. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7307. {
  7308. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7309. {
  7310. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7311. }
  7312. }
  7313. }
  7314. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7315. {
  7316. //tempIndex = ((gun_index==2) ? 1: 0);
  7317. for (int index = 0; index < CCS_QUANTITY; index++)
  7318. {
  7319. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7320. {
  7321. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7322. }
  7323. }
  7324. }
  7325. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7326. {
  7327. //tempIndex = ((gun_index==2) ? 1: 0);
  7328. for (int index = 0; index < GB_QUANTITY; index++)
  7329. {
  7330. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7331. {
  7332. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7333. }
  7334. }
  7335. }
  7336. else if(gunType[gun_index] == GUN_TYPE_DO)
  7337. {
  7338. //tempIndex = ((gun_index==2) ? 1: 0);
  7339. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7340. {
  7341. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7342. {
  7343. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7344. }
  7345. }
  7346. }
  7347. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7348. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7349. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7350. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7353. }
  7354. }
  7355. //********************************(7)Current.Import L2************************************************/
  7356. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7357. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7358. (dataType == ReadingContext_Trigger))
  7359. {
  7360. // Only for AC 3 phase
  7361. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7362. {
  7363. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7364. {
  7365. tempIndex = 2;
  7366. }
  7367. else
  7368. {
  7369. tempIndex = gun_index;
  7370. }
  7371. for (int index = 0; index < AC_QUANTITY; index++)
  7372. {
  7373. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7374. {
  7375. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7376. }
  7377. }
  7378. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7379. }
  7380. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7381. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7382. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7383. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7384. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7385. }
  7386. //********************************(8)Current.Import L3************************************************/
  7387. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7388. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7389. (dataType == ReadingContext_Trigger))
  7390. {
  7391. // Only for AC 3 phase
  7392. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7393. {
  7394. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7395. {
  7396. tempIndex = 2;
  7397. }
  7398. else
  7399. {
  7400. tempIndex = gun_index;
  7401. }
  7402. for (int index = 0; index < AC_QUANTITY; index++)
  7403. {
  7404. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7405. {
  7406. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7407. }
  7408. }
  7409. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7410. }
  7411. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7412. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7413. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7416. }
  7417. //***********************************************(9)VOLTAGE L2******************************************************/
  7418. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7419. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7420. (dataType == ReadingContext_Trigger))
  7421. {
  7422. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7423. {
  7424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7425. {
  7426. tempIndex = 2;
  7427. }
  7428. else
  7429. {
  7430. tempIndex = gun_index;
  7431. }
  7432. for (int index = 0; index < AC_QUANTITY; index++)
  7433. {
  7434. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7435. {
  7436. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7437. }
  7438. }
  7439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7440. }
  7441. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7442. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7446. }
  7447. //***********************************************(10)VOLTAGE L3******************************************************/
  7448. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7449. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7450. (dataType == ReadingContext_Trigger))
  7451. {
  7452. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7453. {
  7454. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7455. {
  7456. tempIndex = 2;
  7457. }
  7458. else
  7459. {
  7460. tempIndex = gun_index;
  7461. }
  7462. for (int index = 0; index < AC_QUANTITY; index++)
  7463. {
  7464. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7465. {
  7466. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7467. }
  7468. }
  7469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7470. }
  7471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7474. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7475. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7476. }
  7477. //***********************************************(11)Current.Offered******************************************************/
  7478. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7479. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7480. (dataType == ReadingContext_Trigger))
  7481. {
  7482. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7483. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7484. {
  7485. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7486. {
  7487. tempIndex = ((gun_index==2) ? 1: 0);
  7488. }
  7489. else
  7490. {
  7491. tempIndex = gun_index;
  7492. }
  7493. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7494. {
  7495. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7496. {
  7497. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7498. }
  7499. } // END OF FOR CHAdeMO_QUANTITY
  7500. }
  7501. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7502. {
  7503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7504. {
  7505. tempIndex = ((gun_index==2) ? 1: 0);
  7506. }
  7507. else
  7508. {
  7509. tempIndex = gun_index;
  7510. }
  7511. for (int index = 0; index < CCS_QUANTITY; index++)
  7512. {
  7513. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7514. {
  7515. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7516. }
  7517. } // END OF CCS_QUANTITY
  7518. }
  7519. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7520. {
  7521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7522. {
  7523. tempIndex = ((gun_index==2) ? 1: 0);
  7524. }
  7525. else
  7526. {
  7527. tempIndex = gun_index;
  7528. }
  7529. for (int index = 0; index < GB_QUANTITY; index++)
  7530. {
  7531. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7532. {
  7533. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7534. }
  7535. } // END OF GB_QUANTITY
  7536. }
  7537. else if(gunType[gun_index] == GUN_TYPE_DO)
  7538. {
  7539. tempIndex = gun_index;
  7540. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7541. {
  7542. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7543. {
  7544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7545. }
  7546. }
  7547. }
  7548. else
  7549. {
  7550. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7551. {
  7552. tempIndex = 2;
  7553. }
  7554. else
  7555. {
  7556. tempIndex = gun_index;
  7557. }
  7558. for (int index = 0; index < AC_QUANTITY; index++)
  7559. {
  7560. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7561. {
  7562. uint16_t currentOffer;
  7563. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7564. {
  7565. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7566. }
  7567. else
  7568. {
  7569. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7570. }
  7571. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7572. }
  7573. }
  7574. }
  7575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7580. }
  7581. //***********************************************(12)Power.Offered******************************************************/
  7582. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7583. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7584. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7585. {
  7586. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7587. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7588. {
  7589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7590. {
  7591. tempIndex = ((gun_index==2) ? 1: 0);
  7592. }
  7593. else
  7594. {
  7595. tempIndex = gun_index;
  7596. }
  7597. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7598. {
  7599. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7600. {
  7601. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7602. }
  7603. } // END OF FOR CHAdeMO_QUANTITY
  7604. }
  7605. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7606. {
  7607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7608. {
  7609. tempIndex = ((gun_index==2) ? 1: 0);
  7610. }
  7611. else
  7612. {
  7613. tempIndex = gun_index;
  7614. }
  7615. for (int index = 0; index < CCS_QUANTITY; index++)
  7616. {
  7617. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7618. {
  7619. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7620. }
  7621. } // END OF CCS_QUANTITY
  7622. }
  7623. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7624. {
  7625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7626. {
  7627. tempIndex = ((gun_index==2) ? 1: 0);
  7628. }
  7629. else
  7630. {
  7631. tempIndex = gun_index;
  7632. }
  7633. for (int index = 0; index < GB_QUANTITY; index++)
  7634. {
  7635. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7636. {
  7637. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7638. }
  7639. } // END OF GB_QUANTITY
  7640. }
  7641. else if(gunType[gun_index] == GUN_TYPE_DO)
  7642. {
  7643. tempIndex = gun_index;
  7644. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7645. {
  7646. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7647. {
  7648. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7649. }
  7650. }
  7651. }
  7652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7657. }
  7658. // Message create ====================================================================================================
  7659. if(TRUE)
  7660. {
  7661. json_object *MeterValueReq = json_object_new_object();
  7662. json_object *MeterValues = json_object_new_array();
  7663. json_object *sampledValues = json_object_new_array();
  7664. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7665. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7666. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7667. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7668. {
  7669. json_object *MeterValue = json_object_new_object();
  7670. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7671. {
  7672. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7673. {
  7674. json_object *sampledValue = json_object_new_object();
  7675. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7676. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7677. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7678. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7679. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7680. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7681. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7682. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7683. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7684. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7685. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7686. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7687. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7688. json_object_array_add(sampledValues, sampledValue);
  7689. }
  7690. }
  7691. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7692. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7693. json_object_array_add(MeterValues, MeterValue);
  7694. }
  7695. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7696. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7697. ,gun_index + 1
  7698. ,MESSAGE_TYPE_CALL
  7699. ,guid
  7700. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7701. json_object_put(MeterValueReq);
  7702. }
  7703. // Put request guid to hash map
  7704. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7705. 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*/)
  7706. {
  7707. result = PASS;
  7708. //DEBUG_INFO("MeterValues mapitem pass\n");
  7709. }
  7710. if((dataType != ReadingContext_Trigger) &&
  7711. (dataType != ReadingContext_Sample_Clock) &&
  7712. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7713. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7714. else
  7715. {
  7716. if(FirstHeartBeat)
  7717. LWS_Send(queuedata +2);
  7718. }
  7719. return result;
  7720. }
  7721. int sendLogStatusNotificationRequest(char *status)
  7722. {
  7723. mtrace();
  7724. int result = PASS;
  7725. char message[4096]={0};
  7726. char guid[37]={0};
  7727. char tempdata[128]={0};
  7728. json_object *LogStatusNotification = json_object_new_object();
  7729. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7730. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7731. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7732. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7733. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7734. random_uuid(guid);
  7735. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7736. json_object_put(LogStatusNotification);
  7737. LWS_Send(message);
  7738. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7739. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7740. {
  7741. result = PASS;
  7742. }
  7743. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7744. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7745. return result;
  7746. }
  7747. int sendSecurityEventNotificationRequest()
  7748. {
  7749. mtrace();
  7750. int result = PASS;
  7751. char message[4096]={0};
  7752. char guid[37]={0};
  7753. char tempdata[128]={0};
  7754. json_object *SecurityEventNotification = json_object_new_object();
  7755. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7756. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7757. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7758. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7759. random_uuid(guid);
  7760. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7761. json_object_put(SecurityEventNotification);
  7762. LWS_Send(message);
  7763. sprintf(tempdata, "SecurityEventNotification,0");
  7764. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7765. {
  7766. result = PASS;
  7767. }
  7768. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7769. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7770. return result;
  7771. }
  7772. int sendSignCertificateRequest()
  7773. {
  7774. mtrace();
  7775. int result = PASS;
  7776. char message[4096]={0};
  7777. char guid[37]={0};
  7778. char tempdata[128]={0};
  7779. json_object *SignCertificate = json_object_new_object();
  7780. DEBUG_INFO("sendSignCertificateRequest...\n");
  7781. // Read csr file content
  7782. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7783. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7784. char *line = NULL;
  7785. size_t len = 0;
  7786. while(getline(&line, &len, fp) != -1)
  7787. {
  7788. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7789. {
  7790. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7791. }
  7792. }
  7793. fclose(fp);
  7794. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7795. random_uuid(guid);
  7796. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7797. json_object_put(SignCertificate);
  7798. LWS_Send(message);
  7799. sprintf(tempdata, "SignCertificate,0");
  7800. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7801. {
  7802. result = PASS;
  7803. }
  7804. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7805. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7806. return result;
  7807. }
  7808. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7809. {
  7810. mtrace();
  7811. int result = PASS;
  7812. char message[110]={0};
  7813. char guid[37]={0};
  7814. char tempdata[65]={0};
  7815. json_object *FirmwareStatusNotification = json_object_new_object();
  7816. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7817. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7818. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7819. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7820. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7821. random_uuid(guid);
  7822. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7823. json_object_put(FirmwareStatusNotification);
  7824. LWS_Send(message);
  7825. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7826. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7827. {
  7828. result = PASS;
  7829. }
  7830. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7831. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7832. return result;
  7833. }
  7834. //==========================================
  7835. // send confirm routine
  7836. //==========================================
  7837. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7838. {
  7839. mtrace();
  7840. int result = FAIL;
  7841. char message[100]={0};
  7842. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7843. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7844. LWS_Send(message);
  7845. result = TRUE;
  7846. return result;
  7847. }
  7848. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7849. {
  7850. mtrace();
  7851. int result = FAIL;
  7852. char message[100]={0};
  7853. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7854. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7855. LWS_Send(message);
  7856. result = TRUE;
  7857. return result;
  7858. }
  7859. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7860. {
  7861. mtrace();
  7862. int result = FAIL;
  7863. char message[100]={0};
  7864. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7865. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7866. LWS_Send(message);
  7867. result = TRUE;
  7868. return result;
  7869. }
  7870. int sendClearCacheConfirmation(char *uuid,char *payload)
  7871. {
  7872. mtrace();
  7873. int result = FAIL;
  7874. char message[500]={0};
  7875. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7876. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7877. LWS_Send(message);
  7878. return result;
  7879. }
  7880. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7881. {
  7882. mtrace();
  7883. int result = FAIL;
  7884. char message[500]={0};
  7885. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7886. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7887. LWS_Send(message);
  7888. return result;
  7889. }
  7890. int sendDataTransferConfirmation(char *uuid,char *payload)
  7891. {
  7892. mtrace();
  7893. char statusStr[20]={0};
  7894. char dataStr[10]={0};
  7895. char sstr[20]={0};
  7896. int c = 0;
  7897. char *loc;
  7898. int result = FAIL;
  7899. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7900. /**********************status**************************/
  7901. loc = strstr(payload, "status");
  7902. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7903. c = 0;
  7904. while (loc[3+strlen("status")+c] != '\"')
  7905. {
  7906. sstr[c] = loc[3+strlen("status")+c];
  7907. c++;
  7908. }
  7909. sstr[c] = '\0';
  7910. strcpy(statusStr, sstr);
  7911. /**********************data**************************/
  7912. loc = strstr(payload, "data");
  7913. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7914. c = 0;
  7915. while (loc[3+strlen("data")+c] != '\"')
  7916. {
  7917. sstr[c] = loc[3+strlen("data")+c];
  7918. c++;
  7919. }
  7920. sstr[c] = '\0';
  7921. strcpy(dataStr, sstr);
  7922. return result;
  7923. }
  7924. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7925. {
  7926. mtrace();
  7927. int result = FAIL;
  7928. char message[1000]={0};
  7929. int CompositeScheduleIndex = 0;
  7930. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7931. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7932. if(nPeriod == 0)
  7933. {
  7934. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7935. {
  7936. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7937. ,MESSAGE_TYPE_CALLRESULT
  7938. ,uuid
  7939. ,payload
  7940. ,connectorIdInt);
  7941. }
  7942. else
  7943. {
  7944. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7945. ,MESSAGE_TYPE_CALLRESULT
  7946. ,uuid
  7947. ,payload
  7948. ,connectorIdInt
  7949. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7950. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7951. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7952. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7953. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7954. }
  7955. }
  7956. else
  7957. {
  7958. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7959. ,MESSAGE_TYPE_CALLRESULT
  7960. ,uuid
  7961. ,payload
  7962. ,connectorIdInt
  7963. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7964. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7965. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7966. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7967. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7968. {
  7969. if (idx_sample == 0)
  7970. {
  7971. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7972. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7973. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7974. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7975. }
  7976. else
  7977. {
  7978. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7979. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7980. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7981. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7982. }
  7983. }
  7984. sprintf(message + strlen(message), "]}}]");
  7985. }
  7986. LWS_Send(message);
  7987. result = TRUE;
  7988. return result;
  7989. }
  7990. int sendGetConfigurationConfirmation(char *uuid)
  7991. {
  7992. mtrace();
  7993. int result = FAIL;
  7994. int MaxKeySupported = 0;
  7995. int sentConfigurationNumber= 0;
  7996. int sentunConfigurationNumber= 0;
  7997. char message[1024*10]={0};
  7998. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7999. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8000. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8001. ,MESSAGE_TYPE_CALLRESULT
  8002. ,uuid );
  8003. //configuration key
  8004. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8005. {
  8006. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8007. {
  8008. if (sentConfigurationNumber == 0)
  8009. {
  8010. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8011. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8012. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8013. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8014. }
  8015. else
  8016. {
  8017. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8018. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8019. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8020. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8021. }
  8022. sentConfigurationNumber = sentConfigurationNumber + 1;
  8023. }
  8024. }
  8025. sprintf(message + strlen(message), "]");
  8026. if(UnknownKeynum != 0)
  8027. {
  8028. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8029. //unkown key
  8030. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8031. {
  8032. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8033. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8034. if(sentunConfigurationNumber == 0)
  8035. {
  8036. sprintf(message + strlen(message), "\"%s\""
  8037. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8038. }
  8039. else
  8040. {
  8041. sprintf(message + strlen(message), ",\"%s\""
  8042. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8043. }
  8044. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8045. }
  8046. sprintf(message + strlen(message), "]");
  8047. }
  8048. sprintf(message + strlen(message), "}]");
  8049. LWS_Send(message);
  8050. return result;
  8051. }
  8052. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8053. {
  8054. mtrace();
  8055. int result = FAIL;
  8056. char message[400]={0};
  8057. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8058. if(strcmp(payload,"")==0)
  8059. {
  8060. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8061. }
  8062. else
  8063. {
  8064. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8065. }
  8066. LWS_Send(message);
  8067. result = TRUE;
  8068. return result;
  8069. }
  8070. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8071. {
  8072. mtrace();
  8073. int result = FAIL;
  8074. char message[80]={0};
  8075. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8076. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8077. LWS_Send(message);
  8078. result = TRUE;
  8079. return result;
  8080. }
  8081. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8082. {
  8083. mtrace();
  8084. int result = FAIL;
  8085. char message[80]={0};
  8086. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8087. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8088. LWS_Send(message);
  8089. result = TRUE;
  8090. return result;
  8091. }
  8092. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8093. {
  8094. mtrace();
  8095. int result = FAIL;
  8096. char message[80]={0};
  8097. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8098. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8099. LWS_Send(message);
  8100. result = TRUE;
  8101. return result;
  8102. }
  8103. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8104. {
  8105. mtrace();
  8106. int result = FAIL;
  8107. char message[80]={0};
  8108. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8109. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8110. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8111. LWS_Send(message);
  8112. result = TRUE;
  8113. return result;
  8114. }
  8115. int sendResetConfirmation(char *uuid,char *payload)
  8116. {
  8117. mtrace();
  8118. int result = FAIL;
  8119. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8120. char message[80]={0};
  8121. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8122. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8123. LWS_Send(message);
  8124. result = TRUE;
  8125. return result;
  8126. }
  8127. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8128. {
  8129. mtrace();
  8130. int result = FAIL;
  8131. char message[500]={0};
  8132. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8133. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8134. LWS_Send(message);
  8135. result = TRUE;
  8136. return result;
  8137. }
  8138. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8139. {
  8140. mtrace();
  8141. int result = FAIL;
  8142. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8143. char message[80]={0};
  8144. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8145. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8146. LWS_Send(message);
  8147. result = TRUE;
  8148. return result;
  8149. }
  8150. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8151. {
  8152. mtrace();
  8153. int result = FAIL;
  8154. char message[80]={0};
  8155. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8156. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8157. LWS_Send(message);
  8158. result = TRUE;
  8159. return result;
  8160. }
  8161. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8162. {
  8163. mtrace();
  8164. int result = FAIL;
  8165. char message[80]={0};
  8166. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8167. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8168. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8169. LWS_Send(message);
  8170. result = TRUE;
  8171. return result;
  8172. }
  8173. int sendUpdateFirmwareConfirmation(char *uuid)
  8174. {
  8175. mtrace();
  8176. int result = FAIL;
  8177. char message[60]={0};
  8178. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8179. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8180. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8181. LWS_Send(message);
  8182. result = TRUE;
  8183. return result;
  8184. }
  8185. int sendCertificateSignedConfirmation(char *uuid)
  8186. {
  8187. mtrace();
  8188. int result = PASS;
  8189. char message[4096]={0};
  8190. json_object *CertificateSigned = json_object_new_object();
  8191. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8192. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8193. sprintf(message,"[%d,\"%s\",%s]"
  8194. ,MESSAGE_TYPE_CALLRESULT
  8195. ,uuid
  8196. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8197. json_object_put(CertificateSigned);
  8198. LWS_Send(message);
  8199. return result;
  8200. }
  8201. int sendDeleteCertificateConfirmation(char *uuid)
  8202. {
  8203. mtrace();
  8204. int result = PASS;
  8205. char message[4096]={0};
  8206. json_object *DeleteCertificate = json_object_new_object();
  8207. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8208. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8209. sprintf(message,"[%d,\"%s\",%s]"
  8210. ,MESSAGE_TYPE_CALLRESULT
  8211. ,uuid
  8212. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8213. json_object_put(DeleteCertificate);
  8214. LWS_Send(message);
  8215. return result;
  8216. }
  8217. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8218. {
  8219. mtrace();
  8220. int result = PASS;
  8221. char message[4096]={0};
  8222. json_object *ExtendedTriggerMessage = json_object_new_object();
  8223. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8224. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8225. sprintf(message,"[%d,\"%s\",%s]"
  8226. ,MESSAGE_TYPE_CALLRESULT
  8227. ,uuid
  8228. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8229. json_object_put(ExtendedTriggerMessage);
  8230. LWS_Send(message);
  8231. return result;
  8232. }
  8233. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8234. {
  8235. mtrace();
  8236. int result = PASS;
  8237. char message[4096]={0};
  8238. json_object *GetInstalledCertificateIds = json_object_new_object();
  8239. json_object *certificateHashDataDatas = json_object_new_array();
  8240. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8241. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8242. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8243. {
  8244. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8245. {
  8246. json_object *certificateHashData = json_object_new_object();
  8247. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8248. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8249. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8250. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8251. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8252. }
  8253. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8254. }
  8255. else
  8256. {
  8257. json_object_put(certificateHashDataDatas);
  8258. }
  8259. sprintf(message,"[%d,\"%s\",%s]"
  8260. ,MESSAGE_TYPE_CALLRESULT
  8261. ,uuid
  8262. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8263. json_object_put(GetInstalledCertificateIds);
  8264. LWS_Send(message);
  8265. return result;
  8266. }
  8267. int sendGetLogConfirmation(char *uuid)
  8268. {
  8269. mtrace();
  8270. int result = PASS;
  8271. char message[4096]={0};
  8272. json_object *GetLog = json_object_new_object();
  8273. DEBUG_INFO("sendGetLogConfirmation...\n");
  8274. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8275. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8276. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8277. sprintf(message,"[%d,\"%s\",%s]"
  8278. ,MESSAGE_TYPE_CALLRESULT
  8279. ,uuid
  8280. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8281. json_object_put(GetLog);
  8282. LWS_Send(message);
  8283. return result;
  8284. }
  8285. int sendInstallCertificateConfirmation(char *uuid)
  8286. {
  8287. mtrace();
  8288. int result = PASS;
  8289. char message[4096]={0};
  8290. json_object *InstallCertificate = json_object_new_object();
  8291. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8292. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8293. sprintf(message,"[%d,\"%s\",%s]"
  8294. ,MESSAGE_TYPE_CALLRESULT
  8295. ,uuid
  8296. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8297. json_object_put(InstallCertificate);
  8298. LWS_Send(message);
  8299. return result;
  8300. }
  8301. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8302. {
  8303. mtrace();
  8304. int result = PASS;
  8305. char message[4096]={0};
  8306. json_object *SignedUpdateFirmware = json_object_new_object();
  8307. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8308. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8309. sprintf(message,"[%d,\"%s\",%s]"
  8310. ,MESSAGE_TYPE_CALLRESULT
  8311. ,uuid
  8312. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8313. json_object_put(SignedUpdateFirmware);
  8314. LWS_Send(message);
  8315. return result;
  8316. }
  8317. int sendUnknownConfirmation(char *uuid)
  8318. {
  8319. mtrace();
  8320. int result = PASS;
  8321. char message[256]={0};
  8322. DEBUG_INFO("sendUnknownConfirmation...\n");
  8323. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8324. LWS_Send(message);
  8325. return result;
  8326. }
  8327. //==========================================
  8328. // Handle server request routine Start
  8329. //==========================================
  8330. int handleCancelReservationRequest(char *uuid, char *payload)
  8331. {
  8332. mtrace();
  8333. int result = FAIL;
  8334. int gunNO = 0;
  8335. int reservationIdInt = -1;
  8336. char comfirmstr[20];
  8337. DEBUG_INFO("handleCancelReservationRequest...\n");
  8338. json_object *CancelReservation;
  8339. CancelReservation = json_tokener_parse(payload);
  8340. if(!is_error(CancelReservation))
  8341. {
  8342. // Required data
  8343. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8344. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8345. }
  8346. json_object_put(CancelReservation);
  8347. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8348. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8349. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8350. if(reservationIdInt != -1)
  8351. {
  8352. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8353. //check Transaction active
  8354. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8356. {
  8357. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8358. {
  8359. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8360. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8361. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8362. {
  8363. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8364. }
  8365. else
  8366. {
  8367. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8368. }
  8369. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8370. goto end;
  8371. }
  8372. }
  8373. for (int index = 0; index < CCS_QUANTITY; index++)
  8374. {
  8375. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8376. {
  8377. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8378. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8379. if(gunType[2] == GUN_TYPE_CCS)
  8380. {
  8381. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8382. }
  8383. else
  8384. {
  8385. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8386. }
  8387. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8388. goto end;
  8389. }
  8390. }
  8391. for (int index = 0; index < GB_QUANTITY; index++)
  8392. {
  8393. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8394. {
  8395. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8396. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8397. if(gunType[2] == GUN_TYPE_GBT)
  8398. {
  8399. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8400. }
  8401. else
  8402. {
  8403. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8404. }
  8405. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8406. goto end;
  8407. }
  8408. }
  8409. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8410. {
  8411. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8412. {
  8413. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8414. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8415. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8416. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8417. goto end;
  8418. }
  8419. }
  8420. for (int index = 0; index < AC_QUANTITY; index++)
  8421. {
  8422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8423. {
  8424. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8425. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8426. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8427. {
  8428. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8429. }
  8430. else
  8431. {
  8432. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8433. }
  8434. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8435. goto end;
  8436. }
  8437. }
  8438. }
  8439. //The reservationId does NOT match the reservationId
  8440. sendCancelReservationConfirmation(uuid, comfirmstr);
  8441. end:
  8442. // Fill in ocpp packet uuid
  8443. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8444. return result;
  8445. }
  8446. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8447. {
  8448. mtrace();
  8449. int result = FAIL;
  8450. int gunIndex = -1;
  8451. char typeStr[16]={0};
  8452. char comfirmstr[20];
  8453. int specificId = FALSE;
  8454. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8455. json_object *ChangeAvailability;
  8456. ChangeAvailability = json_tokener_parse(payload);
  8457. if(!is_error(ChangeAvailability))
  8458. {
  8459. // Required data
  8460. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8461. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8462. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8463. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8464. }
  8465. json_object_put(ChangeAvailability);
  8466. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8467. {
  8468. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8469. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8470. }
  8471. else if(gunIndex == 0)
  8472. {
  8473. for(int i=0; i < gunTotalNumber; i++)
  8474. {
  8475. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8476. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8477. }
  8478. }
  8479. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8480. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8481. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8482. {
  8483. specificId = TRUE;
  8484. }
  8485. if(specificId == FALSE)
  8486. goto end;
  8487. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8488. {
  8489. //----------------------gunIndex is 0 ------------------------------------------------//
  8490. if(gunIndex == 0)
  8491. {
  8492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8493. {
  8494. for(int i=0; i < gunTotalNumber; i++)
  8495. {
  8496. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8497. {
  8498. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8499. {
  8500. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8501. {
  8502. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8503. goto end;
  8504. }
  8505. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8506. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8507. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8508. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8509. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8510. {
  8511. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8512. goto end;
  8513. }
  8514. }
  8515. }//END FOR CHAdeMO_QUANTITY
  8516. for (int index = 0; index < CCS_QUANTITY; index++)
  8517. {
  8518. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8519. {
  8520. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8521. {
  8522. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8523. goto end;
  8524. }
  8525. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8526. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8527. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8528. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8529. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8530. {
  8531. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8532. goto end;
  8533. }
  8534. }
  8535. }//END FOR CCS_QUANTITY
  8536. for (int index = 0; index < GB_QUANTITY; index++)
  8537. {
  8538. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8539. {
  8540. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8541. {
  8542. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8543. goto end;
  8544. }
  8545. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8546. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8547. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8548. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8549. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8550. {
  8551. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8552. goto end;
  8553. }
  8554. }
  8555. }// END FOR GB_QUANTITY
  8556. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8557. {
  8558. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8559. {
  8560. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8561. {
  8562. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8563. goto end;
  8564. }
  8565. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8566. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8567. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8568. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8569. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8570. {
  8571. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8572. goto end;
  8573. }
  8574. }
  8575. }// END FOR GENERAL_GUN_QUANTITY
  8576. for (int index = 0; index < AC_QUANTITY; index++)
  8577. {
  8578. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8579. {
  8580. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8581. {
  8582. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8583. goto end;
  8584. }
  8585. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8586. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8587. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8588. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8589. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8590. {
  8591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8592. goto end;
  8593. }
  8594. }
  8595. }//END FOR AC_QUANTITY
  8596. }// END FOR gunTotalNumber
  8597. }
  8598. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8599. {
  8600. for(int i=0; i < gunTotalNumber; i++)
  8601. {
  8602. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8603. {
  8604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8605. goto end;
  8606. }
  8607. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8608. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8609. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8610. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8611. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8612. {
  8613. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8614. goto end;
  8615. }
  8616. }
  8617. }
  8618. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8619. goto end;
  8620. }
  8621. //----------------------gunIndex is not 0 ------------------------------------------------//
  8622. //check Transaction active
  8623. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8624. {
  8625. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8626. {
  8627. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8628. {
  8629. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8630. goto end;
  8631. }
  8632. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8633. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8634. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8635. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8636. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8637. {
  8638. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8639. goto end;
  8640. }
  8641. else
  8642. {
  8643. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8644. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8645. goto end;
  8646. }
  8647. }
  8648. }//END FOR CHAdeMO_QUANTITY
  8649. for (int index = 0; index < CCS_QUANTITY; index++)
  8650. {
  8651. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8652. {
  8653. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8654. {
  8655. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8656. goto end;
  8657. }
  8658. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8659. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8660. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8661. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8662. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8663. {
  8664. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8665. goto end;
  8666. }
  8667. else
  8668. {
  8669. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8671. goto end;
  8672. }
  8673. }
  8674. }//END FOR CCS_QUANTITY
  8675. for (int index = 0; index < GB_QUANTITY; index++)
  8676. {
  8677. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8678. {
  8679. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8680. {
  8681. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8682. goto end;
  8683. }
  8684. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8685. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8686. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8687. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8688. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8689. {
  8690. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8691. goto end;
  8692. }
  8693. else
  8694. {
  8695. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8696. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8697. goto end;
  8698. }
  8699. }
  8700. }// END FOR GB_QUANTITY
  8701. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8702. {
  8703. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8704. {
  8705. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8706. {
  8707. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8708. goto end;
  8709. }
  8710. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8711. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8712. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8713. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8714. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8715. {
  8716. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8717. goto end;
  8718. }
  8719. else
  8720. {
  8721. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8722. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8723. goto end;
  8724. }
  8725. }
  8726. }// END FOR GENERAL_GUN_QUANTITY
  8727. for (int index = 0; index < AC_QUANTITY; index++)
  8728. {
  8729. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8730. {
  8731. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8732. {
  8733. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8734. goto end;
  8735. }
  8736. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8737. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8738. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8739. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8740. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8741. {
  8742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8743. goto end;
  8744. }
  8745. else
  8746. {
  8747. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8749. goto end;
  8750. }
  8751. }
  8752. }//END FOR AC_QUANTITY
  8753. }//END FOR AvailabilityTypeStr[Inoperative]
  8754. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8755. {
  8756. //----------------------gunIndex is 0 ------------------------------------------------//
  8757. if(gunIndex == 0)
  8758. {
  8759. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8760. {
  8761. for(int i=0; i < gunTotalNumber; i++)
  8762. {
  8763. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8764. {
  8765. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8766. {
  8767. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8768. goto end;
  8769. }
  8770. }//END FOR CHAdeMO_QUANTITY
  8771. for (int index = 0; index < CCS_QUANTITY; index++)
  8772. {
  8773. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8774. {
  8775. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8776. goto end;
  8777. }
  8778. }//END FOR CCS_QUANTITY
  8779. for (int index = 0; index < GB_QUANTITY; index++)
  8780. {
  8781. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8782. {
  8783. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8784. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8785. goto end;
  8786. }
  8787. }// END FOR GB_QUANTITY
  8788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8789. {
  8790. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8791. {
  8792. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8793. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8794. goto end;
  8795. }
  8796. }// END FOR GENERAL_GUN_QUANTITY
  8797. for (int index = 0; index < AC_QUANTITY; index++)
  8798. {
  8799. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8800. {
  8801. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8802. goto end;
  8803. }
  8804. }//END FOR CHAdeMO_QUANTITY
  8805. }// END FOR gunTotalNumber
  8806. }
  8807. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8808. {
  8809. for(int i=0; i < gunTotalNumber; i++)
  8810. {
  8811. for (int index = 0; index < AC_QUANTITY; index++)
  8812. {
  8813. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8814. {
  8815. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8816. goto end;
  8817. }
  8818. }//END FOR CHAdeMO_QUANTITY
  8819. } // END FOR gunTotalNumber
  8820. }
  8821. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8822. goto end;
  8823. }
  8824. //----------------------gunIndex is not 0 ------------------------------------------------//
  8825. //check Transaction active
  8826. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8827. {
  8828. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8829. {
  8830. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8831. goto end;
  8832. }
  8833. }//END FOR CHAdeMO_QUANTITY
  8834. for (int index = 0; index < CCS_QUANTITY; index++)
  8835. {
  8836. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8837. {
  8838. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8839. goto end;
  8840. }
  8841. }//END FOR CCS_QUANTITY
  8842. for (int index = 0; index < GB_QUANTITY; index++)
  8843. {
  8844. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8845. {
  8846. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8847. goto end;
  8848. }
  8849. }// END FOR GB_QUANTITY
  8850. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8851. {
  8852. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8853. {
  8854. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8855. goto end;
  8856. }
  8857. }// END FOR GENERAL_GUN_QUANTITY
  8858. for (int index = 0; index < AC_QUANTITY; index++)
  8859. {
  8860. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8861. {
  8862. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8863. goto end;
  8864. }
  8865. }//END FOR AC_QUANTITY
  8866. }//END FOR AvailabilityTypeStr[Operative]
  8867. end:
  8868. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8869. {
  8870. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8871. }
  8872. else
  8873. {
  8874. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8875. }
  8876. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8877. {
  8878. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8879. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8880. }
  8881. else if(gunIndex == 0)
  8882. {
  8883. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8884. {
  8885. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8886. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8887. }
  8888. }
  8889. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8890. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8891. return result;
  8892. }
  8893. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8894. {
  8895. mtrace();
  8896. int valueInvalid = NO;
  8897. int result = FAIL;
  8898. char keystr[40]={0};
  8899. char valuestr[501]={0}; //value should be limited in 500 bytes
  8900. char comfirmstr[20]={0};
  8901. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8902. json_object *ChangeConfiguration;
  8903. ChangeConfiguration = json_tokener_parse(payload);
  8904. if(!is_error(ChangeConfiguration))
  8905. {
  8906. // Required data
  8907. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8908. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8909. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8910. {
  8911. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8912. }
  8913. else
  8914. {
  8915. valueInvalid = YES;
  8916. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8917. }
  8918. }
  8919. json_object_put(ChangeConfiguration);
  8920. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8921. {
  8922. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8923. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8924. }
  8925. else
  8926. {
  8927. int status = setKeyValue(keystr, valuestr);
  8928. switch(status)
  8929. {
  8930. case ConfigurationStatus_Accepted:
  8931. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8932. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8933. StoreConfigurationTable();
  8934. break;
  8935. case RebootRequired:
  8936. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8937. StoreConfigurationTable();
  8938. break;
  8939. case NotSupported:
  8940. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8941. break;
  8942. case ConfigurationStatus_Rejected:
  8943. default:
  8944. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8945. break;
  8946. }
  8947. }
  8948. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8949. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8950. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8951. {
  8952. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8953. SetOcppConnStatus(FALSE);
  8954. }
  8955. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8956. {
  8957. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8958. }
  8959. return result;
  8960. }
  8961. int handleClearCacheRequest(char *uuid, char *payload)
  8962. {
  8963. mtrace();
  8964. int result = FAIL;
  8965. char comfirmstr[20];
  8966. char rmFileCmd[100]={0};
  8967. struct stat stats;
  8968. DEBUG_INFO("handleClearCacheRequest...\n");
  8969. stat("/Storage/OCPP", &stats);
  8970. // Check for directory existence
  8971. if (S_ISDIR(stats.st_mode) == 1)
  8972. {}
  8973. else
  8974. {
  8975. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8976. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8977. system(rmFileCmd);
  8978. }
  8979. if(OCPP_cleanLocalCache())
  8980. {
  8981. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8982. }
  8983. else
  8984. {
  8985. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8986. }
  8987. sendClearCacheConfirmation(uuid, comfirmstr);
  8988. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8989. return result;
  8990. }
  8991. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8992. {
  8993. mtrace();
  8994. int result = FAIL;
  8995. int resultRename;
  8996. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8997. char chargingProfilePurposeStr[26]={0};
  8998. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8999. char tempchargingProfilePurposeStr[26]={0};
  9000. char str[100]={0};
  9001. char fname[200]={0};
  9002. char comfirmstr[20]={0};
  9003. char word[1600]={0};
  9004. int clearflag = FALSE;
  9005. int chargingProfileIdIsNULL = FALSE;
  9006. int connectorIsNULL = FALSE;
  9007. int chargingProfilePurposeIsNULL = FALSE;
  9008. int stackLevelIsNULL = FALSE;
  9009. //int GotoEnd = FALSE;
  9010. FILE *fptr1, *fptr2;
  9011. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9012. int n_chargingProfile=0;
  9013. int isEmptyFile = FALSE;
  9014. char sLineWord[1600]={0};
  9015. char chargingProfiles[10][100]={0};
  9016. int ChargeProfileCount = 0;
  9017. int ch;
  9018. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9019. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9020. json_object *ClearChargingProfile;
  9021. ClearChargingProfile = json_tokener_parse(payload);
  9022. if(!is_error(ClearChargingProfile))
  9023. {
  9024. // Optional data
  9025. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9026. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9027. else
  9028. chargingProfileIdIsNULL = TRUE;
  9029. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9030. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9031. else
  9032. connectorIsNULL = TRUE;
  9033. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9034. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9035. else
  9036. chargingProfilePurposeIsNULL = TRUE;
  9037. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9038. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9039. else
  9040. stackLevelIsNULL = TRUE;
  9041. }
  9042. json_object_put(ClearChargingProfile);
  9043. if(connectorIsNULL == FALSE)
  9044. {
  9045. switch(connectorIdInt)
  9046. {
  9047. case 0:
  9048. if(chargingProfilePurposeIsNULL == TRUE)
  9049. {
  9050. int l = 0;
  9051. strcpy(fname, ChargePointMaxProfile_JSON);
  9052. if((access(fname,F_OK))!=-1)
  9053. {
  9054. strcpy(chargingProfiles[l], fname);
  9055. l = l + 1;
  9056. }
  9057. strcpy(fname, TxDefaultProfile_0_JSON);
  9058. if((access(fname,F_OK))!=-1)
  9059. {
  9060. strcpy(chargingProfiles[l], fname);
  9061. l = l + 1;
  9062. }
  9063. ChargeProfileCount = l;
  9064. }
  9065. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9066. {
  9067. strcpy(fname, ChargePointMaxProfile_JSON);
  9068. if((access(fname,F_OK))!=-1)
  9069. {
  9070. strcpy(chargingProfiles[0], fname);
  9071. ChargeProfileCount = 1;
  9072. }
  9073. }
  9074. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9075. {
  9076. strcpy(fname, TxDefaultProfile_0_JSON);
  9077. if((access(fname,F_OK))!=-1)
  9078. {
  9079. strcpy(chargingProfiles[0], fname);
  9080. ChargeProfileCount = 1;
  9081. }
  9082. }
  9083. break;
  9084. default:
  9085. if(chargingProfilePurposeIsNULL == TRUE)
  9086. {
  9087. int m = 0;
  9088. memset(fname, 0, ARRAY_SIZE(fname));
  9089. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9090. if((access(fname,F_OK))!=-1)
  9091. {
  9092. strcpy(chargingProfiles[m], fname);
  9093. m = m + 1;
  9094. }
  9095. memset(fname, 0, ARRAY_SIZE(fname));
  9096. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9097. if((access(fname,F_OK))!=-1)
  9098. {
  9099. strcpy(chargingProfiles[m], fname);
  9100. m = m + 1;
  9101. }
  9102. ChargeProfileCount = m;
  9103. }
  9104. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9105. {
  9106. //strcpy(fname, TxDefaultProfile_1_JSON);
  9107. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9108. if((access(fname,F_OK))!=-1)
  9109. {
  9110. strcpy(chargingProfiles[0], fname);
  9111. ChargeProfileCount = 1;
  9112. }
  9113. }
  9114. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9115. {
  9116. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9117. if((access(fname,F_OK))!=-1)
  9118. {
  9119. strcpy(chargingProfiles[0], fname);
  9120. ChargeProfileCount = 1;
  9121. }
  9122. //strcpy(fname, TxProfile_1_JSON);
  9123. }
  9124. //strcpy(fname, ChargePointMaxProfile_JSON );
  9125. break;
  9126. }
  9127. }
  9128. else // Check all Charging Profiles
  9129. {
  9130. int i = 0;
  9131. char fnametemp[200]={0};
  9132. ChargeProfileCount = 0;
  9133. //Check ChargePointMaxProfile.json exit
  9134. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9135. {
  9136. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9137. i = i + 1;
  9138. }
  9139. //Check TxDefaultProfile_0.json exit
  9140. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9141. {
  9142. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9143. i = i + 1;
  9144. }
  9145. //Check TxDefaultProfile_%d.json
  9146. for(int j=1; j <= gunTotalNumber; j++)
  9147. {
  9148. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9149. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9150. if((access(fnametemp,F_OK))!=-1)
  9151. {
  9152. strcpy(chargingProfiles[i], fnametemp);
  9153. i = i + 1;
  9154. }
  9155. }
  9156. //Check TxProfile_%d.json
  9157. for(int j=1; j <= gunTotalNumber; j++)
  9158. {
  9159. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9160. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9161. if((access(fnametemp,F_OK))!=-1)
  9162. {
  9163. strcpy(chargingProfiles[i], fnametemp);
  9164. i = i + 1;
  9165. }
  9166. }
  9167. ChargeProfileCount = i;
  9168. }// End connectorIsNULL is TRUE
  9169. if(ChargeProfileCount == 0)
  9170. {
  9171. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9172. goto end;
  9173. }
  9174. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9175. {
  9176. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9177. goto end;
  9178. }
  9179. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9180. {
  9181. memset(str, 0, ARRAY_SIZE(str));
  9182. // clear temp file
  9183. sprintf(str,"rm -f %s",temp);
  9184. system(str);
  9185. for(int k=0; k < ChargeProfileCount; k++)
  9186. {
  9187. memset(str, 0, ARRAY_SIZE(str));
  9188. //clear file in C
  9189. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9190. system(str);
  9191. }
  9192. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9193. goto end;
  9194. }
  9195. else if(connectorIsNULL == TRUE)
  9196. {
  9197. for(int k=0; k < ChargeProfileCount; k++)
  9198. {
  9199. fptr1 = fopen(chargingProfiles[k], "r");
  9200. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9201. //Check Charging Profile Count
  9202. while(fscanf(fptr1, "%s", word) != EOF)
  9203. {
  9204. //DEBUG_INFO("word=%s\n",word);
  9205. if(strstr(word, "chargingProfileId")!= NULL)
  9206. {
  9207. //DEBUG_INFO("test chargingProfileId \n");
  9208. n_chargingProfile = n_chargingProfile + 1;
  9209. //DEBUG_INFO("chargingProfileId Found\n");
  9210. }
  9211. }
  9212. rewind(fptr1);
  9213. //search Charging Profile Element
  9214. //int i= 0;
  9215. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9216. {
  9217. json_object *tmpProfilee;
  9218. tmpProfilee = json_tokener_parse(sLineWord);
  9219. if(!is_error(tmpProfilee))
  9220. {
  9221. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9222. {
  9223. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9224. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9225. }
  9226. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9227. {
  9228. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9229. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9230. }
  9231. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9232. {
  9233. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9234. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9235. }
  9236. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9237. {
  9238. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9239. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9240. }
  9241. }
  9242. json_object_put(tmpProfilee);
  9243. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9244. {
  9245. //------- not write to fptr2-------//
  9246. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9247. //clearflag = TRUE;
  9248. }
  9249. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9250. {
  9251. //------- not write to fptr2-------//
  9252. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9253. }
  9254. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9255. {
  9256. //------- not write to fptr2-------//
  9257. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9258. }
  9259. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9260. {
  9261. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9262. }
  9263. else
  9264. {
  9265. fprintf(fptr2, sLineWord);//writing data into file
  9266. }
  9267. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9268. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9269. if(clearflag == TRUE)
  9270. {
  9271. fclose(fptr1);
  9272. fclose(fptr2);
  9273. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9274. system(str);
  9275. // clear temp file
  9276. sprintf(str,"rm -f %s",temp);
  9277. system(str);
  9278. }
  9279. else
  9280. {
  9281. fclose(fptr1);
  9282. fclose(fptr2);
  9283. memset(str, 0, ARRAY_SIZE(str));
  9284. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9285. system(str);
  9286. resultRename = rename(temp, chargingProfiles[k]);
  9287. if(resultRename == 0)
  9288. {
  9289. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9290. }
  9291. else
  9292. {
  9293. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9294. }
  9295. if(comfirmstr[0]== 0)
  9296. {
  9297. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9298. }
  9299. //Check chargingProfile is empty file
  9300. /*------ Read the file ----------------*/
  9301. fptr1=fopen(chargingProfiles[k],"r");
  9302. ch=fgetc(fptr1);
  9303. rewind(fptr1);
  9304. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9305. if(ch!=EOF)
  9306. {
  9307. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9308. {
  9309. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9310. if(sLineWord[0]=='\0')
  9311. {
  9312. isEmptyFile = TRUE;
  9313. break;
  9314. }
  9315. else
  9316. {
  9317. isEmptyFile = FALSE;
  9318. break;
  9319. }
  9320. }
  9321. }
  9322. else
  9323. isEmptyFile = TRUE;
  9324. fclose(fptr1);
  9325. if(isEmptyFile == TRUE)
  9326. {
  9327. memset(str, 0, ARRAY_SIZE(str));
  9328. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9329. system(str);
  9330. }
  9331. }
  9332. }// End of while(int k=0; k < ChargePointCount; k++)
  9333. }
  9334. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9335. {
  9336. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9337. for(int k=0; k < ChargeProfileCount; k++)
  9338. {
  9339. fptr1 = fopen(chargingProfiles[k], "r");
  9340. fptr2 = fopen(temp, "w+");
  9341. //Check Charging Profile Count
  9342. while(fscanf(fptr1, "%s", word) != EOF)
  9343. {
  9344. //DEBUG_INFO("word=%s\n",word);
  9345. if(strstr(word, "chargingProfileId")!= NULL)
  9346. {
  9347. n_chargingProfile = n_chargingProfile + 1;
  9348. }
  9349. }
  9350. rewind(fptr1);
  9351. //search Charging Profile Element
  9352. //int i= 0;
  9353. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9354. {
  9355. json_object *tmpProfilee;
  9356. tmpProfilee = json_tokener_parse(sLineWord);
  9357. if(!is_error(tmpProfilee))
  9358. {
  9359. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9360. {
  9361. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9362. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9363. }
  9364. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9365. {
  9366. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9367. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9368. }
  9369. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9370. {
  9371. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9372. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9373. }
  9374. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9375. {
  9376. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9377. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9378. }
  9379. }
  9380. json_object_put(tmpProfilee);
  9381. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9382. {
  9383. //------- not write to fptr2-------//
  9384. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9385. //clearflag = TRUE;
  9386. }
  9387. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9388. {
  9389. //------- not write to fptr2-------//
  9390. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9391. }
  9392. else if(stackLevelIsNULL == TRUE)
  9393. {
  9394. //Clear Whole File
  9395. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9396. clearflag = TRUE;
  9397. break;
  9398. }
  9399. else
  9400. {
  9401. fprintf(fptr2, sLineWord);//writing data into file
  9402. }
  9403. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9404. }
  9405. if(clearflag == TRUE)
  9406. {
  9407. fclose(fptr1);
  9408. fclose(fptr2);
  9409. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9410. system(str);
  9411. // clear temp file
  9412. sprintf(str,"rm -f %s",temp);
  9413. system(str);
  9414. }
  9415. else
  9416. {
  9417. fclose(fptr1);
  9418. fclose(fptr2);
  9419. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9420. system(str);
  9421. resultRename = rename(temp, chargingProfiles[k]);
  9422. if(resultRename == 0)
  9423. {
  9424. DEBUG_INFO("File ChargingProfile renamed successfully");
  9425. }
  9426. else
  9427. {
  9428. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9429. }
  9430. if(comfirmstr[0]== 0)
  9431. {
  9432. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9433. }
  9434. //Check chargingProfile is empty file
  9435. /*------ Read the file ----------------*/
  9436. fptr1=fopen(chargingProfiles[k],"r");
  9437. ch=fgetc(fptr1);
  9438. rewind(fptr1);
  9439. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9440. if(ch!=EOF)
  9441. {
  9442. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9443. {
  9444. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9445. if(sLineWord[0]=='\0')
  9446. {
  9447. isEmptyFile = TRUE;
  9448. break;
  9449. }
  9450. else
  9451. {
  9452. isEmptyFile = FALSE;
  9453. break;
  9454. }
  9455. }
  9456. }
  9457. else
  9458. isEmptyFile = TRUE;
  9459. fclose(fptr1);
  9460. if(isEmptyFile == TRUE)
  9461. {
  9462. memset(str, 0, ARRAY_SIZE(str));
  9463. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9464. system(str);
  9465. }
  9466. /*------- End of reading ---------------*/
  9467. }
  9468. } // while(int k=0; k < ChargeProfileCount; k++)
  9469. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9470. end:
  9471. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9472. {
  9473. if(connectorIdInt == 0)
  9474. {
  9475. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9476. {
  9477. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9478. }
  9479. }
  9480. else
  9481. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9482. }
  9483. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9484. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9485. return result;
  9486. }
  9487. void createFirmwareVersionByDataTransfer(void)
  9488. {
  9489. json_object *FirmwareDataTransfer = json_object_new_object();
  9490. // AC & DC model
  9491. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9492. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9493. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9494. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9495. // DC model
  9496. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9497. {
  9498. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9499. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9500. (gunType[3] != GUN_TYPE_UNKNOWN))
  9501. {
  9502. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9503. }
  9504. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9505. {
  9506. // DS DM DW
  9507. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9508. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9509. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9510. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9511. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9512. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9513. }
  9514. else
  9515. {
  9516. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9517. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9518. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9519. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9520. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9521. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9522. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9523. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9524. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9525. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9526. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9527. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9528. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9529. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9530. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9531. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9532. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9533. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9534. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9535. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9536. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9537. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9538. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9539. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9540. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9541. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9542. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9543. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9544. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9545. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9546. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9547. }
  9548. }
  9549. // 4G model
  9550. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9551. {
  9552. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9553. }
  9554. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9555. json_object_put(FirmwareDataTransfer);
  9556. }
  9557. int handleDataTransferRequest(char *uuid, char *payload)
  9558. {
  9559. mtrace();
  9560. json_object *response = json_object_new_object();
  9561. int result = FAIL;
  9562. char tempvendorId[255]={0};
  9563. char tempmessageId[50]={0};
  9564. char tempdata[1024]={0};
  9565. char message[2048]={0};
  9566. DEBUG_INFO("handleDataTransferRequest...\n");
  9567. if((uuid != NULL) && (payload != NULL))
  9568. {
  9569. json_object *DataTransfer;
  9570. DataTransfer = json_tokener_parse(payload);
  9571. if(!is_error(DataTransfer))
  9572. {
  9573. // Required data
  9574. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9575. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9576. // Optional data
  9577. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9578. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9579. if(json_object_object_get(DataTransfer, "data") != NULL)
  9580. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9581. result = PASS;
  9582. }
  9583. json_object_put(DataTransfer);
  9584. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9585. {
  9586. // Send all moudle firmware version on EVSE
  9587. createFirmwareVersionByDataTransfer();
  9588. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9589. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9590. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9591. json_object_put(response);
  9592. }
  9593. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9594. {
  9595. system("/usr/bin/run_tmate_restart.sh &");
  9596. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9597. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9598. json_object_put(response);
  9599. }
  9600. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9601. {
  9602. json_object *data;
  9603. data = json_tokener_parse(tempdata);
  9604. if(!is_error(data))
  9605. {
  9606. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9607. {
  9608. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9609. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9610. if(json_object_object_get(data, "SOC") != NULL)
  9611. {
  9612. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9613. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9614. }
  9615. if(json_object_object_get(data, "Energy") != NULL)
  9616. {
  9617. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9618. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9619. }
  9620. if(json_object_object_get(data, "Duration") != NULL)
  9621. {
  9622. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9623. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9624. }
  9625. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9626. }
  9627. else
  9628. {
  9629. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9630. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9631. }
  9632. }
  9633. else
  9634. {
  9635. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9636. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9637. }
  9638. json_object_put(data);
  9639. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9640. json_object_put(response);
  9641. }
  9642. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9643. {
  9644. json_object *data;
  9645. data = json_tokener_parse(tempdata);
  9646. if(!is_error(data))
  9647. {
  9648. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9649. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9650. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9651. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9652. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9653. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9654. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9655. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9656. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9657. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9658. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9659. }
  9660. else
  9661. {
  9662. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9663. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9664. }
  9665. json_object_put(data);
  9666. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9667. json_object_put(response);
  9668. }
  9669. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9670. {
  9671. json_object *data;
  9672. data = json_tokener_parse(tempdata);
  9673. if(!is_error(data))
  9674. {
  9675. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9676. if(json_object_object_get(data, "idToken") != NULL)
  9677. {
  9678. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9679. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9680. }
  9681. if(json_object_object_get(data, "price") != NULL)
  9682. {
  9683. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9684. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9685. }
  9686. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9687. }
  9688. else
  9689. {
  9690. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9691. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9692. }
  9693. json_object_put(data);
  9694. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9695. json_object_put(response);
  9696. }
  9697. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9698. {
  9699. json_object *data;
  9700. data = json_tokener_parse(tempdata);
  9701. if(!is_error(data))
  9702. {
  9703. if(json_object_object_get(data, "txId") != NULL)
  9704. {
  9705. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9706. for(int idx = 0;idx<gunTotalNumber;idx++)
  9707. {
  9708. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9709. {
  9710. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9711. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9712. if(json_object_object_get(data, "description") != NULL)
  9713. {
  9714. // California pricing V1.0
  9715. DEBUG_INFO("California pricing V1.0\n");
  9716. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9717. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9718. }
  9719. else
  9720. {
  9721. // California pricing V1.1
  9722. DEBUG_INFO("California pricing V1.1\n");
  9723. if(json_object_object_get(data, "timestamp") != NULL)
  9724. {
  9725. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9726. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9727. }
  9728. if(json_object_object_get(data, "meterValue") != NULL)
  9729. {
  9730. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9731. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9732. }
  9733. if(json_object_object_get(data, "cost") != NULL)
  9734. {
  9735. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9736. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9737. }
  9738. if(json_object_object_get(data, "state") != NULL)
  9739. {
  9740. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9741. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9742. }
  9743. if(json_object_object_get(data, "chargingPrice") != NULL)
  9744. {
  9745. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9746. {
  9747. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9748. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9749. }
  9750. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9751. {
  9752. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9753. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9754. }
  9755. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9756. {
  9757. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9758. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9759. }
  9760. }
  9761. if(json_object_object_get(data, "idlePrice") != NULL)
  9762. {
  9763. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9764. {
  9765. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9766. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9767. }
  9768. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9769. {
  9770. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9771. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9772. }
  9773. }
  9774. if(json_object_object_get(data, "nextPeriod") != NULL)
  9775. {
  9776. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9777. {
  9778. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9779. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9780. }
  9781. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9782. {
  9783. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9784. {
  9785. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  9786. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  9787. }
  9788. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9789. {
  9790. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  9791. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  9792. }
  9793. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9794. {
  9795. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  9796. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  9797. }
  9798. }
  9799. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9800. {
  9801. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9802. {
  9803. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  9804. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  9805. }
  9806. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9807. {
  9808. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  9809. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  9810. }
  9811. }
  9812. }
  9813. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9814. {
  9815. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9816. {
  9817. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9818. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9819. }
  9820. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9821. {
  9822. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9823. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9824. }
  9825. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9826. {
  9827. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9828. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9829. }
  9830. }
  9831. }
  9832. }
  9833. }
  9834. }
  9835. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9836. }
  9837. else
  9838. {
  9839. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9840. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9841. }
  9842. json_object_put(data);
  9843. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9844. json_object_put(response);
  9845. }
  9846. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9847. {
  9848. json_object *data;
  9849. data = json_tokener_parse(tempdata);
  9850. if(!is_error(data))
  9851. {
  9852. if(json_object_object_get(data, "txId") != NULL)
  9853. {
  9854. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9855. for(int idx = 0;idx<gunTotalNumber;idx++)
  9856. {
  9857. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9858. {
  9859. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9860. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9861. if(json_object_object_get(data, "description") != NULL)
  9862. {
  9863. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9864. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9865. }
  9866. }
  9867. }
  9868. }
  9869. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9870. }
  9871. else
  9872. {
  9873. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9874. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9875. }
  9876. json_object_put(data);
  9877. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9878. json_object_put(response);
  9879. }
  9880. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9881. {
  9882. json_object *data;
  9883. data = json_tokener_parse(tempdata);
  9884. if(!is_error(data))
  9885. {
  9886. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9887. if(json_object_object_get(data, "Content_Type") != NULL)
  9888. {
  9889. if((0 <= json_object_get_int(json_object_object_get(data, "Content_Type"))) && (json_object_get_int(json_object_object_get(data, "Content_Type")) <= 1))
  9890. {
  9891. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9892. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9893. {
  9894. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9895. }
  9896. }
  9897. else
  9898. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9899. }
  9900. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9901. }
  9902. else
  9903. {
  9904. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9905. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9906. }
  9907. json_object_put(data);
  9908. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9909. json_object_put(response);
  9910. }
  9911. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9912. {
  9913. json_object *data;
  9914. data = json_tokener_parse(tempdata);
  9915. if(!is_error(data))
  9916. {
  9917. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9918. if(json_object_object_get(data, "ConnectorId") != NULL)
  9919. {
  9920. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9921. }
  9922. if(json_object_object_get(data, "SerialNo") != NULL)
  9923. {
  9924. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9925. }
  9926. if(json_object_object_get(data, "Page_Index") != NULL)
  9927. {
  9928. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9929. }
  9930. if(json_object_object_get(data, "Duration") != NULL)
  9931. {
  9932. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9933. }
  9934. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9935. }
  9936. else
  9937. {
  9938. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9939. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9940. }
  9941. json_object_put(data);
  9942. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9943. json_object_put(response);
  9944. }
  9945. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9946. {
  9947. json_object *data;
  9948. data = json_tokener_parse(tempdata);
  9949. if(!is_error(data))
  9950. {
  9951. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9952. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9953. {
  9954. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9955. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9956. else
  9957. {
  9958. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9959. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9960. }
  9961. }
  9962. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9963. {
  9964. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9965. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9966. else
  9967. {
  9968. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9969. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9970. }
  9971. }
  9972. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9973. {
  9974. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9975. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9976. else
  9977. {
  9978. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9979. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9980. }
  9981. }
  9982. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9983. {
  9984. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9985. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9986. else
  9987. {
  9988. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9989. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9990. }
  9991. }
  9992. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9993. {
  9994. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9995. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9996. else
  9997. {
  9998. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9999. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10000. }
  10001. }
  10002. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10003. {
  10004. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10005. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10006. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10007. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10008. else
  10009. {
  10010. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10011. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10012. }
  10013. }
  10014. if(json_object_object_get(data, "isAuthentication") != NULL)
  10015. {
  10016. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10017. {
  10018. case 0:
  10019. case 1:
  10020. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10021. break;
  10022. default:
  10023. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10024. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10025. break;
  10026. }
  10027. }
  10028. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10029. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10030. }
  10031. else
  10032. {
  10033. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10034. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10035. }
  10036. json_object_put(data);
  10037. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10038. json_object_put(response);
  10039. }
  10040. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10041. {
  10042. json_object *data;
  10043. data = json_tokener_parse(tempdata);
  10044. if(!is_error(data))
  10045. {
  10046. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10047. {
  10048. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10049. {
  10050. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10051. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10052. }
  10053. else
  10054. {
  10055. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10056. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10057. }
  10058. }
  10059. else
  10060. {
  10061. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10062. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10063. }
  10064. }
  10065. else
  10066. {
  10067. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10068. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10069. }
  10070. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10071. json_object_put(response);
  10072. }
  10073. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10074. {
  10075. json_object *data;
  10076. data = json_tokener_parse(tempdata);
  10077. if(!is_error(data))
  10078. {
  10079. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10080. if(json_object_object_get(data, "stationName") != NULL)
  10081. {
  10082. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10083. }
  10084. else
  10085. {
  10086. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10087. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10088. }
  10089. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10090. {
  10091. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10092. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10093. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10094. }
  10095. }
  10096. else
  10097. {
  10098. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10099. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10100. }
  10101. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10102. json_object_put(response);
  10103. }
  10104. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10105. {
  10106. json_object *data;
  10107. data = json_tokener_parse(tempdata);
  10108. if(!is_error(data))
  10109. {
  10110. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10111. if(json_object_object_get(data, "weatherId") != NULL)
  10112. {
  10113. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10114. }
  10115. else
  10116. {
  10117. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10118. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10119. }
  10120. if(json_object_object_get(data, "Temperature") != NULL)
  10121. {
  10122. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10123. }
  10124. else
  10125. {
  10126. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10127. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10128. }
  10129. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10130. {
  10131. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10132. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10133. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10134. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10135. );
  10136. }
  10137. }
  10138. else
  10139. {
  10140. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10141. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10142. }
  10143. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10144. json_object_put(response);
  10145. }
  10146. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10147. {
  10148. json_object *data;
  10149. data = json_tokener_parse(tempdata);
  10150. if(!is_error(data))
  10151. {
  10152. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10153. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10154. {
  10155. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10156. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10157. }
  10158. else
  10159. {
  10160. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10161. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10162. }
  10163. }
  10164. else
  10165. {
  10166. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10167. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10168. }
  10169. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10170. json_object_put(response);
  10171. }
  10172. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10173. {
  10174. json_object *data;
  10175. data = json_tokener_parse(tempdata);
  10176. if(!is_error(data))
  10177. {
  10178. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10179. {
  10180. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10181. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10182. if(gun_index < gunTotalNumber)
  10183. {
  10184. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10185. {
  10186. json_object *responsedata = json_object_new_object();
  10187. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10188. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10189. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10190. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10191. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10192. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10193. }
  10194. else
  10195. {
  10196. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10197. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10198. }
  10199. }
  10200. else
  10201. {
  10202. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10203. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10204. }
  10205. }
  10206. else
  10207. {
  10208. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10209. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10210. }
  10211. }
  10212. else
  10213. {
  10214. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10215. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10216. }
  10217. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10218. json_object_put(response);
  10219. }
  10220. else
  10221. {
  10222. // Can not find valid message id
  10223. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10224. }
  10225. }
  10226. else
  10227. {
  10228. // Payload is null
  10229. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10230. }
  10231. LWS_Send(message);
  10232. return result;
  10233. }
  10234. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10235. {
  10236. mtrace();
  10237. int result = FAIL;
  10238. int connectorIdInt, durationInt;
  10239. char chargingRateUnitStr[4]={0};
  10240. char comfirmstr[20];
  10241. int confirmPeriods = 0;
  10242. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10243. json_object *GetCompositeSchedule;
  10244. GetCompositeSchedule = json_tokener_parse(payload);
  10245. if(!is_error(GetCompositeSchedule))
  10246. {
  10247. // Required data
  10248. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10249. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10250. else
  10251. connectorIdInt = -1;
  10252. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10253. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10254. else
  10255. durationInt = 86400;
  10256. // Optional data
  10257. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10258. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10259. }
  10260. json_object_put(GetCompositeSchedule);
  10261. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10262. if((connectorIdInt == 0) ||
  10263. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10264. {
  10265. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10266. struct StructChargingProfile tmpProfile[1];
  10267. if(strstr(chargingRateUnitStr, "W") != NULL)
  10268. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10269. else
  10270. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10271. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10272. {
  10273. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10274. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10275. }
  10276. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10277. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10278. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10279. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10280. {
  10281. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10282. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10283. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10284. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10285. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10286. {
  10287. confirmPeriods = idx;
  10288. break;
  10289. }
  10290. }
  10291. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10292. {
  10293. confirmPeriods += 1;
  10294. }
  10295. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10296. }
  10297. else
  10298. {
  10299. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10300. }
  10301. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10302. return result;
  10303. }
  10304. int handleGetConfigurationRequest(char *uuid, char *payload)
  10305. {
  10306. mtrace();
  10307. int result = FAIL;
  10308. int MaxKeySupported = 0;
  10309. int n_keys = 0;
  10310. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10311. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10312. json_object *GetConfiguration;
  10313. GetConfiguration = json_tokener_parse(payload);
  10314. if(!is_error(GetConfiguration))
  10315. {
  10316. // Optional data
  10317. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10318. {
  10319. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10320. {
  10321. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10322. n_keys = idx + 1;
  10323. }
  10324. }
  10325. }
  10326. json_object_put(GetConfiguration);
  10327. UnknownKeynum = 0;
  10328. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10329. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10330. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10331. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10332. if(n_keys != 0)
  10333. {
  10334. for(int i=0;i<n_keys;i++)
  10335. {
  10336. getKeyValue(requestKey[i]);
  10337. }
  10338. }
  10339. else
  10340. {
  10341. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10342. getKeyValue("");
  10343. }
  10344. processUnkownKey();
  10345. sendGetConfigurationConfirmation(uuid);
  10346. return result;
  10347. }
  10348. static char fnamePlusPath[100]={0};
  10349. static char fnamePWithNoPath[60]={0};
  10350. void checkUploadLog(void)
  10351. {
  10352. FILE *fp;
  10353. /* Open the command for reading. */
  10354. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10355. if (fp == NULL) {
  10356. DEBUG_WARN("Failed to run command\n" );
  10357. exit(1);
  10358. }
  10359. int ftppathlen = 0;
  10360. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10361. int i = 0;
  10362. /* Read the output a line at a time - output it. */
  10363. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10364. if(i==0)
  10365. {
  10366. ftppathlen = strlen(fnamePlusPath);
  10367. DEBUG_INFO("%s\n", fnamePlusPath);
  10368. fnamePlusPath[ftppathlen]='\0';
  10369. break;
  10370. }
  10371. i= i+1;
  10372. }
  10373. /* close */
  10374. pclose(fp);
  10375. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10376. {
  10377. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10378. {
  10379. fnamePlusPath[k]='\0';
  10380. }
  10381. }
  10382. i=1;
  10383. //char fname[60]={0};
  10384. while(i < ftppathlen)
  10385. {
  10386. int len=ftppathlen-i;
  10387. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10388. {
  10389. DEBUG_INFO("compare '/' all right\n");
  10390. break;
  10391. }
  10392. i=i+1;
  10393. }
  10394. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10395. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10396. fnamePWithNoPath[i+1] = '\0';
  10397. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10398. {
  10399. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10400. {
  10401. fnamePWithNoPath[j]='\0';
  10402. }
  10403. }
  10404. FILE* fp1 = fopen(fnamePlusPath, "r");
  10405. if (fp1)
  10406. {
  10407. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10408. // file exists
  10409. fclose(fp1);
  10410. }
  10411. else
  10412. {
  10413. // file doesn't exist
  10414. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10415. }
  10416. }
  10417. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10418. {
  10419. mtrace();
  10420. int result = FAIL;
  10421. time_t CurrentTime;
  10422. struct tm *tm;
  10423. pthread_t th_Status;
  10424. CurrentTime = time(NULL);
  10425. tm = localtime(&CurrentTime);
  10426. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10427. 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);
  10428. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10429. if(!interLock.isGetDiagnosticGoing)
  10430. {
  10431. interLock.isGetDiagnosticGoing = 1;
  10432. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10433. sleep(1);
  10434. }
  10435. else
  10436. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10437. return result;
  10438. }
  10439. void* GetDiagnosticsProcess(void* data)
  10440. {
  10441. pthread_detach(pthread_self());
  10442. mtrace();
  10443. int retriesInt=0, retryIntervalInt=0;
  10444. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10445. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  10446. int port=0;
  10447. int isSuccess = FALSE;
  10448. char cmdBuf[2048];
  10449. struct tm *tmNow;
  10450. time_t CurrentTime;
  10451. struct tm tmStart;
  10452. struct tm tmStop;
  10453. CurrentTime = time(NULL);
  10454. tmNow=localtime(&CurrentTime);
  10455. uint16_t targetYear, targetMonth;
  10456. json_object *GetDiagnostics;
  10457. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10458. GetDiagnostics = json_tokener_parse(data);
  10459. if(!is_error(GetDiagnostics))
  10460. {
  10461. // Required data
  10462. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10463. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10464. // Optional data
  10465. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10466. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10467. else
  10468. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10469. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10470. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10471. else
  10472. retryIntervalInt = 30;
  10473. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10474. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10475. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10476. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10477. }
  10478. json_object_put(GetDiagnostics);
  10479. // Pack log to compress file
  10480. if((sscanf((char*)startTimestr, "%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) &&
  10481. (sscanf((char*)stopTimestr, "%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))
  10482. {
  10483. // Pack system log
  10484. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10485. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10486. targetYear = tmStart.tm_year;
  10487. targetMonth = tmStart.tm_mon;
  10488. do
  10489. {
  10490. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10491. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10492. if(targetMonth+1>=13)
  10493. {
  10494. targetYear += 1;
  10495. targetMonth = 1;
  10496. }
  10497. else
  10498. {
  10499. targetMonth += 1;
  10500. }
  10501. }while((targetYear < (tmNow->tm_year+1900)) ||
  10502. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10503. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10504. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10505. system(cmdBuf);
  10506. // Pack charging & event log
  10507. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10508. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10509. targetYear = tmStart.tm_year;
  10510. targetMonth = tmStart.tm_mon;
  10511. do
  10512. {
  10513. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10514. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10515. if(targetMonth+1>=13)
  10516. {
  10517. targetYear += 1;
  10518. targetMonth = 1;
  10519. }
  10520. else
  10521. {
  10522. targetMonth += 1;
  10523. }
  10524. }while((targetYear < (tmNow->tm_year+1900)) ||
  10525. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10526. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10527. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10528. system(cmdBuf);
  10529. // Combine log file
  10530. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10531. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10532. }
  10533. else
  10534. {
  10535. system("exec /root/logPackTools 'log' 6");
  10536. }
  10537. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10538. system(cmdBuf);
  10539. checkUploadLog();
  10540. //****************location*******************/
  10541. if(strcmp(locationstr,"")==0)
  10542. {
  10543. DEBUG_INFO("location is <Empty>!\n");
  10544. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10545. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10546. goto end;
  10547. }
  10548. memset(protocol, 0, ARRAY_SIZE(protocol));
  10549. memset(user, 0, ARRAY_SIZE(user) );
  10550. memset(password, 0, ARRAY_SIZE(password));
  10551. memset(host, 0, ARRAY_SIZE(host));
  10552. memset(path, 0, ARRAY_SIZE(path));
  10553. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10554. memset(host1, 0, ARRAY_SIZE(host1));
  10555. memset(path1, 0, ARRAY_SIZE(path1));
  10556. /*location: ftp://user:password@host:port/path*/
  10557. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10558. if((access(fnamePlusPath,F_OK))!=-1)
  10559. {
  10560. DEBUG_INFO("fnamePlusPath exist.\n");
  10561. }
  10562. else
  10563. {
  10564. DEBUG_INFO("fnamePlusPath not exist!\n");
  10565. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10566. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10567. goto end;
  10568. }
  10569. if(strchr(locationstr,'@')==NULL)
  10570. {
  10571. sscanf(locationstr,
  10572. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10573. protocol, host, &port, path);
  10574. strcpy(user,"anonymous");
  10575. strcpy(password,"");
  10576. }
  10577. else
  10578. {
  10579. //DEBUG_INFO("pch=%s\n", pch);
  10580. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10581. protocol, user, password, host, &port, path);
  10582. }
  10583. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10584. {
  10585. DEBUG_INFO("protocol is not ftp/http ! \n");
  10586. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10587. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10588. goto end;
  10589. }
  10590. if(strncmp(locationstr,"http", 4) == 0)
  10591. {
  10592. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10593. sprintf(ftppath,"/%s", path);
  10594. do
  10595. {
  10596. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10597. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10598. sleep(3);
  10599. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10600. if(!isSuccess)
  10601. {
  10602. DEBUG_INFO("Diagnostics fail.\n");
  10603. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10604. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10605. sleep(retryIntervalInt);
  10606. }
  10607. else
  10608. {
  10609. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10610. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10611. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10612. }
  10613. retriesInt--;
  10614. }while((isSuccess == 0)&&(retriesInt >= 0));
  10615. }
  10616. else
  10617. {
  10618. sscanf(host,"%[^/]%s",host1, path1);
  10619. if(strlen(path) > 0)
  10620. sprintf(ftppath,"/%s", path);
  10621. else
  10622. sprintf(ftppath,"/%s", path1);
  10623. int ftppathlen=strlen(ftppath);
  10624. int i=1;
  10625. char filenametemp[50];
  10626. while(i < ftppathlen)
  10627. {
  10628. int len=ftppathlen-i;
  10629. if(ftppath[len]== 47) // '/' ascll code: 47
  10630. {
  10631. DEBUG_INFO("find '/' all right\n");
  10632. break;
  10633. }
  10634. i=i+1;
  10635. }
  10636. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10637. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10638. filenametemp[i+1] = 0;
  10639. if(port == 0)
  10640. port = 21;
  10641. do
  10642. {
  10643. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10644. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10645. sleep(3);
  10646. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10647. if(!isSuccess)
  10648. {
  10649. DEBUG_INFO("Diagnostics fail.\n");
  10650. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10651. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10652. sleep(retryIntervalInt);
  10653. }
  10654. else
  10655. {
  10656. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10657. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10658. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10659. }
  10660. retriesInt--;
  10661. }while((!isSuccess)&&(retriesInt >= 0));
  10662. }
  10663. end:
  10664. system("rm -f /mnt/*");
  10665. sleep(5);
  10666. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10667. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10668. interLock.isGetDiagnosticGoing = 0;
  10669. pthread_exit(NULL);
  10670. }
  10671. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10672. {
  10673. mtrace();
  10674. int result = FAIL;
  10675. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10676. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10677. {
  10678. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10679. locallistVersion = -1;
  10680. }
  10681. else
  10682. {
  10683. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10684. locallistVersion = 0;
  10685. OCPP_getListVerion();
  10686. }
  10687. //from db.OCPP_getListVerion
  10688. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10689. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10690. sendGetLocalListVersionConfirmation(uuid,"");
  10691. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10692. return result;
  10693. }
  10694. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10695. {
  10696. mtrace();
  10697. int result = FAIL;
  10698. int connectorIdInt=-1;
  10699. int tempIndex = 0;
  10700. int connectorIdIsNULL, chargingProfileIsNULL;
  10701. char comfirmstr[20]={0};
  10702. char cmdBuf[512];
  10703. json_object *RemoteStartTransaction;
  10704. FILE *fp;
  10705. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10706. if(server_pending == TRUE)
  10707. {
  10708. return 0;
  10709. }
  10710. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10711. RemoteStartTransaction = json_tokener_parse(payload);
  10712. if(!is_error(RemoteStartTransaction))
  10713. {
  10714. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10715. {
  10716. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10717. }
  10718. else
  10719. {
  10720. connectorIdIsNULL = TRUE;
  10721. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10722. {
  10723. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10724. {
  10725. connectorIdIsNULL = FALSE;
  10726. connectorIdInt = (gun_index+1);
  10727. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10728. break;
  10729. }
  10730. }
  10731. }
  10732. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10733. {
  10734. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10735. // Required data
  10736. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10737. // Optional data
  10738. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10739. {
  10740. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10741. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10742. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10743. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10744. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10745. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10746. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10747. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10748. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10749. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10750. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10751. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10752. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10753. {
  10754. 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")));
  10755. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10756. 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"));
  10757. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10758. 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"));
  10759. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10760. 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")));
  10761. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10762. {
  10763. 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++)
  10764. {
  10765. 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"));
  10766. 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"));
  10767. 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)
  10768. 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"));
  10769. }
  10770. }
  10771. }
  10772. }
  10773. else
  10774. {
  10775. chargingProfileIsNULL = TRUE;
  10776. }
  10777. }
  10778. }
  10779. else
  10780. {
  10781. connectorIdIsNULL = TRUE;
  10782. }
  10783. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10784. {
  10785. DEBUG_WARN("Connector id is NULL\n.");
  10786. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10787. goto end;
  10788. }
  10789. /*
  10790. enum _SYSTEM_STATUS
  10791. {
  10792. S_BOOTING = 0,
  10793. S_IDLE, = 1
  10794. S_AUTHORIZING, = 2
  10795. S_REASSIGN_CHECK, = 3
  10796. S_REASSIGN, = 4
  10797. S_PRECHARGE, = 5
  10798. S_PREPARING_FOR_EV, = 6
  10799. S_PREPARING_FOR_EVSE, = 7
  10800. S_CHARGING, = 8
  10801. S_TERMINATING, = 9
  10802. S_COMPLETE, = 10
  10803. S_ALARM, = 11
  10804. S_FAULT = 12
  10805. }
  10806. */
  10807. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10808. {
  10809. //check Transaction active
  10810. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10811. {
  10812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10813. {
  10814. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10815. }
  10816. else
  10817. {
  10818. tempIndex = connectorIdInt -1;
  10819. }
  10820. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10821. {
  10822. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10823. {
  10824. 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))
  10825. {
  10826. //Reserved
  10827. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10828. }
  10829. 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))
  10830. {
  10831. //Reserved
  10832. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10833. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10834. goto end;
  10835. }
  10836. else
  10837. {
  10838. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10839. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10840. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10841. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10842. {
  10843. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10844. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10845. goto end;
  10846. }
  10847. }//END FOR ELSE
  10848. }
  10849. }// END FOR CHAdeMO_QUANTITY
  10850. }
  10851. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10852. {
  10853. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10854. {
  10855. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10856. }
  10857. else
  10858. {
  10859. tempIndex = connectorIdInt -1;
  10860. }
  10861. for (int index = 0; index < CCS_QUANTITY; index++)
  10862. {
  10863. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10864. {
  10865. 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))
  10866. {
  10867. //Reserved
  10868. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10869. }
  10870. 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))
  10871. {
  10872. //Reserved
  10873. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10874. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10875. goto end;
  10876. }
  10877. else
  10878. {
  10879. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10880. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10881. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10882. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10883. {
  10884. DEBUG_WARN("CCS connector not allow start\n.");
  10885. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10886. goto end;
  10887. }
  10888. }// END FOR ELSE
  10889. }
  10890. }// END FOR CCS_QUANTITY
  10891. }
  10892. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10893. {
  10894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10895. {
  10896. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10897. }
  10898. else
  10899. {
  10900. tempIndex = connectorIdInt -1;
  10901. }
  10902. for (int index = 0; index < GB_QUANTITY; index++)
  10903. {
  10904. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10905. {
  10906. 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))
  10907. {
  10908. //Reserved
  10909. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10910. }
  10911. 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))
  10912. {
  10913. //Reserved
  10914. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10915. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10916. goto end;
  10917. }
  10918. else
  10919. {
  10920. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10921. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10922. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10923. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10924. {
  10925. DEBUG_WARN("GB connector not allow start\n.");
  10926. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10927. goto end;
  10928. }
  10929. }// END FOR ELSE
  10930. }
  10931. } // END FOR GB_QUANTITY
  10932. }
  10933. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10934. {
  10935. tempIndex = connectorIdInt -1;
  10936. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10937. {
  10938. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10939. {
  10940. 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))
  10941. {
  10942. //Reserved
  10943. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10944. }
  10945. 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))
  10946. {
  10947. //Reserved
  10948. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10949. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10950. goto end;
  10951. }
  10952. else
  10953. {
  10954. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10955. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10956. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10957. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10958. {
  10959. DEBUG_WARN("GB connector not allow start\n.");
  10960. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10961. goto end;
  10962. }
  10963. }// END FOR ELSE
  10964. }
  10965. } // END FOR GB_QUANTITY
  10966. }
  10967. else
  10968. {
  10969. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10970. {
  10971. tempIndex = 2;
  10972. }
  10973. else
  10974. {
  10975. tempIndex = connectorIdInt -1;
  10976. }
  10977. for (int index = 0; index < AC_QUANTITY; index++)
  10978. {
  10979. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10980. {
  10981. 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))
  10982. {
  10983. //Reserved
  10984. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10985. }
  10986. 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))
  10987. {
  10988. //Reserved
  10989. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10990. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10991. goto end;
  10992. }
  10993. else
  10994. {
  10995. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10996. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10997. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10998. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10999. {
  11000. DEBUG_WARN("AC connector not allow start\n.");
  11001. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11002. goto end;
  11003. }
  11004. }//END FOR ELSE
  11005. }
  11006. }// END FOR AC_QUANTITY
  11007. }
  11008. if(chargingProfileIsNULL == FALSE)
  11009. {
  11010. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11011. {
  11012. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11013. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11014. //memset idTag
  11015. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11016. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11017. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11018. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11019. // Save profile to file
  11020. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11021. system(cmdBuf);
  11022. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11023. fp = fopen(cmdBuf, "w");
  11024. 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));
  11025. fclose(fp);
  11026. }
  11027. else
  11028. {
  11029. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  11030. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11031. }
  11032. }
  11033. else
  11034. {
  11035. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11036. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11037. //memset idTag
  11038. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11039. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11040. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11041. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11042. }
  11043. }
  11044. else
  11045. {
  11046. DEBUG_WARN("Connector id over\n.");
  11047. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11048. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11049. }
  11050. end:
  11051. json_object_put(RemoteStartTransaction);
  11052. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  11053. {
  11054. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  11055. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11056. }
  11057. //OCPP send RemoteStartConfirmation by first.
  11058. sendRemoteStartConfirmation(uuid, comfirmstr);
  11059. return result;
  11060. }
  11061. int handleRemoteStartRequest(char *uuid, char *payload)
  11062. {
  11063. mtrace();
  11064. int result = PASS;
  11065. int connectorIdInt=-1;
  11066. int tempIndex = 0;
  11067. char comfirmstr[20]={0};
  11068. char cmdBuf[512];
  11069. json_object *RemoteStartTransaction;
  11070. FILE *fp;
  11071. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11072. if(server_pending == TRUE)
  11073. {
  11074. result = FAIL;
  11075. }
  11076. RemoteStartTransaction = json_tokener_parse(payload);
  11077. if(!is_error(RemoteStartTransaction))
  11078. {
  11079. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11080. {
  11081. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11082. }
  11083. else
  11084. {
  11085. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11086. {
  11087. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11088. {
  11089. connectorIdInt = (gun_index+1);
  11090. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11091. break;
  11092. }
  11093. }
  11094. }
  11095. if(connectorIdInt == 0)
  11096. {
  11097. DEBUG_WARN("Connector id shall not equal 0.\n");
  11098. result = FAIL;
  11099. }
  11100. else if(connectorIdInt == -1)
  11101. {
  11102. DEBUG_INFO("Connector id does not specific.\n");
  11103. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11104. {
  11105. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11106. // Required data
  11107. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11108. // Optional data
  11109. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11110. {
  11111. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11112. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11113. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11114. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11115. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11116. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11117. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11118. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11119. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11120. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11121. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11122. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11123. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11124. {
  11125. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  11126. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11127. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  11128. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11129. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  11130. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11131. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  11132. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11133. {
  11134. 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++)
  11135. {
  11136. ShmOCPP16Data->RemoteStartTransaction[gun_index].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"));
  11137. ShmOCPP16Data->RemoteStartTransaction[gun_index].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"));
  11138. 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)
  11139. ShmOCPP16Data->RemoteStartTransaction[gun_index].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"));
  11140. }
  11141. }
  11142. }
  11143. }
  11144. else
  11145. {
  11146. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11147. }
  11148. }
  11149. }
  11150. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11151. {
  11152. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11153. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11154. // Required data
  11155. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11156. // Optional data
  11157. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11158. {
  11159. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11160. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11161. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11162. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11163. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11164. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11165. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11166. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11167. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11168. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11169. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11170. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11171. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11172. {
  11173. 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")));
  11174. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11175. 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"));
  11176. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11177. 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"));
  11178. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11179. 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")));
  11180. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11181. {
  11182. 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++)
  11183. {
  11184. 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"));
  11185. 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"));
  11186. 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)
  11187. 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"));
  11188. }
  11189. }
  11190. }
  11191. }
  11192. else
  11193. {
  11194. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11195. }
  11196. }
  11197. else
  11198. {
  11199. DEBUG_WARN("Connector id is over maximun value.\n");
  11200. result = FAIL;
  11201. }
  11202. }
  11203. if(result == PASS)
  11204. {
  11205. if(connectorIdInt > 0)
  11206. {
  11207. //check Transaction active
  11208. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11209. {
  11210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11211. {
  11212. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11213. }
  11214. else
  11215. {
  11216. tempIndex = connectorIdInt -1;
  11217. }
  11218. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11219. {
  11220. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11221. {
  11222. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11223. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11224. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11225. {
  11226. //Reserved
  11227. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11228. }
  11229. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11230. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11231. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11232. {
  11233. //Reserved
  11234. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11235. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11236. goto end;
  11237. }
  11238. else
  11239. {
  11240. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11241. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11242. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11243. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11244. {
  11245. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11246. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11247. goto end;
  11248. }
  11249. }//END FOR ELSE
  11250. }
  11251. }// END FOR CHAdeMO_QUANTITY
  11252. }
  11253. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11254. {
  11255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11256. {
  11257. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11258. }
  11259. else
  11260. {
  11261. tempIndex = connectorIdInt -1;
  11262. }
  11263. for (int index = 0; index < CCS_QUANTITY; index++)
  11264. {
  11265. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11266. {
  11267. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11268. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11269. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11270. {
  11271. //Reserved
  11272. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11273. }
  11274. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11275. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11276. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11277. {
  11278. //Reserved
  11279. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11280. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11281. goto end;
  11282. }
  11283. else
  11284. {
  11285. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11286. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11287. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11288. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11289. {
  11290. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11291. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11292. goto end;
  11293. }
  11294. }// END FOR ELSE
  11295. }
  11296. }// END FOR CCS_QUANTITY
  11297. }
  11298. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11299. {
  11300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11301. {
  11302. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11303. }
  11304. else
  11305. {
  11306. tempIndex = connectorIdInt -1;
  11307. }
  11308. for (int index = 0; index < GB_QUANTITY; index++)
  11309. {
  11310. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11311. {
  11312. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11313. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11314. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11315. {
  11316. //Reserved
  11317. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11318. }
  11319. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11320. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11321. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11322. {
  11323. //Reserved
  11324. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11325. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11326. goto end;
  11327. }
  11328. else
  11329. {
  11330. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11331. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11332. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11333. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11334. {
  11335. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11336. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11337. goto end;
  11338. }
  11339. }// END FOR ELSE
  11340. }
  11341. } // END FOR GB_QUANTITY
  11342. }
  11343. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11344. {
  11345. tempIndex = connectorIdInt -1;
  11346. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11347. {
  11348. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11349. {
  11350. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11351. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11352. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11353. {
  11354. //Reserved
  11355. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11356. }
  11357. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11358. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11359. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11360. {
  11361. //Reserved
  11362. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11363. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11364. goto end;
  11365. }
  11366. else
  11367. {
  11368. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11369. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11370. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11371. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11372. {
  11373. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11374. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11375. goto end;
  11376. }
  11377. }// END FOR ELSE
  11378. }
  11379. } // END FOR GB_QUANTITY
  11380. }
  11381. else
  11382. {
  11383. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11384. {
  11385. tempIndex = 2;
  11386. }
  11387. else
  11388. {
  11389. tempIndex = connectorIdInt -1;
  11390. }
  11391. for (int index = 0; index < AC_QUANTITY; index++)
  11392. {
  11393. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11394. {
  11395. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11396. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11397. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11398. {
  11399. //Reserved
  11400. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11401. }
  11402. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11403. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11404. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11405. {
  11406. //Reserved
  11407. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11408. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11409. goto end;
  11410. }
  11411. else
  11412. {
  11413. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11414. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11415. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11416. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11417. {
  11418. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11419. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11420. goto end;
  11421. }
  11422. }//END FOR ELSE
  11423. }
  11424. }// END FOR AC_QUANTITY
  11425. }
  11426. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11427. {
  11428. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11429. {
  11430. // Save profile to file
  11431. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11432. system(cmdBuf);
  11433. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11434. fp = fopen(cmdBuf, "w");
  11435. 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));
  11436. fclose(fp);
  11437. }
  11438. else
  11439. {
  11440. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11441. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11442. goto end;
  11443. }
  11444. }
  11445. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11446. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11447. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11448. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11449. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11450. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11451. }
  11452. else
  11453. {
  11454. uint8_t isHasIdleConnector = FALSE;
  11455. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11456. {
  11457. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11458. {
  11459. isHasIdleConnector = TRUE;
  11460. break;
  11461. }
  11462. }
  11463. if(isHasIdleConnector == TRUE)
  11464. {
  11465. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11466. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11467. {
  11468. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11469. {
  11470. // Save profile to file
  11471. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11472. system(cmdBuf);
  11473. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11474. fp = fopen(cmdBuf, "w");
  11475. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11476. fclose(fp);
  11477. refreshStartTimer(&clientTime.RemoteStartWait);
  11478. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11479. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11480. }
  11481. else
  11482. {
  11483. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11484. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11485. }
  11486. }
  11487. else
  11488. {
  11489. refreshStartTimer(&clientTime.RemoteStartWait);
  11490. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11491. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11492. }
  11493. }
  11494. else
  11495. {
  11496. DEBUG_INFO("There is not any connector is idle.\n");
  11497. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11498. }
  11499. }
  11500. }
  11501. else
  11502. {
  11503. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11504. }
  11505. end:
  11506. json_object_put(RemoteStartTransaction);
  11507. sendRemoteStartConfirmation(uuid, comfirmstr);
  11508. return result;
  11509. }
  11510. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11511. {
  11512. mtrace();
  11513. int result = FAIL;
  11514. int match = FALSE;
  11515. int GunNO = 0;
  11516. int tempIndex = 0;
  11517. int transactionIdInt=0;
  11518. int transactionIdIsNULL= TRUE;
  11519. char comfirmstr[20];
  11520. json_object *RemoteStopTransaction;
  11521. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11522. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11523. if(server_pending == TRUE)
  11524. {
  11525. return 0;
  11526. }
  11527. RemoteStopTransaction = json_tokener_parse(payload);
  11528. if(!is_error(RemoteStopTransaction))
  11529. {
  11530. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11531. {
  11532. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11533. transactionIdIsNULL = FALSE;
  11534. }
  11535. }
  11536. json_object_put(RemoteStopTransaction);
  11537. if(transactionIdIsNULL == FALSE)
  11538. {
  11539. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11540. {
  11541. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11542. {
  11543. //check Transaction active
  11544. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11545. {
  11546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11547. {
  11548. tempIndex = ((gun_index==2) ? 1: 0);
  11549. }
  11550. else
  11551. {
  11552. tempIndex = gun_index;
  11553. }
  11554. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11555. {
  11556. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11557. {
  11558. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11559. {
  11560. match = TRUE;
  11561. GunNO = gun_index;
  11562. }
  11563. }
  11564. }// END FOR CHAdeMO_QUANTITY
  11565. }
  11566. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11567. {
  11568. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11569. {
  11570. tempIndex = ((gun_index==2) ? 1: 0);
  11571. }
  11572. else
  11573. {
  11574. tempIndex = gun_index;
  11575. }
  11576. for (int index = 0; index < CCS_QUANTITY; index++)
  11577. {
  11578. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11579. {
  11580. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11581. {
  11582. match = TRUE;
  11583. GunNO = gun_index;
  11584. }
  11585. }
  11586. }// END FOR CCS_QUANTITY
  11587. }
  11588. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11589. {
  11590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11591. {
  11592. tempIndex = ((gun_index==2) ? 1: 0);
  11593. }
  11594. else
  11595. {
  11596. tempIndex = gun_index;
  11597. }
  11598. for (int index = 0; index < GB_QUANTITY; index++)
  11599. {
  11600. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11601. {
  11602. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11603. {
  11604. match = TRUE;
  11605. GunNO = gun_index;
  11606. }
  11607. }
  11608. }// END FOR GB_QUANTITY
  11609. }
  11610. else if(gunType[gun_index] == GUN_TYPE_DO)
  11611. {
  11612. tempIndex = gun_index;
  11613. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11614. {
  11615. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11616. {
  11617. 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
  11618. {
  11619. match = TRUE;
  11620. GunNO = gun_index;
  11621. }
  11622. }
  11623. }// END FOR GB_QUANTITY
  11624. }
  11625. else
  11626. {
  11627. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11628. {
  11629. tempIndex = 2;
  11630. }
  11631. else
  11632. {
  11633. tempIndex = gun_index;
  11634. }
  11635. for (int index = 0; index < AC_QUANTITY; index++)
  11636. {
  11637. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11638. {
  11639. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11640. {
  11641. match = TRUE;
  11642. GunNO = gun_index;
  11643. }
  11644. }
  11645. }// END FOR CHAdeMO_QUANTITY
  11646. } // END FOR AC ELSE
  11647. }// CHECK IF ResponseTransactionId == transactionIdInt
  11648. }//END FOR
  11649. if( match == TRUE)
  11650. {
  11651. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11652. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11653. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11654. }
  11655. else
  11656. {
  11657. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11658. }
  11659. }
  11660. else
  11661. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11662. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11663. return result;
  11664. }
  11665. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11666. {
  11667. mtrace();
  11668. int result = FAIL;
  11669. int connectorIdInt=0, reservationIdInt=0;
  11670. int tempIndex = 0;
  11671. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11672. char comfirmstr[20]={0};
  11673. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11674. int c = 0;
  11675. char *loc;
  11676. //char *ptr;
  11677. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11678. strcpy(sstrtemp, stringtrimspace(payload));
  11679. //***(1)connectorId ****/
  11680. c=0;
  11681. loc = strstr(sstrtemp, "connectorId");
  11682. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11683. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11684. {
  11685. sstr[c] = loc[strlen("connectorId")+2+c];
  11686. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11687. c++;
  11688. }
  11689. sstr[c] = '\0';
  11690. connectorIdInt = atoi(sstr);
  11691. //***(2)expiryDate ****/
  11692. loc = strstr(sstrtemp, "expiryDate");
  11693. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11694. c = 0;
  11695. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11696. {
  11697. sstr[c] = loc[3+strlen("expiryDate")+c];
  11698. c++;
  11699. }
  11700. sstr[c] = '\0';
  11701. strcpy(expiryDatestr, sstr);
  11702. //***(3)idTag ****/
  11703. loc = strstr(sstrtemp, "idTag");
  11704. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11705. c = 0;
  11706. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11707. {
  11708. sstr[c] = loc[3+strlen("idTag")+c];
  11709. c++;
  11710. }
  11711. sstr[c] = '\0';
  11712. strcpy(idTagstr, sstr);
  11713. //***(4)parentIdTag ****/
  11714. loc = strstr(sstrtemp, "parentIdTag");
  11715. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11716. c = 0;
  11717. if(loc == NULL)
  11718. {
  11719. strcpy(parentIdTagstr, "");
  11720. }
  11721. else
  11722. {
  11723. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11724. {
  11725. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11726. c++;
  11727. }
  11728. sstr[c] = '\0';
  11729. strcpy(parentIdTagstr, sstr);
  11730. }
  11731. //***(5)reservationId ****/
  11732. c=0;
  11733. loc = strstr(sstrtemp, "reservationId");
  11734. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11735. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11736. {
  11737. sstr[c] = loc[strlen("reservationId")+2+c];
  11738. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11739. c++;
  11740. }
  11741. sstr[c] = '\0';
  11742. reservationIdInt = atoi(sstr);
  11743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11744. /*
  11745. enum SYSTEM_STATUS
  11746. {
  11747. SYS_MODE_BOOTING = 0,
  11748. SYS_MODE_IDLE = 1,
  11749. SYS_MODE_AUTHORIZING = 2,
  11750. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11751. SYS_MODE_REASSIGN = 4,
  11752. SYS_MODE_PREPARING = 5,
  11753. SYS_MODE_PREPARE_FOR_EV = 6,
  11754. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11755. SYS_MODE_CHARGING = 8,
  11756. SYS_MODE_TERMINATING = 9,
  11757. SYS_MODE_COMPLETE = 10,
  11758. SYS_MODE_ALARM = 11,
  11759. SYS_MODE_FAULT = 12,
  11760. SYS_MODE_RESERVATION = 13,
  11761. SYS_MODE_BOOKING = 14,
  11762. SYS_MODE_MAINTAIN = 15,
  11763. SYS_MODE_DEBUG = 16,
  11764. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11765. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11766. SYS_MODE_UPDATE = 19
  11767. };
  11768. */
  11769. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11770. {
  11771. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11772. goto end;
  11773. }
  11774. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11775. {
  11776. //check Transaction active
  11777. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11778. {
  11779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11780. {
  11781. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11782. }
  11783. else
  11784. {
  11785. tempIndex = connectorIdInt -1;
  11786. }
  11787. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11788. {
  11789. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11790. {
  11791. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11792. {
  11793. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11794. {
  11795. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11796. {
  11797. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11798. {
  11799. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11800. }
  11801. else
  11802. {
  11803. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11804. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11805. }
  11806. }
  11807. 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'))
  11808. {
  11809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11810. }
  11811. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11812. {
  11813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11814. }
  11815. else
  11816. {
  11817. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11818. }
  11819. }
  11820. 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
  11821. {
  11822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11823. }
  11824. }
  11825. else
  11826. {
  11827. //replace reservation
  11828. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11830. }
  11831. }
  11832. } // END FOR CHAdeMO_QUANTITY
  11833. }
  11834. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11835. {
  11836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11837. {
  11838. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11839. }
  11840. else
  11841. {
  11842. tempIndex = connectorIdInt -1;
  11843. }
  11844. for (int index = 0; index < CCS_QUANTITY; index++)
  11845. {
  11846. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11847. {
  11848. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11849. {
  11850. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11851. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11852. {
  11853. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11854. {
  11855. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11856. {
  11857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11858. }
  11859. else
  11860. {
  11861. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11863. }
  11864. }
  11865. 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'))
  11866. {
  11867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11868. }
  11869. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11870. {
  11871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11872. }
  11873. else
  11874. {
  11875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11876. }
  11877. }
  11878. 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
  11879. {
  11880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11881. }
  11882. }
  11883. else
  11884. {
  11885. //replace reservation
  11886. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11887. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11888. }
  11889. }
  11890. } // END FOR CCS_QUANTITY
  11891. }
  11892. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11893. {
  11894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11895. {
  11896. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11897. }
  11898. else
  11899. {
  11900. tempIndex = connectorIdInt -1;
  11901. }
  11902. for (int index = 0; index < GB_QUANTITY; index++)
  11903. {
  11904. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11905. {
  11906. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11907. {
  11908. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11909. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11910. {
  11911. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11912. {
  11913. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11914. {
  11915. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11916. }
  11917. else
  11918. {
  11919. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11920. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11921. }
  11922. }
  11923. 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'))
  11924. {
  11925. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11926. }
  11927. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11928. {
  11929. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11930. }
  11931. else
  11932. {
  11933. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11934. }
  11935. }
  11936. 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
  11937. {
  11938. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11939. }
  11940. }
  11941. else
  11942. {
  11943. //replace reservation
  11944. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11945. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11946. }
  11947. }
  11948. }// END FOR GB_QUANTITY
  11949. }
  11950. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11951. {
  11952. tempIndex = connectorIdInt -1;
  11953. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11954. {
  11955. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11956. {
  11957. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11958. {
  11959. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11960. 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
  11961. {
  11962. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11963. {
  11964. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11965. {
  11966. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11967. }
  11968. else
  11969. {
  11970. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11972. }
  11973. }
  11974. 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'))
  11975. {
  11976. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11977. }
  11978. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11979. {
  11980. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11981. }
  11982. else
  11983. {
  11984. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11985. }
  11986. }
  11987. 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
  11988. {
  11989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11990. }
  11991. }
  11992. else
  11993. {
  11994. //replace reservation
  11995. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11997. }
  11998. }
  11999. }// END FOR GB_QUANTITY
  12000. }
  12001. else
  12002. {
  12003. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12004. {
  12005. tempIndex = 2;
  12006. }
  12007. else
  12008. {
  12009. tempIndex = (connectorIdInt -1);
  12010. }
  12011. for (int index = 0; index < AC_QUANTITY; index++)
  12012. {
  12013. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12014. {
  12015. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12016. {
  12017. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12018. {
  12019. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12020. {
  12021. 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))
  12022. {
  12023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12024. }
  12025. else
  12026. {
  12027. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12028. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12029. }
  12030. }
  12031. 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'))
  12032. {
  12033. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12034. }
  12035. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12036. {
  12037. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12038. }
  12039. else
  12040. {
  12041. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12042. }
  12043. }
  12044. 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
  12045. {
  12046. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12047. }
  12048. }
  12049. else
  12050. {
  12051. //replace reservation
  12052. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12053. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12054. }
  12055. }
  12056. } // END FOR AC_QUANTITY
  12057. }
  12058. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12059. }
  12060. else if(connectorIdInt == 0)
  12061. {
  12062. //check Transaction active
  12063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12064. {
  12065. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12066. {
  12067. 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'))
  12068. {
  12069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12070. goto end;
  12071. }
  12072. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12073. {
  12074. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12075. goto end;
  12076. }
  12077. 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
  12078. {
  12079. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12080. goto end;
  12081. }
  12082. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12083. {
  12084. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12085. goto end;
  12086. }
  12087. }
  12088. }// END FOR CHAdeMO_QUANTITY
  12089. for (int index = 0; index < CCS_QUANTITY; index++)
  12090. {
  12091. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12092. {
  12093. 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'))
  12094. {
  12095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12096. goto end;
  12097. }
  12098. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12099. {
  12100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12101. goto end;
  12102. }
  12103. 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
  12104. {
  12105. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12106. goto end;
  12107. }
  12108. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12109. {
  12110. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12111. goto end;
  12112. }
  12113. }
  12114. } // END FOR CCS_QUANTITY
  12115. for (int index = 0; index < GB_QUANTITY; index++)
  12116. {
  12117. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12118. {
  12119. 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'))
  12120. {
  12121. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12122. goto end;
  12123. }
  12124. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12125. {
  12126. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12127. goto end;
  12128. }
  12129. 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
  12130. {
  12131. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12132. goto end;
  12133. }
  12134. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12135. {
  12136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12137. goto end;
  12138. }
  12139. }
  12140. } // END FOR GB_QUANTITY
  12141. for (int index = 0; index < AC_QUANTITY; index++)
  12142. {
  12143. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12144. {
  12145. 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'))
  12146. {
  12147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12148. goto end;
  12149. }
  12150. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12151. {
  12152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12153. goto end;
  12154. }
  12155. 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
  12156. {
  12157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12158. goto end;
  12159. }
  12160. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12161. {
  12162. 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))
  12163. {
  12164. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12165. goto end;
  12166. }
  12167. }
  12168. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12169. {
  12170. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12171. goto end;
  12172. }
  12173. }
  12174. }// END FOR AC_QUANTITY
  12175. //The connectorId is 0
  12176. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12178. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12179. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12180. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12181. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12182. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12183. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12184. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12185. result = TRUE;
  12186. return result;
  12187. }
  12188. else
  12189. {
  12190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12191. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12192. }
  12193. if(strcmp(comfirmstr,"Accepted") == 0)
  12194. {
  12195. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12196. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12197. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12198. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12199. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12200. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12201. result = TRUE;
  12202. return result;
  12203. }
  12204. end:
  12205. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12206. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12207. return result;
  12208. }
  12209. int handleResetRequest(char *uuid, char *payload)
  12210. {
  12211. mtrace();
  12212. int result = FAIL;
  12213. char sstr[10]={0},sstrtemp[30]={ 0 };
  12214. char typestr[10]={0};
  12215. char comfirmstr[20]={0};
  12216. int c = 0;
  12217. char *loc;
  12218. DEBUG_INFO("handleResetRequest...\n");
  12219. strcpy(sstrtemp, stringtrimspace(payload));
  12220. loc = strstr(sstrtemp, "type");
  12221. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12222. c = 0;
  12223. while (loc[3+strlen("type")+c] != '\"')
  12224. {
  12225. sstr[c] = loc[3+strlen("type")+c];
  12226. c++;
  12227. }
  12228. sstr[c] = '\0';
  12229. strcpy(typestr,sstr);
  12230. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12231. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12232. {
  12233. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12234. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12235. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12236. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12237. }
  12238. else
  12239. {
  12240. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12241. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12242. result = PASS;
  12243. }
  12244. sendResetConfirmation(uuid, comfirmstr);
  12245. return result;
  12246. }
  12247. int handleSendLocalListRequest(char *uuid, char *payload)
  12248. {
  12249. mtrace();
  12250. int result = FAIL;
  12251. char comfirmstr[20];
  12252. int checkState_Faulted = FALSE;
  12253. json_object *SendLocalList;
  12254. DEBUG_INFO("handleSendLocalListRequest...\n");
  12255. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12256. {
  12257. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12258. goto end;
  12259. }
  12260. //check Charge Point state
  12261. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12262. {
  12263. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12264. {
  12265. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12266. }
  12267. }
  12268. for (int index = 0; index < CCS_QUANTITY; index++)
  12269. {
  12270. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12271. {
  12272. checkState_Faulted = TRUE; //OCPP Status
  12273. }
  12274. }
  12275. for (int index = 0; index < GB_QUANTITY; index++)
  12276. {
  12277. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12278. {
  12279. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12280. }
  12281. }
  12282. //check Charge Point state
  12283. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12284. {
  12285. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12286. {
  12287. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12288. }
  12289. }
  12290. //check Charge Point state
  12291. for (int index = 0; index < AC_QUANTITY; index++)
  12292. {
  12293. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12294. {
  12295. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12296. }
  12297. }
  12298. if(checkState_Faulted == TRUE)
  12299. {
  12300. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12301. goto end;
  12302. }
  12303. // Parsing payload
  12304. SendLocalList = json_tokener_parse(payload);
  12305. if(!is_error(SendLocalList))
  12306. {
  12307. // Required data
  12308. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12309. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12310. // Optional data
  12311. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12312. {
  12313. //Check UpdateType
  12314. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12315. {
  12316. //Local list full update
  12317. DEBUG_INFO("Local list full update.\n");
  12318. locallistVersion = 0;
  12319. OCPP_getListVerion();
  12320. /*if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12321. {
  12322. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12323. goto end;
  12324. }*/
  12325. OCPP_cleanLocalList();
  12326. }
  12327. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12328. {
  12329. //Local list different update
  12330. DEBUG_INFO("Local list different update.\n");
  12331. locallistVersion = 0;
  12332. OCPP_getListVerion();
  12333. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12334. {
  12335. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12336. goto end;
  12337. }
  12338. }
  12339. else
  12340. {
  12341. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12342. goto end;
  12343. }
  12344. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12345. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12346. {
  12347. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  12348. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12349. {
  12350. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  12351. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12352. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  12353. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12354. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  12355. }
  12356. // Add to db
  12357. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12358. {
  12359. //Local list full update
  12360. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12361. idx,
  12362. ShmOCPP16Data->SendLocalList.ListVersion,
  12363. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12364. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12365. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12366. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12367. // update list
  12368. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12369. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12370. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12371. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12372. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12373. }
  12374. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12375. {
  12376. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12377. idx,
  12378. ShmOCPP16Data->SendLocalList.ListVersion,
  12379. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12380. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12381. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12382. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12383. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12384. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12385. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12386. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12387. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12388. }
  12389. }
  12390. }
  12391. else
  12392. {
  12393. //Check UpdateType
  12394. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12395. {
  12396. //Local list full update
  12397. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12398. OCPP_cleanLocalList();
  12399. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12400. goto end;
  12401. }
  12402. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12403. {
  12404. //Local list different update
  12405. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12406. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12407. goto end;
  12408. }
  12409. }
  12410. result = PASS;
  12411. }
  12412. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12413. end:
  12414. json_object_put(SendLocalList);
  12415. sendSendLocalListConfirmation(uuid, comfirmstr);
  12416. return result;
  12417. }
  12418. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12419. {
  12420. mtrace();
  12421. int result = FAIL;
  12422. struct StructSetChargingProfile SetProfileReq = {0};
  12423. int tempchargingProfileIdInt;
  12424. int tempstackLevelInt;
  12425. int chargingSchedulePeriodCount = 0;
  12426. char comfirmstr[20]={0};
  12427. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12428. char rmFileCmd[128]={0};
  12429. int profileQuantity = 0;
  12430. int replaceableProfileCnt = 0;
  12431. json_object *SetChargingProfile;
  12432. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12433. SetChargingProfile = json_tokener_parse(payload);
  12434. if(!is_error(SetChargingProfile))
  12435. {
  12436. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12437. {
  12438. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12439. }
  12440. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12441. {
  12442. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12443. {
  12444. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12445. }
  12446. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12447. {
  12448. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12449. }
  12450. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12451. {
  12452. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12453. }
  12454. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12455. {
  12456. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12457. }
  12458. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12459. {
  12460. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12461. }
  12462. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12463. {
  12464. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12465. }
  12466. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12467. {
  12468. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12469. }
  12470. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12471. {
  12472. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12473. }
  12474. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12475. {
  12476. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12477. {
  12478. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  12479. }
  12480. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12481. {
  12482. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12483. }
  12484. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12485. {
  12486. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12487. }
  12488. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12489. {
  12490. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  12491. }
  12492. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12493. {
  12494. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12495. if(chargingSchedulePeriodCount <= 10)
  12496. {
  12497. 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++)
  12498. {
  12499. 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)
  12500. {
  12501. SetProfileReq.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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  12502. }
  12503. 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)
  12504. {
  12505. SetProfileReq.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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  12506. }
  12507. 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)
  12508. {
  12509. SetProfileReq.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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  12510. }
  12511. }
  12512. }
  12513. }
  12514. }
  12515. }
  12516. }
  12517. // Profile periods quantity check
  12518. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12519. {
  12520. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12521. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12522. goto end;
  12523. }
  12524. // Check invalid limit
  12525. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12526. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12527. {
  12528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12529. {
  12530. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12531. {
  12532. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  12533. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12534. {
  12535. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12536. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12537. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12538. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12539. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12540. goto end;
  12541. }
  12542. }
  12543. }
  12544. else
  12545. {
  12546. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12547. {
  12548. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower) ||
  12549. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) < (modelnameInfo.ratedPower*0.01)))
  12550. {
  12551. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12552. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12553. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12554. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12555. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12556. goto end;
  12557. }
  12558. }
  12559. }
  12560. }
  12561. // Profile purpose info check
  12562. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12563. {
  12564. FILE *fp;
  12565. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12566. if(SetProfileReq.ConnectorId != 0)
  12567. {
  12568. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12569. DEBUG_WARN("Profile connector id is not 0.\n");
  12570. goto end;
  12571. }
  12572. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12573. if (!fp)
  12574. {
  12575. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12576. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12577. }
  12578. else
  12579. {
  12580. char *line = NULL;
  12581. size_t len = 0;
  12582. while(getline(&line, &len, fp) != -1)
  12583. {
  12584. json_object *obj = NULL;
  12585. obj = json_tokener_parse(line);
  12586. if(is_error(obj))
  12587. {
  12588. DEBUG_ERROR("Parse txProfile from file error.\n");
  12589. }
  12590. else
  12591. {
  12592. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12593. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12594. {
  12595. profileQuantity += 1;
  12596. }
  12597. else
  12598. replaceableProfileCnt += 1;
  12599. }
  12600. }
  12601. }
  12602. fclose(fp);
  12603. }
  12604. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12605. {
  12606. FILE *fp;
  12607. char filename[128]={0};
  12608. int tmpProfileQuantity;
  12609. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12610. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12611. {
  12612. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12613. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12614. goto end;
  12615. }
  12616. if(SetProfileReq.ConnectorId == 0)
  12617. {
  12618. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12619. {
  12620. tmpProfileQuantity = 0;
  12621. memset(filename, 0, ARRAY_SIZE(filename));
  12622. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12623. fp = fopen(filename, "r");
  12624. if (!fp)
  12625. {
  12626. DEBUG_INFO("%s does not create.\n", filename);
  12627. fp = fopen(filename, "w+");
  12628. }
  12629. else
  12630. {
  12631. char *line = NULL;
  12632. size_t len = 0;
  12633. while(getline(&line, &len, fp) != -1)
  12634. {
  12635. json_object *obj = NULL;
  12636. obj = json_tokener_parse(line);
  12637. if(is_error(obj))
  12638. {
  12639. DEBUG_ERROR("Parse txProfile from file error.\n");
  12640. }
  12641. else
  12642. {
  12643. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12644. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12645. {
  12646. tmpProfileQuantity += 1;
  12647. }
  12648. else
  12649. replaceableProfileCnt += 1;
  12650. }
  12651. }
  12652. }
  12653. fclose(fp);
  12654. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12655. }
  12656. }
  12657. else
  12658. {
  12659. memset(filename, 0, ARRAY_SIZE(filename));
  12660. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12661. fp = fopen(filename, "r");
  12662. if (!fp)
  12663. {
  12664. DEBUG_INFO("%s does not create.\n", filename);
  12665. fp = fopen(filename, "w+");
  12666. }
  12667. else
  12668. {
  12669. char *line = NULL;
  12670. size_t len = 0;
  12671. while(getline(&line, &len, fp) != -1)
  12672. {
  12673. json_object *obj = NULL;
  12674. obj = json_tokener_parse(line);
  12675. if(is_error(obj))
  12676. {
  12677. DEBUG_ERROR("Parse txProfile from file error.\n");
  12678. }
  12679. else
  12680. {
  12681. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12682. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12683. {
  12684. profileQuantity += 1;
  12685. }
  12686. else
  12687. replaceableProfileCnt += 1;
  12688. }
  12689. }
  12690. }
  12691. fclose(fp);
  12692. }
  12693. }
  12694. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12695. {
  12696. int isMatchTransactiodId= FALSE;
  12697. FILE *fp;
  12698. char filename[128]={0};
  12699. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12700. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12701. if(SetProfileReq.ConnectorId == 0)
  12702. {
  12703. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12704. DEBUG_WARN("Profile connector id is 0.\n");
  12705. goto end;
  12706. }
  12707. int tempIndex = 0;
  12708. //check Transaction active
  12709. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12710. {
  12711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12712. {
  12713. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12714. }
  12715. else
  12716. {
  12717. tempIndex = SetProfileReq.ConnectorId -1;
  12718. }
  12719. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12720. {
  12721. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12722. {
  12723. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12724. {
  12725. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12726. {
  12727. isMatchTransactiodId = TRUE;
  12728. break;
  12729. }
  12730. }
  12731. }
  12732. }
  12733. }
  12734. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12735. {
  12736. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12737. {
  12738. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12739. }
  12740. else
  12741. {
  12742. tempIndex = SetProfileReq.ConnectorId -1;
  12743. }
  12744. for (int index = 0; index < CCS_QUANTITY; index++)
  12745. {
  12746. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12747. {
  12748. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12749. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12750. {
  12751. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12752. {
  12753. isMatchTransactiodId = TRUE;
  12754. break;
  12755. }
  12756. }
  12757. }
  12758. }
  12759. }
  12760. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12761. {
  12762. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12763. {
  12764. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12765. }
  12766. else
  12767. {
  12768. tempIndex = SetProfileReq.ConnectorId -1;
  12769. }
  12770. for (int index = 0; index < GB_QUANTITY; index++)
  12771. {
  12772. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12773. {
  12774. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12775. {
  12776. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12777. {
  12778. isMatchTransactiodId = TRUE;
  12779. break;
  12780. }
  12781. }
  12782. }
  12783. }
  12784. }
  12785. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12786. {
  12787. tempIndex = SetProfileReq.ConnectorId -1;
  12788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12789. {
  12790. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12791. {
  12792. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12793. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12794. {
  12795. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12796. {
  12797. isMatchTransactiodId = TRUE;
  12798. break;
  12799. }
  12800. }
  12801. }
  12802. }
  12803. }
  12804. else
  12805. {
  12806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12807. {
  12808. tempIndex = 2;
  12809. }
  12810. else
  12811. {
  12812. tempIndex = (SetProfileReq.ConnectorId -1);
  12813. }
  12814. for (int index = 0; index < AC_QUANTITY; index++)
  12815. {
  12816. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12817. {
  12818. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12819. {
  12820. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12821. {
  12822. isMatchTransactiodId = TRUE;
  12823. break;
  12824. }
  12825. }
  12826. }
  12827. }
  12828. }
  12829. //check Transaction active
  12830. if(isMatchTransactiodId == FALSE)
  12831. {
  12832. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12833. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12834. goto end;
  12835. }
  12836. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12837. {
  12838. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12839. DEBUG_WARN("Connector id is over max gun number.\n");
  12840. goto end;
  12841. }
  12842. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12843. fp = fopen(filename, "r");
  12844. if (!fp)
  12845. {
  12846. DEBUG_INFO("%s does not create.\n", filename);
  12847. fp = fopen(filename, "w+");
  12848. }
  12849. else
  12850. {
  12851. char *line = NULL;
  12852. size_t len = 0;
  12853. while(getline(&line, &len, fp) != -1)
  12854. {
  12855. json_object *obj = NULL;
  12856. obj = json_tokener_parse(line);
  12857. if(is_error(obj))
  12858. {
  12859. DEBUG_ERROR("Parse txProfile from file error.\n");
  12860. }
  12861. else
  12862. {
  12863. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12864. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12865. {
  12866. profileQuantity += 1;
  12867. }
  12868. else
  12869. replaceableProfileCnt += 1;
  12870. }
  12871. }
  12872. }
  12873. fclose(fp);
  12874. }
  12875. // Check ChargeProfileMaxStackLevel
  12876. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12877. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12878. {
  12879. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12880. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12881. goto end;
  12882. }
  12883. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12884. {
  12885. FILE *fp;
  12886. char dataLine[4096]={0};
  12887. char fnametemp[128]={0};
  12888. int tmpProfileQuantity;
  12889. //Check ChargePointMaxProfile.json exit
  12890. profileQuantity = 0;
  12891. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12892. {
  12893. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12894. //Check Charging Profile Count
  12895. tmpProfileQuantity = 0;
  12896. while(fscanf(fp, "%s", dataLine) != EOF)
  12897. {
  12898. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12899. {
  12900. profileQuantity += 1;
  12901. tmpProfileQuantity += 1;
  12902. }
  12903. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12904. }
  12905. fclose(fp);
  12906. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12907. }
  12908. //Check TxDefaultProfile_%d.json
  12909. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12910. {
  12911. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12912. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12913. if((access(fnametemp,F_OK))!=-1)
  12914. {
  12915. fp = fopen(fnametemp, "r");
  12916. //Check Charging Profile Count
  12917. tmpProfileQuantity = 0;
  12918. while(fscanf(fp, "%s", dataLine) != EOF)
  12919. {
  12920. //DEBUG_INFO("word=%s\n",word);
  12921. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12922. {
  12923. profileQuantity += 1;
  12924. tmpProfileQuantity += 1;
  12925. }
  12926. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12927. }
  12928. fclose(fp);
  12929. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12930. }
  12931. }
  12932. //Check TxProfile_%d.json
  12933. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12934. {
  12935. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12936. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12937. if((access(fnametemp,F_OK))!=-1)
  12938. {
  12939. fp = fopen(fnametemp, "r");
  12940. //Check Charging Profile Count
  12941. tmpProfileQuantity = 0;
  12942. while(fscanf(fp, "%s", dataLine) != EOF)
  12943. {
  12944. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12945. {
  12946. profileQuantity += 1;
  12947. tmpProfileQuantity += 1;
  12948. }
  12949. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12950. }
  12951. fclose(fp);
  12952. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12953. }
  12954. }
  12955. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12956. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12957. // To check total Profile quantity
  12958. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12959. {
  12960. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12961. {
  12962. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12963. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12964. goto end;
  12965. }
  12966. }
  12967. else
  12968. {
  12969. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12970. {
  12971. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12972. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12973. goto end;
  12974. }
  12975. }
  12976. }
  12977. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12978. //**********************************Write to File********************************************************/
  12979. {
  12980. FILE *infile;
  12981. FILE *outfile;
  12982. char dataLine[4096]={0};
  12983. char filename[128]={0};
  12984. int chkChar=0;
  12985. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12986. {
  12987. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12988. {
  12989. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12990. }
  12991. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12992. {
  12993. if(SetProfileReq.ConnectorId==0)
  12994. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12995. else
  12996. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12997. }
  12998. else
  12999. {
  13000. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13001. }
  13002. infile = fopen (filename, "r");
  13003. outfile = fopen (tempfile, "w");
  13004. chkChar = fgetc(infile);
  13005. rewind(infile);
  13006. if(chkChar == EOF)
  13007. {
  13008. // Profile is empty
  13009. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13010. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13011. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13012. fclose(infile);
  13013. fclose(outfile);
  13014. sprintf(rmFileCmd,"rm -f %s",filename);
  13015. system(rmFileCmd);
  13016. rename(tempfile, filename);
  13017. }
  13018. else
  13019. {
  13020. // Profile is not empty
  13021. int ChargingProfileAdded = FALSE;
  13022. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13023. {
  13024. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13025. json_object *tmpChargingProfile;
  13026. tmpChargingProfile = json_tokener_parse(dataLine);
  13027. if(!is_error(SetChargingProfile))
  13028. {
  13029. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13030. {
  13031. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13032. {
  13033. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13034. }
  13035. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13036. {
  13037. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13038. }
  13039. }
  13040. }
  13041. json_object_put(tmpChargingProfile);
  13042. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13043. {
  13044. if(ChargingProfileAdded == FALSE)
  13045. {
  13046. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13047. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13048. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13049. ChargingProfileAdded = TRUE;
  13050. }
  13051. }
  13052. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13053. {
  13054. if(ChargingProfileAdded == FALSE)
  13055. {
  13056. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13057. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13058. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13059. ChargingProfileAdded = TRUE;
  13060. }
  13061. }
  13062. else
  13063. {
  13064. fprintf(outfile,"%s\n",dataLine);
  13065. if(ChargingProfileAdded == FALSE)
  13066. {
  13067. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13068. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13069. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13070. ChargingProfileAdded = TRUE;
  13071. }
  13072. }
  13073. } // end of while loop
  13074. fclose(infile);
  13075. fclose(outfile);
  13076. sprintf(rmFileCmd,"rm -f %s",filename);
  13077. system(rmFileCmd);
  13078. rename(tempfile, filename);
  13079. }
  13080. }
  13081. sleep(1);
  13082. result = TRUE;
  13083. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13084. }
  13085. end:
  13086. json_object_put(SetChargingProfile);
  13087. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13088. {
  13089. if(SetProfileReq.ConnectorId == 0)
  13090. {
  13091. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13092. {
  13093. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13094. }
  13095. }
  13096. else
  13097. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13098. }
  13099. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13100. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13101. return result;
  13102. }
  13103. int handleTriggerMessageRequest(char *uuid, char *payload)
  13104. {
  13105. mtrace();
  13106. int result = FAIL;
  13107. int connectorIdIsNULL = FALSE;
  13108. int connectorIdInt =0;
  13109. char sstr[40]={0},sstrtemp[100]={ 0 };
  13110. char requestedMessagestr[40]={0};
  13111. char comfirmstr[20]={0};
  13112. int c = 0;
  13113. char *loc;
  13114. DEBUG_INFO("handleTriggerMessageRequest\n");
  13115. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13116. strcpy(sstrtemp, stringtrimspace(payload));
  13117. c = 0;
  13118. loc = strstr(sstrtemp, "requestedMessage");
  13119. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13120. {
  13121. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13122. c++;
  13123. }
  13124. sstr[c] = '\0';
  13125. strcpy(requestedMessagestr, sstr);
  13126. c = 0;
  13127. loc = strstr(sstrtemp, "connectorId");
  13128. if(loc == NULL)
  13129. {
  13130. connectorIdIsNULL = TRUE;
  13131. }
  13132. else
  13133. {
  13134. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13135. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13136. {
  13137. sstr[c] = loc[strlen("connectorId")+2+c];
  13138. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13139. c++;
  13140. }
  13141. sstr[c] = '\0';
  13142. connectorIdInt = atoi(sstr);
  13143. }
  13144. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13145. {
  13146. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13147. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13148. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13149. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13150. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13151. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13152. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13153. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13154. {
  13155. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13156. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13157. return TRUE;
  13158. }
  13159. else
  13160. {
  13161. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13162. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13163. }
  13164. }
  13165. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13166. {
  13167. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13168. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13169. return TRUE;
  13170. }
  13171. //==========================
  13172. // Trigger message
  13173. //==========================
  13174. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13175. {
  13176. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13177. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13178. {
  13179. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13180. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13181. }
  13182. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13183. }
  13184. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13185. {
  13186. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13187. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13188. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13189. }
  13190. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13191. {
  13192. //sendBootNotificationRequest();
  13193. server_sign = FALSE;
  13194. }
  13195. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13196. {
  13197. refreshStartTimer(&clientTime.Heartbeat);
  13198. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13199. }
  13200. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13201. {
  13202. if(connectorIdIsNULL == FALSE)
  13203. {
  13204. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13205. {
  13206. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13207. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13208. }
  13209. }
  13210. else
  13211. {
  13212. for(int idx=0;idx< gunTotalNumber;idx++)
  13213. {
  13214. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13215. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13216. }
  13217. }
  13218. }
  13219. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13220. {
  13221. if(connectorIdIsNULL == FALSE)
  13222. {
  13223. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13224. {
  13225. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13226. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13227. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13228. }
  13229. }
  13230. else
  13231. {
  13232. for(int idx=0;idx< gunTotalNumber;idx++)
  13233. {
  13234. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13235. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13236. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13237. }
  13238. }
  13239. }
  13240. return result;
  13241. }
  13242. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13243. {
  13244. mtrace();
  13245. int result = FAIL;
  13246. int connectorIdInt =0;
  13247. char comfirmstr[20]={0};
  13248. int tempIndex = 0;
  13249. json_object *UnlockConnector;
  13250. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13251. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13252. UnlockConnector = json_tokener_parse(payload);
  13253. if(!is_error(UnlockConnector))
  13254. {
  13255. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13256. {
  13257. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13258. }
  13259. }
  13260. json_object_put(UnlockConnector);
  13261. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13262. if(gunTotalNumber == 0)
  13263. {
  13264. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13265. goto end;
  13266. }
  13267. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13268. {
  13269. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13270. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13271. goto end;
  13272. }
  13273. else
  13274. {
  13275. //check Transaction active
  13276. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13277. {
  13278. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13279. {
  13280. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13281. }
  13282. else
  13283. {
  13284. tempIndex = connectorIdInt -1;
  13285. }
  13286. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13287. {
  13288. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13289. {
  13290. //stop Transaction
  13291. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13292. }
  13293. }
  13294. }
  13295. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13296. {
  13297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13298. {
  13299. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13300. }
  13301. else
  13302. {
  13303. tempIndex = connectorIdInt -1;
  13304. }
  13305. for (int index = 0; index < CCS_QUANTITY; index++)
  13306. {
  13307. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13308. {
  13309. //stop Transaction
  13310. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13311. }
  13312. }
  13313. }
  13314. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13315. {
  13316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13317. {
  13318. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13319. }
  13320. else
  13321. {
  13322. tempIndex = connectorIdInt -1;
  13323. }
  13324. for (int index = 0; index < GB_QUANTITY; index++)
  13325. {
  13326. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13327. {
  13328. //stop Transaction
  13329. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13330. }
  13331. }
  13332. }
  13333. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13334. {
  13335. tempIndex = connectorIdInt -1;
  13336. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13337. {
  13338. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13339. {
  13340. //stop Transaction
  13341. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13342. }
  13343. }
  13344. }
  13345. else
  13346. {
  13347. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13348. {
  13349. tempIndex = 2;
  13350. }
  13351. else
  13352. {
  13353. tempIndex = connectorIdInt-1;
  13354. }
  13355. for (int index = 0; index < AC_QUANTITY; index++)
  13356. {
  13357. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13358. {
  13359. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13360. }
  13361. }
  13362. }
  13363. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13364. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13365. result = TRUE;
  13366. return result;
  13367. }
  13368. end:
  13369. //json_object_put(obj); --- remove temporally
  13370. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13371. return result;
  13372. }
  13373. static char UpdateFirmwarepayloadData[300]={0};
  13374. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13375. {
  13376. mtrace();
  13377. int result = FAIL;
  13378. pthread_t t;
  13379. sendUpdateFirmwareConfirmation(uuid);
  13380. memset(UpdateFirmwarepayloadData, 0, 300);
  13381. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13382. if(!interLock.isUpdateFirmwareGoing)
  13383. {
  13384. interLock.isUpdateFirmwareGoing = 1;
  13385. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13386. sleep(1);
  13387. }
  13388. else
  13389. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13390. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13391. return result;
  13392. }
  13393. void *UpdateFirmwareProcess(void *data)
  13394. {
  13395. pthread_detach(pthread_self());
  13396. mtrace();
  13397. int retriesInt =0, retryIntervalInt=0;
  13398. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13399. int port=0;
  13400. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13401. int isSuccess = 0;
  13402. char ftpbuf[1024];
  13403. char temp[1024];
  13404. char * pch;
  13405. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13406. json_object *UpdateFirmware;
  13407. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13408. if(!is_error(UpdateFirmware))
  13409. {
  13410. // Required data
  13411. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13412. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13413. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13414. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13415. // Optional data
  13416. if(json_object_object_get(UpdateFirmware, "retries"))
  13417. {
  13418. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13419. }
  13420. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13421. {
  13422. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13423. }
  13424. }
  13425. json_object_put(UpdateFirmware);
  13426. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13427. memset(path, 0, ARRAY_SIZE(path));
  13428. // Wait retrieveData
  13429. if(strlen(retrieveDatestr) > 10)
  13430. {
  13431. do
  13432. {
  13433. sleep(1);
  13434. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13435. }
  13436. // Ready to download
  13437. system("rm -f /mnt/*");
  13438. if(strncmp(locationstr,"http", 4) == 0)
  13439. {
  13440. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13441. sprintf(ftppath,"/%s", path);
  13442. DEBUG_INFO("locationstr: %s\n", locationstr);
  13443. DEBUG_INFO("protocol: %s\n",protocol);
  13444. DEBUG_INFO("host: %s\n",host);
  13445. DEBUG_INFO("path: %s\n",path);
  13446. DEBUG_INFO("ftppath: %s\n",ftppath);
  13447. int ftppathlen=strlen(ftppath);
  13448. int i=1;
  13449. char filenametemp[50];
  13450. while(i < ftppathlen)
  13451. {
  13452. int len=ftppathlen-i;
  13453. if(ftppath[len]== 47) // '/' ascll code: 47
  13454. {
  13455. DEBUG_INFO("compare '/' all right\n");
  13456. break;
  13457. }
  13458. i=i+1;
  13459. }
  13460. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13461. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13462. filenametemp[i+1] = 0;
  13463. do
  13464. {
  13465. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13466. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13467. sleep(1);
  13468. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13469. if(!isSuccess)
  13470. {
  13471. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13472. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13473. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13474. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13475. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13476. }
  13477. else
  13478. {
  13479. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13480. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13481. }
  13482. retriesInt--;
  13483. }while((isSuccess == 0)&&(retriesInt >= 0));
  13484. }
  13485. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13486. {
  13487. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13488. memset(temp, 0, ARRAY_SIZE(temp));
  13489. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13490. strcpy(ftpbuf, locationstr);
  13491. int ftppathlen=strlen(ftpbuf);
  13492. int i=1;
  13493. char filenametemp[50];
  13494. while(i < ftppathlen)
  13495. {
  13496. int len=ftppathlen-i;
  13497. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13498. {
  13499. DEBUG_INFO(" compare '/' all right\n");
  13500. break;
  13501. }
  13502. i=i+1;
  13503. }
  13504. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13505. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13506. filenametemp[i+1] = 0;
  13507. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13508. pch=strchr(temp,'@');
  13509. if(pch==NULL)
  13510. {
  13511. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13512. protocol, host, &port, path);
  13513. strcpy(user,"anonymous");
  13514. strcpy(password,"");
  13515. }
  13516. else
  13517. {
  13518. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13519. protocol, user, host, &port, path);
  13520. }
  13521. sscanf(host,"%[^/]%s",host1, path1);
  13522. sprintf(ftppath,"%s:/%s", host,path);
  13523. if(port == 0)
  13524. {
  13525. port = 21;
  13526. }
  13527. do
  13528. {
  13529. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13530. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13531. sleep(1);
  13532. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13533. if(!isSuccess)
  13534. {
  13535. //BulldogUtil.sleepMs(interval*1000);
  13536. DEBUG_INFO("Update firmware request and download file fail.\n");
  13537. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13538. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13539. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13540. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13541. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13542. }
  13543. else
  13544. {
  13545. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13546. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13547. }
  13548. retriesInt--;
  13549. }while((!isSuccess)&&(retriesInt >= 0));
  13550. }
  13551. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13552. {
  13553. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13554. memset(temp, 0, ARRAY_SIZE(temp));
  13555. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13556. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13557. int ftppathlen=strlen(ftpbuf);
  13558. int i=1;
  13559. char filenametemp[50];
  13560. while(i < ftppathlen)
  13561. {
  13562. int len=ftppathlen-i;
  13563. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13564. {
  13565. DEBUG_INFO(" compare '/' all right\n");
  13566. break;
  13567. }
  13568. i=i+1;
  13569. }
  13570. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13571. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13572. filenametemp[i+1] = 0;
  13573. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13574. pch=strchr(temp,'@');
  13575. if(pch==NULL)
  13576. {
  13577. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13578. protocol, host, &port, path);
  13579. strcpy(user,"anonymous");
  13580. strcpy(password,"");
  13581. }
  13582. else
  13583. {
  13584. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13585. protocol, user, password, host, &port, path);
  13586. }
  13587. sscanf(host,"%[^/]%s",host1, path1);
  13588. sprintf(ftppath,"%s", path1);
  13589. //DEBUG_INFO("protocol =%s\n",protocol);
  13590. //DEBUG_INFO("user =%s\n",user);
  13591. //DEBUG_INFO("password =%s\n",password);
  13592. //DEBUG_INFO("host1 =%s\n",host1);
  13593. //DEBUG_INFO("port =%d\n",port);
  13594. //DEBUG_INFO("path1 =%s\n",path1);
  13595. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13596. //ftpFile(host, user, password, port, ftppath, fname);
  13597. //download firmware pthred
  13598. if(port == 0)
  13599. {
  13600. port = 21;
  13601. }
  13602. do
  13603. {
  13604. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13605. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13606. sleep(1);
  13607. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13608. if(!isSuccess)
  13609. {
  13610. //BulldogUtil.sleepMs(interval*1000);
  13611. DEBUG_INFO("Update firmware request and download file fail.\n");
  13612. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13613. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13614. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13615. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13616. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13617. }
  13618. else
  13619. {
  13620. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13621. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13622. }
  13623. retriesInt--;
  13624. }while((!isSuccess)&&(retriesInt >= 0));
  13625. }
  13626. else
  13627. {
  13628. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13629. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13630. sleep(1);
  13631. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13632. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13633. }
  13634. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13635. interLock.isUpdateFirmwareGoing = 0;
  13636. pthread_exit(NULL);
  13637. }
  13638. int handleCertificateSignedRequest(char *uuid, char *payload)
  13639. {
  13640. mtrace();
  13641. int result = PASS;
  13642. json_object *CertificateSigned;
  13643. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13644. CertificateSigned = json_tokener_parse(payload);
  13645. if(!is_error(CertificateSigned))
  13646. {
  13647. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13648. }
  13649. json_object_put(CertificateSigned);
  13650. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13651. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13652. fclose(fp);
  13653. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13654. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13655. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13656. sendCertificateSignedConfirmation(uuid);
  13657. return result;
  13658. }
  13659. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13660. {
  13661. mtrace();
  13662. int result = PASS;
  13663. json_object *DeleteCertificate;
  13664. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13665. DeleteCertificate = json_tokener_parse(payload);
  13666. if(!is_error(DeleteCertificate))
  13667. {
  13668. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13669. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13670. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13671. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13672. }
  13673. json_object_put(DeleteCertificate);
  13674. /*
  13675. * TODO: Delete certificateSigned process
  13676. */
  13677. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13678. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13679. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13680. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13681. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13682. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13683. sendDeleteCertificateConfirmation(uuid);
  13684. return result;
  13685. }
  13686. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13687. {
  13688. mtrace();
  13689. int result = PASS;
  13690. json_object *ExtendedTriggerMessage;
  13691. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13692. ExtendedTriggerMessage = json_tokener_parse(payload);
  13693. if(!is_error(ExtendedTriggerMessage))
  13694. {
  13695. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13696. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13697. {
  13698. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13699. }
  13700. else
  13701. {
  13702. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13703. }
  13704. }
  13705. json_object_put(ExtendedTriggerMessage);
  13706. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13707. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13708. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13709. {
  13710. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13711. }
  13712. else
  13713. {
  13714. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13715. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13716. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13717. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13718. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13719. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13720. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13721. {
  13722. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13723. }
  13724. else
  13725. {
  13726. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13727. }
  13728. }
  13729. sendExtendedTriggerMessageConfirmation(uuid);
  13730. //==========================
  13731. // Trigger message
  13732. //==========================
  13733. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13734. {
  13735. //sendBootNotificationRequest();
  13736. server_sign = FALSE;
  13737. }
  13738. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13739. {
  13740. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13741. }
  13742. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13743. {
  13744. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13745. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13746. {
  13747. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13748. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13749. }
  13750. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13751. }
  13752. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13753. {
  13754. refreshStartTimer(&clientTime.Heartbeat);
  13755. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13756. }
  13757. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13758. {
  13759. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13760. {
  13761. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13762. }
  13763. else
  13764. {
  13765. for(int idx=0;idx< gunTotalNumber;idx++)
  13766. {
  13767. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13768. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13769. }
  13770. }
  13771. }
  13772. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13773. {
  13774. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13775. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13776. {
  13777. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  13778. }
  13779. }
  13780. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13781. {
  13782. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13783. {
  13784. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13785. }
  13786. else
  13787. {
  13788. for(int idx=0;idx< gunTotalNumber;idx++)
  13789. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13790. }
  13791. }
  13792. return result;
  13793. }
  13794. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13795. {
  13796. mtrace();
  13797. int result = PASS;
  13798. json_object *GetInstalledCertificateIds;
  13799. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13800. GetInstalledCertificateIds = json_tokener_parse(payload);
  13801. if(!is_error(GetInstalledCertificateIds))
  13802. {
  13803. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13804. }
  13805. json_object_put(GetInstalledCertificateIds);
  13806. /*
  13807. * TODO: Return installed certificate process
  13808. */
  13809. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13810. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13811. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13812. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13813. sendGetInstalledCertificateIdsConfirmation(uuid);
  13814. return result;
  13815. }
  13816. int handleGetLogRequest(char *uuid, char *payload)
  13817. {
  13818. mtrace();
  13819. int result = PASS;
  13820. json_object *GetLog;
  13821. DEBUG_INFO("handleGetLogRequest...\n");
  13822. GetLog = json_tokener_parse(payload);
  13823. if(!is_error(GetLog))
  13824. {
  13825. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13826. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13827. if(json_object_object_get(GetLog, "retries") != NULL)
  13828. {
  13829. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13830. }
  13831. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13832. {
  13833. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13834. }
  13835. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13836. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13837. {
  13838. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13839. }
  13840. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13841. {
  13842. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13843. }
  13844. }
  13845. json_object_put(GetLog);
  13846. /*
  13847. * TODO: Upload log process
  13848. */
  13849. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13850. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13851. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13852. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13853. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13854. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13855. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13856. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13857. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13858. sendGetLogConfirmation(uuid);
  13859. return result;
  13860. }
  13861. int handleInstallCertificateRequest(char *uuid, char *payload)
  13862. {
  13863. mtrace();
  13864. int result = PASS;
  13865. json_object *InstallCertificate;
  13866. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13867. InstallCertificate = json_tokener_parse(payload);
  13868. if(!is_error(InstallCertificate))
  13869. {
  13870. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13871. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13872. /*
  13873. * TODO: Install certificate process
  13874. */
  13875. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13876. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13877. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13878. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13879. sendInstallCertificateConfirmation(uuid);
  13880. }
  13881. json_object_put(InstallCertificate);
  13882. return result;
  13883. }
  13884. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13885. {
  13886. mtrace();
  13887. int result = PASS;
  13888. json_object *SignedUpdateFirmware;
  13889. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13890. SignedUpdateFirmware = json_tokener_parse(payload);
  13891. if(!is_error(SignedUpdateFirmware))
  13892. {
  13893. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13894. {
  13895. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13896. }
  13897. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13898. {
  13899. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13900. }
  13901. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13902. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13903. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13904. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13905. {
  13906. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13907. }
  13908. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13909. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13910. }
  13911. json_object_put(SignedUpdateFirmware);
  13912. /*
  13913. * TODO: Upgrade firmware process
  13914. */
  13915. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13916. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13917. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13918. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13919. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13920. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13921. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13922. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13923. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13924. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13925. sendInstallCertificateConfirmation(uuid);
  13926. return result;
  13927. }
  13928. int handleUnknownRequest(char *uuid, char *payload)
  13929. {
  13930. mtrace();
  13931. int result = PASS;
  13932. DEBUG_INFO("handleUnknownRequest...\n");
  13933. sendUnknownConfirmation(uuid);
  13934. result = PASS;
  13935. return result;
  13936. }
  13937. //==========================================
  13938. // Handle server response routine
  13939. //==========================================
  13940. void handleAuthorizeResponse(char *payload, int gun_index)
  13941. {
  13942. mtrace();
  13943. char expiryDatestr[36]={0};
  13944. char parentIdTagstr[21]={0};
  13945. char statusstr[20]={0};
  13946. int expiryDateISNULL=FALSE;
  13947. int parentIdTagISNULL=FALSE;
  13948. DEBUG_INFO("handleAuthorizeResponse...\n");
  13949. json_object *Authorize;
  13950. Authorize = json_tokener_parse(payload);
  13951. if(!is_error(Authorize))
  13952. {
  13953. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13954. {
  13955. // Required data
  13956. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13957. // Optional data
  13958. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13959. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13960. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13961. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13962. }
  13963. }
  13964. json_object_put(Authorize);
  13965. if(expiryDateISNULL == FALSE)
  13966. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13967. if(parentIdTagISNULL == FALSE)
  13968. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13969. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13970. //Update idTag information to authorization cache if supproted
  13971. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13972. {
  13973. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13974. }
  13975. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13976. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13977. authorizeRetryTimes = 0;
  13978. }
  13979. void handleBootNotificationResponse(char *payload, int gun_index)
  13980. {
  13981. mtrace();
  13982. char statusStr[12]={0};
  13983. char currentTimeStr[30]={0};
  13984. int intervalInt = 0;
  13985. DEBUG_INFO("handleBootNotificationResponse...\n");
  13986. json_object *BootNotification;
  13987. BootNotification = json_tokener_parse(payload);
  13988. if(!is_error(BootNotification))
  13989. {
  13990. // Required data
  13991. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13992. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13993. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13994. }
  13995. json_object_put(BootNotification);
  13996. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13997. BootNotificationInterval = intervalInt;
  13998. //write back to ShmOCPP16Data->BootNotification
  13999. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  14000. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  14001. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  14002. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  14003. {
  14004. BootNotificationInterval = 0;
  14005. if((intervalInt == 0) || (intervalInt >= 10))
  14006. {
  14007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  14008. HeartBeatWaitTime = intervalInt;
  14009. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  14010. }
  14011. server_sign = TRUE;
  14012. server_pending =FALSE;
  14013. }
  14014. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  14015. {
  14016. server_pending = TRUE;
  14017. }
  14018. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  14019. srand(time(NULL));
  14020. refreshStartTimer(&clientTime.Heartbeat);
  14021. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  14022. SetOcppConnStatus(TRUE);
  14023. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  14024. }
  14025. void handleDataTransferResponse(char *payload, int gun_index)
  14026. {
  14027. json_object *DataTransfer = json_tokener_parse(payload);
  14028. if(!is_error(DataTransfer))
  14029. {
  14030. // Required data
  14031. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  14032. // Optional data
  14033. if(json_object_object_get(DataTransfer, "data") != NULL)
  14034. {
  14035. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14036. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14037. if(!is_error(Data))
  14038. {
  14039. if(json_object_object_get(Data, "msgId") != NULL)
  14040. {
  14041. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  14042. {
  14043. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  14044. }
  14045. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  14046. {
  14047. if(json_object_object_get(Data, "ConnectorId") != NULL)
  14048. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  14049. }
  14050. }
  14051. }
  14052. json_object_put(Data);
  14053. }
  14054. }
  14055. json_object_put(DataTransfer);
  14056. }
  14057. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  14058. {
  14059. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  14060. //struct json_object *obj;
  14061. // obj = json_tokener_parse(payload);
  14062. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  14063. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  14064. //No fields are defined.
  14065. }
  14066. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14067. {
  14068. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  14069. //struct json_object *obj;
  14070. // obj = json_tokener_parse(payload);
  14071. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  14072. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  14073. //No fields are defined.
  14074. }
  14075. void handleHeartbeatResponse(char *payload, int gun_index)
  14076. {
  14077. mtrace();
  14078. DEBUG_INFO("handleHeartbeatResponse...\n");
  14079. json_object *Heartbeat;
  14080. Heartbeat = json_tokener_parse(payload);
  14081. if(!is_error(Heartbeat))
  14082. {
  14083. // Required data
  14084. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  14085. }
  14086. json_object_put(Heartbeat);
  14087. if(FirstHeartBeat == 0)
  14088. {
  14089. FirstHeartBeat = 1;
  14090. DEBUG_INFO("FirstHeartBeat \n");
  14091. }
  14092. HeartBeatWithNOResponse = 0;
  14093. refreshStartTimer(&clientTime.Heartbeat);
  14094. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  14095. }
  14096. void handleMeterValuesResponse(char *payload, int gun_index)
  14097. {
  14098. mtrace();
  14099. DEBUG_INFO("handleMeterValuesResponse...\n");
  14100. isQueueSendable = 1;
  14101. }
  14102. void handleStartTransactionResponse(char *payload, int gun_index)
  14103. {
  14104. mtrace();
  14105. //int transactionIdInt = 0;
  14106. FILE *outfile;
  14107. char data[100]={0};
  14108. DEBUG_INFO("handleStartTransactionResponse...\n");
  14109. json_object *StartTransaction;
  14110. StartTransaction = json_tokener_parse(payload);
  14111. if(!is_error(StartTransaction))
  14112. {
  14113. // Required data
  14114. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  14115. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  14116. // Optional data
  14117. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  14118. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  14119. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14120. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  14121. }
  14122. json_object_put(StartTransaction);
  14123. isQueueSendable = 1;
  14124. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  14125. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  14126. //-----------Start : write to the Queue TransactionId file -----------------//
  14127. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  14128. {}
  14129. else
  14130. {
  14131. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  14132. if(log == NULL)
  14133. {
  14134. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  14135. return ;
  14136. }
  14137. else
  14138. {
  14139. fclose(log);
  14140. }
  14141. }
  14142. // open file for writing
  14143. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  14144. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  14145. {
  14146. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  14147. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  14148. fputs(data, outfile);
  14149. fclose (outfile);
  14150. }
  14151. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14152. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14153. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  14154. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  14155. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14156. }
  14157. void handleStatusNotificationResponse(char *payload, int gun_index)
  14158. {
  14159. mtrace();
  14160. DEBUG_INFO("handleStatusNotificationResponse...\n");
  14161. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  14162. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14163. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  14164. }
  14165. void handleStopTransactionnResponse(char *payload, int gun_index)
  14166. {
  14167. mtrace();
  14168. DEBUG_INFO("handleStopTransactionnResponse...\n");
  14169. json_object *StopTransaction;
  14170. StopTransaction = json_tokener_parse(payload);
  14171. if(!is_error(StopTransaction))
  14172. {
  14173. // Optional data
  14174. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  14175. {
  14176. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  14177. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  14178. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  14179. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14180. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  14181. }
  14182. }
  14183. json_object_put(StopTransaction);
  14184. isQueueSendable = 1;
  14185. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  14186. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  14187. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14188. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14189. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  14190. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  14191. }
  14192. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  14193. {
  14194. mtrace();
  14195. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  14196. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  14197. }
  14198. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  14199. {
  14200. mtrace();
  14201. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  14202. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  14203. }
  14204. void handleSignCertificateResponse(char *payload, int gun_index)
  14205. {
  14206. mtrace();
  14207. DEBUG_INFO("handleSignCertificateResponse...\n");
  14208. json_object *SignCertificate;
  14209. SignCertificate = json_tokener_parse(payload);
  14210. if(!is_error(SignCertificate))
  14211. {
  14212. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  14213. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  14214. }
  14215. json_object_put(SignCertificate);
  14216. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  14217. }
  14218. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14219. {
  14220. mtrace();
  14221. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  14222. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  14223. }
  14224. //==========================================
  14225. // Handle Error routine
  14226. //==========================================
  14227. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14228. {
  14229. mtrace();
  14230. #ifdef SystemLogMessage
  14231. DEBUG_INFO("errorCode: %s\n", errorCode);
  14232. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14233. DEBUG_INFO("errorDetails: %s\n", payload);
  14234. #endif
  14235. }
  14236. //===============================================
  14237. // Common routine
  14238. //===============================================
  14239. int initialConfigurationTable(void)
  14240. {
  14241. //clock_t start_t, end_t, total_t;
  14242. FILE *fp;
  14243. FILE *outfile;
  14244. char str[512]={0};
  14245. char sstr[256]={0};
  14246. int c = 0;
  14247. char *loc;
  14248. int confVersion = 15;
  14249. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14250. //start_t = clock();
  14251. //printf("Starting of the program, start_t = %ld\n", start_t);
  14252. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14253. // Check configuration file size is correct
  14254. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  14255. {
  14256. struct stat st;
  14257. stat("/Storage/OCPP/OCPPConfiguration", &st);
  14258. if(st.st_size < 3100)
  14259. {
  14260. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14261. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14262. }
  14263. }
  14264. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14265. {
  14266. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14267. if(outfile == NULL)
  14268. {
  14269. DEBUG_INFO("Error opening file\n");
  14270. return FALSE;
  14271. }
  14272. /*Core Profile*/
  14273. //AllowOfflineTxForUnknownId
  14274. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14278. //AuthorizationCacheEnabled
  14279. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14283. //AuthorizeRemoteTxRequests
  14284. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14288. //BlinkRepeat
  14289. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14293. //ClockAlignedDataInterval
  14294. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14298. //ConnectionTimeOut
  14299. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14303. //GetConfigurationMaxKeys
  14304. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14308. // HeartbeatInterval
  14309. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14313. // LightIntensity
  14314. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14318. // LocalAuthorizeOffline
  14319. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14323. // LocalPreAuthorize
  14324. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14328. // MaxEnergyOnInvalidId
  14329. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14333. // MeterValuesAlignedData
  14334. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14336. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  14338. else
  14339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14341. // MeterValuesAlignedDataMaxLength
  14342. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14344. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14346. else
  14347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14349. // MeterValuesSampledData
  14350. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  14354. else
  14355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14357. // MeterValuesSampledDataMaxLength
  14358. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14362. else
  14363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14365. // MeterValueSampleInterval
  14366. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14370. // MinimumStatusDuration
  14371. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14374. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14376. // NumberOfConnectors
  14377. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14380. {
  14381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14382. }
  14383. else
  14384. {
  14385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14386. }
  14387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14388. // ResetRetries
  14389. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14393. // ConnectorPhaseRotation
  14394. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14398. // ConnectorPhaseRotationMaxLength
  14399. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14403. // StopTransactionOnEVSideDisconnect
  14404. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14408. // StopTransactionOnInvalidId
  14409. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14413. // StopTxnAlignedData
  14414. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14418. // StopTxnAlignedDataMaxLength
  14419. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14423. // StopTxnSampledData
  14424. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14426. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14428. else
  14429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14431. // StopTxnSampledDataMaxLength
  14432. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14435. {
  14436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14437. }
  14438. else
  14439. {
  14440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14441. }
  14442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14443. // SupportedFeatureProfiles
  14444. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14448. // SupportedFeatureProfilesMaxLength
  14449. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14453. // TransactionMessageAttempts
  14454. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14457. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14459. // TransactionMessageRetryInterval
  14460. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14463. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14465. // UnlockConnectorOnEVSideDisconnect
  14466. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14470. // WebSocketPingInterval
  14471. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14475. // QueueOffLineMeterValues
  14476. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14480. // AuthorizationKey
  14481. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14484. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14485. // SecurityProfile
  14486. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14490. // DefaultPrice
  14491. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14495. // CustomDisplayCostAndPrice
  14496. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14500. // CustomIdleFeeAfterStop
  14501. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14505. // TimeOffset
  14506. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14510. // NextTimeOffsetTransitionDateTime
  14511. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14515. // TimeOffsetNextTransition
  14516. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14520. // SystemUptimeSec
  14521. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14525. // FreeVend
  14526. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14530. // FreeVendIdtag
  14531. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14535. // OcppServer
  14536. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14538. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14540. // MaintainServer
  14541. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14543. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14545. // StatusNotificationPeriodically
  14546. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14550. // StatusNotificationInterval
  14551. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14555. // PreAuthAmount
  14556. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14560. // isEnableLocalPowerSharing
  14561. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14565. // PowerSharingServerIP
  14566. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14568. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14570. // EVCCID_PREFIX
  14571. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14575. // Configuration Version
  14576. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14580. //* Local Auth List Management Profile*/
  14581. #if 0
  14582. //For OCTT Test Case
  14583. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14586. #endif
  14587. #if 1
  14588. //LocalAuthListEnabled
  14589. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14593. #endif
  14594. //LocalAuthListMaxLength
  14595. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14599. //SendLocalListMaxLength
  14600. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14604. //ReserveConnectorZeroSupported
  14605. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14609. //* Smart Charging Profile */
  14610. //ChargeProfileMaxStackLevel
  14611. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14615. // ChargingScheduleAllowedChargingRateUnit
  14616. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14620. // ChargingScheduleMaxPeriods
  14621. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14625. // ConnectorSwitch3to1PhaseSupported
  14626. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14630. // MaxChargingProfilesInstalled
  14631. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14635. fclose(outfile);
  14636. }
  14637. else
  14638. {
  14639. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14640. char keystr[60]={0};
  14641. char readonlystr[10]={0};
  14642. char valuestr[256]={0};
  14643. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14644. if(fp == NULL) {
  14645. DEBUG_INFO("Error opening file");
  14646. return FALSE;
  14647. }
  14648. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14649. {
  14650. //DEBUG_INFO("Get Configuration \n");
  14651. if(strlen(str) > 0)
  14652. {
  14653. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14654. //*************************key*********************************/
  14655. if(strstr(str, "key") != NULL)
  14656. {
  14657. loc = strstr(str, "key");
  14658. c = 0;
  14659. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14660. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14661. {
  14662. sstr[c] = loc[strlen("key")+3+c];
  14663. c++;
  14664. }
  14665. sstr[c] = '\0';
  14666. strcpy(keystr,sstr);
  14667. }
  14668. //*************************readonly*********************************/
  14669. if(strstr(str, "readonly") != NULL)
  14670. {
  14671. loc = strstr(str, "readonly");
  14672. c = 0;
  14673. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14674. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14675. {
  14676. sstr[c] = loc[strlen("readonly")+2+c];
  14677. c++;
  14678. }
  14679. sstr[c] = '\0';
  14680. strcpy(readonlystr,sstr);
  14681. }
  14682. //*************************value*********************************/
  14683. if(strstr(str, "value") != NULL)
  14684. {
  14685. loc = strstr(str, "value");
  14686. c = 0;
  14687. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14688. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14689. {
  14690. sstr[c] = loc[strlen("value")+3+c];
  14691. c++;
  14692. }
  14693. sstr[c] = '\0';
  14694. strcpy(valuestr,sstr);
  14695. }
  14696. // DEBUG_INFO("keystr=%s\n",keystr);
  14697. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14698. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14699. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14700. {
  14701. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14702. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14704. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14705. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14706. }
  14707. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14708. {
  14709. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14710. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14712. }
  14713. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14714. {
  14715. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14717. }
  14718. if(strcmp(keystr, "BlinkRepeat") == 0)
  14719. {
  14720. //Charger.BlinkRepeat = Integer.parseInt(value);
  14721. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14723. }
  14724. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14725. {
  14726. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14728. }
  14729. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14730. {
  14731. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14733. }
  14734. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14735. {
  14736. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14738. }
  14739. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14740. {
  14741. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14743. HeartBeatWaitTime = atoi(valuestr);
  14744. }
  14745. if(strcmp(keystr, "LightIntensity") == 0)
  14746. {
  14747. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14749. }
  14750. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14751. {
  14752. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14754. }
  14755. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14756. {
  14757. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14759. }
  14760. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14761. {
  14762. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14764. }
  14765. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14766. {
  14767. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14769. }
  14770. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14771. {
  14772. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14774. }
  14775. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14776. {
  14777. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14779. }
  14780. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14781. {
  14782. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14784. }
  14785. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14786. {
  14787. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14789. }
  14790. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14791. {
  14792. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14794. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14795. }
  14796. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14797. {
  14798. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14800. }
  14801. if(strcmp(keystr, "ResetRetries") == 0)
  14802. {
  14803. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14805. }
  14806. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14807. {
  14808. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14810. }
  14811. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14812. {
  14813. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14815. }
  14816. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14817. {
  14818. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14820. }
  14821. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14822. {
  14823. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14825. }
  14826. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14827. {
  14828. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14830. }
  14831. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14832. {
  14833. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14835. }
  14836. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14837. {
  14838. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14840. }
  14841. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14842. {
  14843. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14845. }
  14846. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14847. {
  14848. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14850. }
  14851. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14852. {
  14853. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14855. }
  14856. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14857. {
  14858. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14860. TransactionMessageAttemptsValue = atoi(valuestr);
  14861. }
  14862. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14863. {
  14864. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14866. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14867. }
  14868. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14869. {
  14870. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14872. }
  14873. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14874. {
  14875. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14877. }
  14878. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14879. {
  14880. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14882. }
  14883. if(strcmp(keystr, "AuthorizationKey") == 0)
  14884. {
  14885. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14886. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14888. }
  14889. if(strcmp(keystr, "SecurityProfile") == 0)
  14890. {
  14891. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14893. }
  14894. if(strcmp(keystr, "DefaultPrice") == 0)
  14895. {
  14896. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14898. }
  14899. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14900. {
  14901. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14903. }
  14904. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14905. {
  14906. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14908. }
  14909. if(strcmp(keystr, "TimeOffset") == 0)
  14910. {
  14911. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14913. }
  14914. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14915. {
  14916. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14918. }
  14919. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14920. {
  14921. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14923. }
  14924. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14925. {
  14926. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14928. }
  14929. if(strcmp(keystr, "FreeVend") == 0)
  14930. {
  14931. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14933. }
  14934. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14935. {
  14936. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14938. }
  14939. if(strcmp(keystr, "OcppServer") == 0)
  14940. {
  14941. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14942. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14943. }
  14944. if(strcmp(keystr, "MaintainServer") == 0)
  14945. {
  14946. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14947. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14948. }
  14949. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14950. {
  14951. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14952. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14953. }
  14954. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14955. {
  14956. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14958. }
  14959. if(strcmp(keystr, "PreAuthAmount") == 0)
  14960. {
  14961. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14962. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  14963. }
  14964. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14965. {
  14966. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14968. }
  14969. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14970. {
  14971. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14972. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14973. }
  14974. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14975. {
  14976. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14978. }
  14979. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14980. {
  14981. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14983. }
  14984. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14985. {
  14986. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14988. }
  14989. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14990. {
  14991. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14993. }
  14994. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14995. {
  14996. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14998. }
  14999. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  15000. {
  15001. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  15003. }
  15004. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  15005. {
  15006. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  15008. }
  15009. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15010. {
  15011. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  15013. }
  15014. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  15015. {
  15016. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  15018. }
  15019. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  15020. {
  15021. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  15023. }
  15024. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  15025. {
  15026. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  15028. }
  15029. }
  15030. }
  15031. fclose(fp);
  15032. }
  15033. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  15034. {
  15035. return PASS;
  15036. }
  15037. else
  15038. {
  15039. return FAIL;
  15040. }
  15041. }
  15042. void StoreConfigurationTable(void)
  15043. {
  15044. FILE *outfile;
  15045. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15046. if(outfile == NULL)
  15047. {
  15048. DEBUG_INFO("Error opening file");
  15049. return ;
  15050. }
  15051. /*Core Profile*/
  15052. //AllowOfflineTxForUnknownId
  15053. /*
  15054. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15055. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  15056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  15058. */
  15059. //DEBUG_INFO("data=%s\n",data);
  15060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15061. //AuthorizationCacheEnabled
  15062. /*
  15063. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15066. */
  15067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15068. //AuthorizeRemoteTxRequests
  15069. /*
  15070. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  15071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  15073. */
  15074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15075. //BlinkRepeat
  15076. /*
  15077. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15080. */
  15081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15082. //ClockAlignedDataInterval
  15083. /*
  15084. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15087. */
  15088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15089. //ConnectionTimeOut
  15090. /*
  15091. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15094. */
  15095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15096. //GetConfigurationMaxKeys
  15097. /*
  15098. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  15101. */
  15102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15103. // HeartbeatInterval
  15104. /*
  15105. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  15108. */
  15109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15110. // LightIntensity
  15111. /*
  15112. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15115. */
  15116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15117. // LocalAuthorizeOffline
  15118. /*
  15119. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  15120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15122. */
  15123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15124. // LocalPreAuthorize
  15125. /*
  15126. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  15127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15129. */
  15130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15131. // MaxEnergyOnInvalidId
  15132. /*
  15133. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15136. */
  15137. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  15138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15139. // MeterValuesAlignedData
  15140. /*
  15141. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15144. */
  15145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15146. // MeterValuesAlignedDataMaxLength
  15147. /*
  15148. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  15151. */
  15152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15153. // MeterValuesSampledData
  15154. /*
  15155. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15158. */
  15159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15160. // MeterValuesSampledDataMaxLength
  15161. /*
  15162. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  15165. */
  15166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15167. // MeterValueSampleInterval
  15168. /*
  15169. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  15172. */
  15173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15174. // MinimumStatusDuration
  15175. /*
  15176. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  15179. */
  15180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15181. // NumberOfConnectors
  15182. /*
  15183. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15185. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15186. {
  15187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15188. }
  15189. else
  15190. {
  15191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15192. }
  15193. */
  15194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15195. // ResetRetries
  15196. /*
  15197. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15200. */
  15201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15202. // ConnectorPhaseRotation
  15203. /*
  15204. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15207. */
  15208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15209. // ConnectorPhaseRotationMaxLength
  15210. /*
  15211. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15214. */
  15215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15216. // StopTransactionOnEVSideDisconnect
  15217. /*
  15218. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  15219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15221. */
  15222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15223. // StopTransactionOnInvalidId
  15224. /*
  15225. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  15226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15228. */
  15229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15230. // StopTxnAlignedData
  15231. /*
  15232. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  15235. */
  15236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15237. // StopTxnAlignedDataMaxLength
  15238. /*
  15239. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15242. */
  15243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15244. // StopTxnSampledData
  15245. /*
  15246. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  15249. */
  15250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15251. // StopTxnSampledDataMaxLength
  15252. /*
  15253. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15256. */
  15257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15258. // SupportedFeatureProfiles
  15259. /*
  15260. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15263. */
  15264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15265. // SupportedFeatureProfilesMaxLength
  15266. /*
  15267. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15270. */
  15271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15272. // TransactionMessageAttempts
  15273. /*
  15274. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15277. */
  15278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15279. // TransactionMessageRetryInterval
  15280. /*
  15281. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15284. */
  15285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15286. // UnlockConnectorOnEVSideDisconnect
  15287. /*
  15288. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15291. */
  15292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15293. // WebSocketPingInterval
  15294. /*
  15295. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15298. */
  15299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15300. // QueueOffLineMeterValues
  15301. /*
  15302. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15305. */
  15306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15307. // AuthorizationKey
  15308. /*
  15309. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15312. */
  15313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15314. // SecurityProfile
  15315. /*
  15316. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15319. */
  15320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15321. // DefaultPrice
  15322. /*
  15323. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15326. */
  15327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15328. // CustomDisplayCostAndPrice
  15329. /*
  15330. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15333. */
  15334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15335. // CustomIdleFeeAfterStop
  15336. /*
  15337. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15340. */
  15341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15342. // TimeOffset
  15343. /*
  15344. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15347. */
  15348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15349. // NextTimeOffsetTransitionDateTime
  15350. /*
  15351. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15354. */
  15355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15356. // TimeOffsetNextTransition
  15357. /*
  15358. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15361. */
  15362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15363. // SystemUptimeSec
  15364. /*
  15365. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15368. */
  15369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15370. // FreeVend
  15371. /*
  15372. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15375. */
  15376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15377. // FreeVendIdtag
  15378. /*
  15379. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15382. */
  15383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15384. // OcppServer
  15385. /*
  15386. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15389. */
  15390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15391. // MaintainServer
  15392. /*
  15393. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15396. */
  15397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15398. // StatusNotificationPeriodically
  15399. /*
  15400. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15403. */
  15404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15405. // StatusNotificationInterval
  15406. /*
  15407. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15410. */
  15411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15412. // PreAuthAmount
  15413. /*
  15414. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15417. */
  15418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15419. // isEnableLocalPowerSharing
  15420. /*
  15421. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15424. */
  15425. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15426. // PowerSharingServerIP
  15427. /*
  15428. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15431. */
  15432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15433. // EVCCID_PREFIX
  15434. /*
  15435. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15438. */
  15439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15440. // ConfigurationVersion
  15441. /*
  15442. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15445. */
  15446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15447. //* Local Auth List Management Profile*/
  15448. //LocalAuthListEnabled
  15449. /*
  15450. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15453. */
  15454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15455. //LocalAuthListMaxLength
  15456. /*
  15457. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15460. */
  15461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15462. //SendLocalListMaxLength
  15463. /*
  15464. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15467. */
  15468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15469. //ReserveConnectorZeroSupported
  15470. /*
  15471. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15474. */
  15475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15476. //* Smart Charging Profile */
  15477. //ChargeProfileMaxStackLevel
  15478. /*
  15479. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15482. */
  15483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15484. // ChargingScheduleAllowedChargingRateUnit
  15485. /*
  15486. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15489. */
  15490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15491. // ChargingScheduleMaxPeriods
  15492. /*
  15493. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15496. */
  15497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15498. // ConnectorSwitch3to1PhaseSupported
  15499. /*
  15500. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15503. */
  15504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15505. // MaxChargingProfilesInstalled
  15506. /*
  15507. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15510. */
  15511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15512. fclose(outfile);
  15513. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15514. }
  15515. void getKeyValue(char *keyReq)
  15516. {
  15517. int isEmpty = FALSE;
  15518. int isKnowKey = FALSE;
  15519. DEBUG_INFO("keyReq = %s\n", keyReq);
  15520. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15521. isEmpty = TRUE;
  15522. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15523. {
  15524. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15527. {
  15528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15529. }
  15530. else
  15531. {
  15532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15533. }
  15534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15535. isKnowKey = TRUE;
  15536. }
  15537. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15538. {
  15539. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15542. {
  15543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15544. }
  15545. else
  15546. {
  15547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15548. }
  15549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15550. isKnowKey = TRUE;
  15551. }
  15552. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15553. {
  15554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15557. {
  15558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15559. }
  15560. else
  15561. {
  15562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15563. }
  15564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15565. isKnowKey = TRUE;
  15566. }
  15567. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15568. {
  15569. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15572. {
  15573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15574. }
  15575. else
  15576. {
  15577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15578. }
  15579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15580. isKnowKey = TRUE;
  15581. }
  15582. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15583. {
  15584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15587. {
  15588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15589. }
  15590. else
  15591. {
  15592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15593. }
  15594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15595. isKnowKey = TRUE;
  15596. }
  15597. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15598. {
  15599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15602. {
  15603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15604. }
  15605. else
  15606. {
  15607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15608. }
  15609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15610. isKnowKey = TRUE;
  15611. }
  15612. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15613. {
  15614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15617. {
  15618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15619. }
  15620. else
  15621. {
  15622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15623. }
  15624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15625. isKnowKey = TRUE;
  15626. }
  15627. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15628. {
  15629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15632. {
  15633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15634. }
  15635. else
  15636. {
  15637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15638. }
  15639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15640. isKnowKey = TRUE;
  15641. }
  15642. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15643. {
  15644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15647. {
  15648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15649. }
  15650. else
  15651. {
  15652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15653. }
  15654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15655. isKnowKey = TRUE;
  15656. }
  15657. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15658. {
  15659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15662. {
  15663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15664. }
  15665. else
  15666. {
  15667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15668. }
  15669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15670. isKnowKey = TRUE;
  15671. }
  15672. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15673. {
  15674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15677. {
  15678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15679. }
  15680. else
  15681. {
  15682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15683. }
  15684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15685. isKnowKey = TRUE;
  15686. }
  15687. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15688. {
  15689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15692. {
  15693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15694. }
  15695. else
  15696. {
  15697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15698. }
  15699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15700. isKnowKey = TRUE;
  15701. }
  15702. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15703. {
  15704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15707. {
  15708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15709. }
  15710. else
  15711. {
  15712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15713. }
  15714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15715. isKnowKey = TRUE;
  15716. }
  15717. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15718. {
  15719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15722. {
  15723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15724. }
  15725. else
  15726. {
  15727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15728. }
  15729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15730. isKnowKey = TRUE;
  15731. }
  15732. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15733. {
  15734. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15737. {
  15738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15739. }
  15740. else
  15741. {
  15742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15743. }
  15744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15745. isKnowKey = TRUE;
  15746. }
  15747. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15748. {
  15749. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15752. {
  15753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15754. }
  15755. else
  15756. {
  15757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15758. }
  15759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15760. isKnowKey = TRUE;
  15761. }
  15762. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15763. {
  15764. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15767. {
  15768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15769. }
  15770. else
  15771. {
  15772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15773. }
  15774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15775. isKnowKey = TRUE;
  15776. }
  15777. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15778. {
  15779. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15781. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15782. {
  15783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15784. }
  15785. else
  15786. {
  15787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15788. }
  15789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15790. isKnowKey = TRUE;
  15791. }
  15792. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15793. {
  15794. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15796. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15797. {
  15798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15799. }
  15800. else
  15801. {
  15802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15803. }
  15804. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15806. isKnowKey = TRUE;
  15807. }
  15808. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15809. {
  15810. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15813. {
  15814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15815. }
  15816. else
  15817. {
  15818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15819. }
  15820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15821. isKnowKey = TRUE;
  15822. }
  15823. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15824. {
  15825. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15828. {
  15829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15830. }
  15831. else
  15832. {
  15833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15834. }
  15835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15836. isKnowKey = TRUE;
  15837. }
  15838. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15839. {
  15840. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15843. {
  15844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15845. }
  15846. else
  15847. {
  15848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15849. }
  15850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15851. isKnowKey = TRUE;
  15852. }
  15853. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15854. {
  15855. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15858. {
  15859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15860. }
  15861. else
  15862. {
  15863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15864. }
  15865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15866. isKnowKey = TRUE;
  15867. }
  15868. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15869. {
  15870. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15873. {
  15874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15875. }
  15876. else
  15877. {
  15878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15879. }
  15880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15881. isKnowKey = TRUE;
  15882. }
  15883. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15884. {
  15885. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15888. {
  15889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15890. }
  15891. else
  15892. {
  15893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15894. }
  15895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15896. isKnowKey = TRUE;
  15897. }
  15898. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15899. {
  15900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15903. {
  15904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15905. }
  15906. else
  15907. {
  15908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15909. }
  15910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15911. isKnowKey = TRUE;
  15912. }
  15913. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15914. {
  15915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15917. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15918. {
  15919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15920. }
  15921. else
  15922. {
  15923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15924. }
  15925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15926. isKnowKey = TRUE;
  15927. }
  15928. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15929. {
  15930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15933. {
  15934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15935. }
  15936. else
  15937. {
  15938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15939. }
  15940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15941. isKnowKey = TRUE;
  15942. }
  15943. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15944. {
  15945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15948. {
  15949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15950. }
  15951. else
  15952. {
  15953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15954. }
  15955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15956. isKnowKey = TRUE;
  15957. }
  15958. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15959. {
  15960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15962. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15963. {
  15964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15965. }
  15966. else
  15967. {
  15968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15969. }
  15970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15971. isKnowKey = TRUE;
  15972. }
  15973. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15974. {
  15975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15978. {
  15979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15980. }
  15981. else
  15982. {
  15983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15984. }
  15985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15986. isKnowKey = TRUE;
  15987. }
  15988. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15989. {
  15990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15993. {
  15994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15995. }
  15996. else
  15997. {
  15998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15999. }
  16000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  16001. isKnowKey = TRUE;
  16002. }
  16003. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  16004. {
  16005. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  16006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  16007. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16008. {
  16009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  16010. }
  16011. else
  16012. {
  16013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  16014. }
  16015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  16016. isKnowKey = TRUE;
  16017. }
  16018. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  16019. {
  16020. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  16021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  16022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16023. {
  16024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  16025. }
  16026. else
  16027. {
  16028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  16029. }
  16030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  16031. isKnowKey = TRUE;
  16032. }
  16033. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  16034. {
  16035. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  16036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  16037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16038. {
  16039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  16040. }
  16041. else
  16042. {
  16043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  16044. }
  16045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  16046. isKnowKey = TRUE;
  16047. }
  16048. /*
  16049. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  16050. {
  16051. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  16052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  16053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  16054. {
  16055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  16056. }
  16057. else
  16058. {
  16059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  16060. }
  16061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  16062. isKnowKey = TRUE;
  16063. }*/
  16064. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  16065. {
  16066. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  16067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  16068. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16069. {
  16070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  16071. }
  16072. else
  16073. {
  16074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  16075. }
  16076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  16077. isKnowKey = TRUE;
  16078. }
  16079. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  16080. {
  16081. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  16082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  16083. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  16084. {
  16085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  16086. }
  16087. else
  16088. {
  16089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  16090. }
  16091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  16092. isKnowKey = TRUE;
  16093. }
  16094. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  16095. {
  16096. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  16097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  16098. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16099. {
  16100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  16101. }
  16102. else
  16103. {
  16104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  16105. }
  16106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  16107. isKnowKey = TRUE;
  16108. }
  16109. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  16110. {
  16111. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  16112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  16113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16114. {
  16115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  16116. }
  16117. else
  16118. {
  16119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  16120. }
  16121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  16122. isKnowKey = TRUE;
  16123. }
  16124. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  16125. {
  16126. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  16127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  16128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16129. {
  16130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  16131. }
  16132. else
  16133. {
  16134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  16135. }
  16136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  16137. isKnowKey = TRUE;
  16138. }
  16139. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  16140. {
  16141. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  16142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  16143. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16144. {
  16145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  16146. }
  16147. else
  16148. {
  16149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  16150. }
  16151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  16152. isKnowKey = TRUE;
  16153. }
  16154. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  16155. {
  16156. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  16157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  16158. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16159. {
  16160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  16161. }
  16162. else
  16163. {
  16164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  16165. }
  16166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  16167. isKnowKey = TRUE;
  16168. }
  16169. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  16170. {
  16171. struct sysinfo s_info;
  16172. int error = sysinfo(&s_info);
  16173. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  16174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  16175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  16176. {
  16177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  16178. }
  16179. else
  16180. {
  16181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  16182. }
  16183. if(error != 0)
  16184. {
  16185. DEBUG_WARN("System uptime get error: %d\n", error);
  16186. }
  16187. else
  16188. {
  16189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  16190. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  16191. }
  16192. isKnowKey = TRUE;
  16193. }
  16194. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  16195. {
  16196. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  16197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  16198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16199. {
  16200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  16201. }
  16202. else
  16203. {
  16204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  16205. }
  16206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  16207. isKnowKey = TRUE;
  16208. }
  16209. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  16210. {
  16211. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  16212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  16213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16214. {
  16215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  16216. }
  16217. else
  16218. {
  16219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  16220. }
  16221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16222. isKnowKey = TRUE;
  16223. }
  16224. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  16225. {
  16226. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  16227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  16228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16229. {
  16230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  16231. }
  16232. else
  16233. {
  16234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  16235. }
  16236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16237. isKnowKey = TRUE;
  16238. }
  16239. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  16240. {
  16241. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  16242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  16243. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16244. {
  16245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  16246. }
  16247. else
  16248. {
  16249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  16250. }
  16251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16252. isKnowKey = TRUE;
  16253. }
  16254. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  16255. {
  16256. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  16257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  16258. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16259. {
  16260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  16261. }
  16262. else
  16263. {
  16264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  16265. }
  16266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  16267. isKnowKey = TRUE;
  16268. }
  16269. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  16270. {
  16271. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  16272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  16273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16274. {
  16275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  16276. }
  16277. else
  16278. {
  16279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  16280. }
  16281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  16282. isKnowKey = TRUE;
  16283. }
  16284. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  16285. {
  16286. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  16287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  16288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  16289. {
  16290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  16291. }
  16292. else
  16293. {
  16294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  16295. }
  16296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  16297. isKnowKey = TRUE;
  16298. }
  16299. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  16300. {
  16301. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  16302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  16303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16304. {
  16305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  16306. }
  16307. else
  16308. {
  16309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  16310. }
  16311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  16312. isKnowKey = TRUE;
  16313. }
  16314. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  16315. {
  16316. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  16317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  16318. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16319. {
  16320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  16321. }
  16322. else
  16323. {
  16324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  16325. }
  16326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  16327. isKnowKey = TRUE;
  16328. }
  16329. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  16330. {
  16331. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  16332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  16333. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16334. {
  16335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  16336. }
  16337. else
  16338. {
  16339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16340. }
  16341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16342. isKnowKey = TRUE;
  16343. }
  16344. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16345. {
  16346. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16348. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16349. {
  16350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16351. }
  16352. else
  16353. {
  16354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16355. }
  16356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16357. isKnowKey = TRUE;
  16358. }
  16359. #if 1
  16360. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16361. {
  16362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16364. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16365. {
  16366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16367. }
  16368. else
  16369. {
  16370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16371. }
  16372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16373. isKnowKey = TRUE;
  16374. }
  16375. #endif
  16376. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16377. {
  16378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16380. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16381. {
  16382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16383. }
  16384. else
  16385. {
  16386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16387. }
  16388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16389. isKnowKey = TRUE;
  16390. }
  16391. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16392. {
  16393. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16395. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16396. {
  16397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16398. }
  16399. else
  16400. {
  16401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16402. }
  16403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16404. isKnowKey = TRUE;
  16405. }
  16406. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16407. {
  16408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16410. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16411. {
  16412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16413. }
  16414. else
  16415. {
  16416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16417. }
  16418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16419. isKnowKey = TRUE;
  16420. }
  16421. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16422. {
  16423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16425. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16426. {
  16427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16428. }
  16429. else
  16430. {
  16431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16432. }
  16433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16434. isKnowKey = TRUE;
  16435. }
  16436. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16437. {
  16438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16440. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16441. {
  16442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16443. }
  16444. else
  16445. {
  16446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16447. }
  16448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16449. isKnowKey = TRUE;
  16450. }
  16451. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16452. {
  16453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16455. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16456. {
  16457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16458. }
  16459. else
  16460. {
  16461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16462. }
  16463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16464. isKnowKey = TRUE;
  16465. }
  16466. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16467. {
  16468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16470. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16471. {
  16472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16473. }
  16474. else
  16475. {
  16476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16477. }
  16478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16479. isKnowKey = TRUE;
  16480. }
  16481. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16482. {
  16483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16485. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16486. {
  16487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16488. }
  16489. else
  16490. {
  16491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16492. }
  16493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16494. isKnowKey = TRUE;
  16495. }
  16496. //=========================================================
  16497. if(!isEmpty && !isKnowKey)
  16498. {
  16499. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16500. strcpy(unknownkey[UnknownKeynum], keyReq);
  16501. UnknownKeynum = UnknownKeynum + 1;
  16502. }
  16503. }
  16504. void processUnkownKey(void)
  16505. {
  16506. DEBUG_INFO("processUnkownKey...\n");
  16507. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16508. for(int index=0; index < UnknownKeynum; index++)
  16509. {
  16510. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16511. {
  16512. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16513. }
  16514. }
  16515. }
  16516. int setKeyValue(char *key, char *value)
  16517. {
  16518. int isSuccess = NotSupported;
  16519. int check_ascii=0;
  16520. char str[501]={0};
  16521. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16522. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16523. {
  16524. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16526. {
  16527. strcpy(str, (const char*)value);
  16528. for(int i = 0; str[i]; i++){
  16529. str[i] = tolower(str[i]);
  16530. }
  16531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16532. isSuccess = ConfigurationStatus_Accepted;
  16533. }
  16534. else
  16535. {
  16536. isSuccess = ConfigurationStatus_Rejected;
  16537. }
  16538. }
  16539. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16540. {
  16541. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16543. {
  16544. strcpy(str, (const char*)value);
  16545. for(int i = 0; str[i]; i++){
  16546. str[i] = tolower(str[i]);
  16547. }
  16548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16549. isSuccess = ConfigurationStatus_Accepted;
  16550. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16551. }
  16552. else
  16553. {
  16554. isSuccess = ConfigurationStatus_Rejected;
  16555. }
  16556. }
  16557. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16558. {
  16559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16560. {
  16561. strcpy(str, (const char*)value);
  16562. for(int i = 0; str[i]; i++)
  16563. {
  16564. str[i] = tolower(str[i]);
  16565. }
  16566. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16568. isSuccess = ConfigurationStatus_Accepted;
  16569. }
  16570. else
  16571. {
  16572. isSuccess = ConfigurationStatus_Rejected;
  16573. }
  16574. }
  16575. if(strcmp(key, "BlinkRepeat") == 0)
  16576. {
  16577. //Charger.BlinkRepeat = Integer.parseInt(value);
  16578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16579. {
  16580. check_ascii = value[0];
  16581. if( (check_ascii < 48) || (check_ascii > 57) )
  16582. {
  16583. isSuccess = ConfigurationStatus_Rejected;
  16584. }
  16585. else
  16586. {
  16587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16588. isSuccess = ConfigurationStatus_Accepted;
  16589. }
  16590. }
  16591. else
  16592. {
  16593. isSuccess = ConfigurationStatus_Rejected;
  16594. }
  16595. }
  16596. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16597. {
  16598. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16599. {
  16600. check_ascii = value[0];
  16601. if( (check_ascii < 48) || (check_ascii > 57) )
  16602. {
  16603. isSuccess = ConfigurationStatus_Rejected;
  16604. }
  16605. else
  16606. {
  16607. if((atoi(value) == 0) || (atoi(value) >= 5))
  16608. {
  16609. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16611. isSuccess = ConfigurationStatus_Accepted;
  16612. }
  16613. else
  16614. isSuccess = ConfigurationStatus_Rejected;
  16615. }
  16616. }
  16617. else
  16618. {
  16619. isSuccess = ConfigurationStatus_Rejected;
  16620. }
  16621. }
  16622. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16623. {
  16624. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16625. {
  16626. check_ascii = value[0];
  16627. if( (check_ascii < 48) || (check_ascii > 57) )
  16628. {
  16629. isSuccess = ConfigurationStatus_Rejected;
  16630. }
  16631. else
  16632. {
  16633. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16635. isSuccess = ConfigurationStatus_Accepted;
  16636. }
  16637. }
  16638. else
  16639. {
  16640. isSuccess = ConfigurationStatus_Rejected;
  16641. }
  16642. }
  16643. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16644. {
  16645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16646. {
  16647. check_ascii = value[0];
  16648. if( (check_ascii < 48) || (check_ascii > 57) )
  16649. {
  16650. isSuccess = ConfigurationStatus_Rejected;
  16651. }
  16652. else
  16653. {
  16654. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16656. isSuccess = ConfigurationStatus_Accepted;
  16657. }
  16658. }
  16659. else
  16660. {
  16661. isSuccess = ConfigurationStatus_Rejected;
  16662. }
  16663. }
  16664. if(strcmp(key, "HeartbeatInterval") == 0)
  16665. {
  16666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16667. {
  16668. check_ascii = value[0];
  16669. if( (check_ascii < 48) || (check_ascii > 57) )
  16670. {
  16671. isSuccess = ConfigurationStatus_Rejected;
  16672. }
  16673. else
  16674. {
  16675. if((atoi(value) == 0) || (atoi(value) >= 10))
  16676. {
  16677. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16679. HeartBeatWaitTime = atoi(value);
  16680. isSuccess = ConfigurationStatus_Accepted;
  16681. }
  16682. else
  16683. {
  16684. isSuccess = ConfigurationStatus_Rejected;
  16685. }
  16686. }
  16687. }
  16688. else
  16689. {
  16690. isSuccess = ConfigurationStatus_Rejected;
  16691. }
  16692. }
  16693. if(strcmp(key, "LightIntensity") == 0)
  16694. {
  16695. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16696. {
  16697. check_ascii = value[0];
  16698. if( (check_ascii < 48) || (check_ascii > 57) )
  16699. {
  16700. isSuccess = ConfigurationStatus_Rejected;
  16701. }
  16702. else
  16703. {
  16704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16705. isSuccess = ConfigurationStatus_Accepted;
  16706. }
  16707. }
  16708. else
  16709. {
  16710. isSuccess = ConfigurationStatus_Rejected;
  16711. }
  16712. }
  16713. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16714. {
  16715. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16716. {
  16717. strcpy(str, (const char*)value);
  16718. for(int i = 0; str[i]; i++)
  16719. {
  16720. str[i] = tolower(str[i]);
  16721. }
  16722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16723. isSuccess = ConfigurationStatus_Accepted;
  16724. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16725. }
  16726. else
  16727. {
  16728. isSuccess = ConfigurationStatus_Rejected;
  16729. }
  16730. }
  16731. if(strcmp(key, "LocalPreAuthorize") == 0)
  16732. {
  16733. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16734. {
  16735. strcpy(str, (const char*)value);
  16736. for(int i = 0; str[i]; i++)
  16737. {
  16738. str[i] = tolower(str[i]);
  16739. }
  16740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16741. isSuccess = ConfigurationStatus_Accepted;
  16742. }
  16743. else
  16744. {
  16745. isSuccess = ConfigurationStatus_Rejected;
  16746. }
  16747. }
  16748. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16749. {
  16750. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16751. {
  16752. check_ascii = value[0];
  16753. if( (check_ascii < 48) || (check_ascii > 57) )
  16754. {
  16755. isSuccess = ConfigurationStatus_Rejected;
  16756. }
  16757. else
  16758. {
  16759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16760. isSuccess = ConfigurationStatus_Accepted;
  16761. }
  16762. }
  16763. else
  16764. {
  16765. isSuccess = ConfigurationStatus_Rejected;
  16766. }
  16767. }
  16768. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16769. {
  16770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16771. {
  16772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16773. isSuccess = ConfigurationStatus_Accepted;
  16774. }
  16775. else
  16776. {
  16777. isSuccess = ConfigurationStatus_Rejected;
  16778. }
  16779. }
  16780. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16781. {
  16782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16783. {
  16784. check_ascii = value[0];
  16785. if( (check_ascii < 48) || (check_ascii > 57) )
  16786. {
  16787. isSuccess = ConfigurationStatus_Rejected;
  16788. }
  16789. else
  16790. {
  16791. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16792. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16793. isSuccess = ConfigurationStatus_Accepted;
  16794. }
  16795. }
  16796. else
  16797. {
  16798. isSuccess = ConfigurationStatus_Rejected;
  16799. }
  16800. }
  16801. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16802. {
  16803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16804. {
  16805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16806. isSuccess = ConfigurationStatus_Accepted;
  16807. }
  16808. else
  16809. {
  16810. isSuccess = ConfigurationStatus_Rejected;
  16811. }
  16812. }
  16813. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16814. {
  16815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16816. {
  16817. check_ascii = value[0];
  16818. if( (check_ascii < 48) || (check_ascii > 57) )
  16819. {
  16820. isSuccess = ConfigurationStatus_Rejected;
  16821. }
  16822. else
  16823. {
  16824. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16826. isSuccess = ConfigurationStatus_Accepted;
  16827. }
  16828. }
  16829. else
  16830. {
  16831. isSuccess = ConfigurationStatus_Rejected;
  16832. }
  16833. }
  16834. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16835. {
  16836. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16837. {
  16838. check_ascii = value[0];
  16839. if( (check_ascii < 48) || (check_ascii > 57) )
  16840. {
  16841. isSuccess = ConfigurationStatus_Rejected;
  16842. }
  16843. else
  16844. {
  16845. if((atoi(value) == 0) || (atoi(value) >= 3))
  16846. {
  16847. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16849. isSuccess = ConfigurationStatus_Accepted;
  16850. }
  16851. else
  16852. {
  16853. isSuccess = ConfigurationStatus_Rejected;
  16854. }
  16855. }
  16856. }
  16857. else
  16858. {
  16859. isSuccess = ConfigurationStatus_Rejected;
  16860. }
  16861. }
  16862. if(strcmp(key, "MinimumStatusDuration") == 0)
  16863. {
  16864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16865. {
  16866. check_ascii = value[0];
  16867. if( (check_ascii < 48) || (check_ascii > 57) )
  16868. {
  16869. isSuccess = ConfigurationStatus_Rejected;
  16870. }
  16871. else
  16872. {
  16873. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16874. {
  16875. isSuccess = ConfigurationStatus_Rejected;
  16876. }
  16877. else
  16878. {
  16879. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16881. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16882. isSuccess = ConfigurationStatus_Accepted;
  16883. }
  16884. }
  16885. }
  16886. else
  16887. {
  16888. isSuccess = ConfigurationStatus_Rejected;
  16889. }
  16890. }
  16891. if(strcmp(key, "NumberOfConnectors") == 0)
  16892. {
  16893. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16894. {
  16895. check_ascii = value[0];
  16896. if( (check_ascii < 48) || (check_ascii > 57) )
  16897. {
  16898. isSuccess = ConfigurationStatus_Rejected;
  16899. }
  16900. else
  16901. {
  16902. //Charger.ResetRetries = Integer.parseInt(value);
  16903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16904. isSuccess = ConfigurationStatus_Accepted;
  16905. }
  16906. }
  16907. else
  16908. {
  16909. isSuccess = ConfigurationStatus_Rejected;
  16910. }
  16911. }
  16912. if(strcmp(key, "ResetRetries") == 0)
  16913. {
  16914. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16915. {
  16916. check_ascii = value[0];
  16917. if( (check_ascii < 48) || (check_ascii > 57) )
  16918. {
  16919. isSuccess = ConfigurationStatus_Rejected;
  16920. }
  16921. else
  16922. {
  16923. //Charger.ResetRetries = Integer.parseInt(value);
  16924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16925. isSuccess = ConfigurationStatus_Accepted;
  16926. }
  16927. }
  16928. else
  16929. {
  16930. isSuccess = ConfigurationStatus_Rejected;
  16931. }
  16932. }
  16933. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16934. {
  16935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16936. {
  16937. strcpy(str, (const char*)value);
  16938. for(int i = 0; str[i]; i++)
  16939. {
  16940. str[i] = tolower(str[i]);
  16941. }
  16942. if(strcmp(str, "notapplicable")== 0)
  16943. {
  16944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16945. isSuccess = ConfigurationStatus_Accepted;
  16946. }
  16947. else if(strcmp(str, "unknown")== 0)
  16948. {
  16949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16950. isSuccess = ConfigurationStatus_Accepted;
  16951. }
  16952. else if(strcmp(str, "rst")== 0)
  16953. {
  16954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16955. isSuccess = ConfigurationStatus_Accepted;
  16956. }
  16957. else if(strcmp(str, "rts")== 0)
  16958. {
  16959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16960. isSuccess = ConfigurationStatus_Accepted;
  16961. }
  16962. else if(strcmp(str, "srt")== 0)
  16963. {
  16964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16965. isSuccess = ConfigurationStatus_Accepted;
  16966. }
  16967. else if(strcmp(str, "str")== 0)
  16968. {
  16969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16970. isSuccess = ConfigurationStatus_Accepted;
  16971. }
  16972. else if(strcmp(str, "trs")== 0)
  16973. {
  16974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16975. isSuccess = ConfigurationStatus_Accepted;
  16976. }
  16977. else if(strcmp(str, "tsr")== 0)
  16978. {
  16979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16980. isSuccess = ConfigurationStatus_Accepted;
  16981. }
  16982. else
  16983. {
  16984. isSuccess = ConfigurationStatus_Rejected;
  16985. }
  16986. }
  16987. else
  16988. {
  16989. isSuccess = ConfigurationStatus_Rejected;
  16990. }
  16991. }
  16992. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16993. {
  16994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16995. {
  16996. check_ascii = value[0];
  16997. if( (check_ascii < 48) || (check_ascii > 57) )
  16998. {
  16999. isSuccess = ConfigurationStatus_Rejected;
  17000. }
  17001. else
  17002. {
  17003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  17004. isSuccess = ConfigurationStatus_Accepted;
  17005. }
  17006. }
  17007. else
  17008. {
  17009. isSuccess = ConfigurationStatus_Rejected;
  17010. }
  17011. }
  17012. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  17013. {
  17014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17015. {
  17016. strcpy(str, (const char*)value);
  17017. for(int i = 0; str[i]; i++)
  17018. {
  17019. str[i] = tolower(str[i]);
  17020. }
  17021. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17023. isSuccess = ConfigurationStatus_Accepted;
  17024. }
  17025. else
  17026. {
  17027. isSuccess = ConfigurationStatus_Rejected;
  17028. }
  17029. }
  17030. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  17031. {
  17032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17033. {
  17034. strcpy(str, (const char*)value);
  17035. for(int i = 0; str[i]; i++)
  17036. {
  17037. str[i] = tolower(str[i]);
  17038. }
  17039. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  17040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17041. isSuccess = ConfigurationStatus_Accepted;
  17042. }
  17043. else
  17044. {
  17045. isSuccess = ConfigurationStatus_Rejected;
  17046. }
  17047. }
  17048. if(strcmp(key, "StopTxnAlignedData") == 0)
  17049. {
  17050. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17051. {
  17052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  17053. isSuccess = ConfigurationStatus_Accepted;
  17054. }
  17055. else
  17056. {
  17057. isSuccess = ConfigurationStatus_Rejected;
  17058. }
  17059. }
  17060. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  17061. {
  17062. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17063. {
  17064. check_ascii = value[0];
  17065. if( (check_ascii < 48) || (check_ascii > 57) )
  17066. {
  17067. isSuccess = ConfigurationStatus_Rejected;
  17068. }
  17069. else
  17070. {
  17071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  17072. isSuccess = ConfigurationStatus_Accepted;
  17073. }
  17074. }
  17075. else
  17076. {
  17077. isSuccess = ConfigurationStatus_Rejected;
  17078. }
  17079. }
  17080. if(strcmp(key, "StopTxnSampledData") == 0)
  17081. {
  17082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17083. {
  17084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  17085. isSuccess = ConfigurationStatus_Accepted;
  17086. }
  17087. else
  17088. {
  17089. isSuccess = ConfigurationStatus_Rejected;
  17090. }
  17091. }
  17092. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  17093. {
  17094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17095. {
  17096. check_ascii = value[0];
  17097. if( (check_ascii < 48) || (check_ascii > 57) )
  17098. {
  17099. isSuccess = ConfigurationStatus_Rejected;
  17100. }
  17101. else
  17102. {
  17103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  17104. isSuccess = ConfigurationStatus_Accepted;
  17105. }
  17106. }
  17107. else
  17108. {
  17109. isSuccess = ConfigurationStatus_Rejected;
  17110. }
  17111. }
  17112. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  17113. {
  17114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17115. {
  17116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  17117. isSuccess = ConfigurationStatus_Accepted;
  17118. }
  17119. else
  17120. {
  17121. isSuccess = ConfigurationStatus_Rejected;
  17122. }
  17123. }
  17124. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  17125. {
  17126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17127. {
  17128. check_ascii = value[0];
  17129. if( (check_ascii < 48) || (check_ascii > 57) )
  17130. {
  17131. isSuccess = ConfigurationStatus_Rejected;
  17132. }
  17133. else
  17134. {
  17135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  17136. isSuccess = ConfigurationStatus_Accepted;
  17137. }
  17138. }
  17139. else
  17140. {
  17141. isSuccess = ConfigurationStatus_Rejected;
  17142. }
  17143. }
  17144. if(strcmp(key, "TransactionMessageAttempts") == 0)
  17145. {
  17146. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17147. {
  17148. check_ascii = value[0];
  17149. if( (check_ascii < 48) || (check_ascii > 57) )
  17150. {
  17151. isSuccess = ConfigurationStatus_Rejected;
  17152. }
  17153. else
  17154. {
  17155. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  17156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  17157. TransactionMessageAttemptsValue = atoi(value);
  17158. isSuccess = ConfigurationStatus_Accepted;
  17159. }
  17160. }
  17161. else
  17162. {
  17163. isSuccess = ConfigurationStatus_Rejected;
  17164. }
  17165. }
  17166. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  17167. {
  17168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17169. {
  17170. check_ascii = value[0];
  17171. if( (check_ascii < 48) || (check_ascii > 57) )
  17172. {
  17173. isSuccess = ConfigurationStatus_Rejected;
  17174. }
  17175. else
  17176. {
  17177. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  17178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  17179. TransactionMessageRetryIntervalValue = atoi(value);
  17180. isSuccess = ConfigurationStatus_Accepted;
  17181. }
  17182. }
  17183. else
  17184. {
  17185. isSuccess = ConfigurationStatus_Rejected;
  17186. }
  17187. }
  17188. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  17189. {
  17190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17191. {
  17192. strcpy(str, (const char*)value);
  17193. for(int i = 0; str[i]; i++)
  17194. {
  17195. str[i] = tolower(str[i]);
  17196. }
  17197. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17199. isSuccess = ConfigurationStatus_Accepted;
  17200. }
  17201. else
  17202. {
  17203. isSuccess = ConfigurationStatus_Rejected;
  17204. }
  17205. }
  17206. if(strcmp(key, "WebSocketPingInterval") == 0)
  17207. {
  17208. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17209. {
  17210. check_ascii = value[0];
  17211. if( (check_ascii < 48) || (check_ascii > 57) )
  17212. {
  17213. isSuccess = ConfigurationStatus_Rejected;
  17214. }
  17215. else
  17216. {
  17217. if((atoi(value) == 0) || (atoi(value) >= 10))
  17218. {
  17219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  17220. isSuccess = ConfigurationStatus_Accepted;
  17221. }
  17222. else
  17223. isSuccess = ConfigurationStatus_Rejected;
  17224. }
  17225. }
  17226. else
  17227. {
  17228. isSuccess = ConfigurationStatus_Rejected;
  17229. }
  17230. }
  17231. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  17232. {
  17233. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17234. {
  17235. strcpy(str, (const char*)value);
  17236. for(int i = 0; str[i]; i++)
  17237. {
  17238. str[i] = tolower(str[i]);
  17239. }
  17240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17241. isSuccess = ConfigurationStatus_Accepted;
  17242. }
  17243. else
  17244. {
  17245. isSuccess = ConfigurationStatus_Rejected;
  17246. }
  17247. }
  17248. if(strcmp(key, "AuthorizationKey") == 0)
  17249. {
  17250. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  17251. {
  17252. strcpy(str, (const char*)value);
  17253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  17254. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17255. isSuccess = ConfigurationStatus_Accepted;
  17256. }
  17257. else
  17258. {
  17259. isSuccess = ConfigurationStatus_Rejected;
  17260. }
  17261. }
  17262. if(strcmp(key, "SecurityProfile") == 0)
  17263. {
  17264. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17265. {
  17266. check_ascii = value[0];
  17267. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  17268. {
  17269. isSuccess = ConfigurationStatus_Rejected;
  17270. }
  17271. else if(check_ascii == 0x33)
  17272. {
  17273. isSuccess = NotSupported;
  17274. }
  17275. else
  17276. {
  17277. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  17278. {
  17279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  17280. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  17281. isSuccess = ConfigurationStatus_Accepted;
  17282. }
  17283. else
  17284. isSuccess = ConfigurationStatus_Rejected;
  17285. }
  17286. }
  17287. else
  17288. {
  17289. isSuccess = ConfigurationStatus_Rejected;
  17290. }
  17291. }
  17292. if(strcmp(key, "DefaultPrice") == 0)
  17293. {
  17294. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  17295. {
  17296. strcpy(str, (const char*)value);
  17297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  17298. isSuccess = ConfigurationStatus_Accepted;
  17299. }
  17300. else
  17301. {
  17302. isSuccess = ConfigurationStatus_Rejected;
  17303. }
  17304. }
  17305. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  17306. {
  17307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17308. {
  17309. strcpy(str, (const char*)value);
  17310. for(int i = 0; str[i]; i++)
  17311. {
  17312. str[i] = tolower(str[i]);
  17313. }
  17314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17315. isSuccess = ConfigurationStatus_Accepted;
  17316. }
  17317. else
  17318. {
  17319. isSuccess = ConfigurationStatus_Rejected;
  17320. }
  17321. }
  17322. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17323. {
  17324. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17325. {
  17326. strcpy(str, (const char*)value);
  17327. for(int i = 0; str[i]; i++)
  17328. {
  17329. str[i] = tolower(str[i]);
  17330. }
  17331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17332. isSuccess = ConfigurationStatus_Accepted;
  17333. }
  17334. else
  17335. {
  17336. isSuccess = ConfigurationStatus_Rejected;
  17337. }
  17338. }
  17339. if(strcmp(key, "TimeOffset") == 0)
  17340. {
  17341. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17342. {
  17343. strcpy(str, (const char*)value);
  17344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  17345. isSuccess = ConfigurationStatus_Accepted;
  17346. }
  17347. else
  17348. {
  17349. isSuccess = ConfigurationStatus_Rejected;
  17350. }
  17351. }
  17352. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  17353. {
  17354. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17355. {
  17356. strcpy(str, (const char*)value);
  17357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17358. isSuccess = ConfigurationStatus_Accepted;
  17359. }
  17360. else
  17361. {
  17362. isSuccess = ConfigurationStatus_Rejected;
  17363. }
  17364. }
  17365. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17366. {
  17367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17368. {
  17369. strcpy(str, (const char*)value);
  17370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17371. isSuccess = ConfigurationStatus_Accepted;
  17372. }
  17373. else
  17374. {
  17375. isSuccess = ConfigurationStatus_Rejected;
  17376. }
  17377. }
  17378. if(strcmp(key, "SystemUptimeSec") == 0)
  17379. {
  17380. isSuccess = NotSupported;
  17381. }
  17382. if(strcmp(key, "FreeVend") == 0)
  17383. {
  17384. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17385. {
  17386. strcpy(str, (const char*)value);
  17387. for(int i = 0; str[i]; i++)
  17388. {
  17389. str[i] = tolower(str[i]);
  17390. }
  17391. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17393. isSuccess = ConfigurationStatus_Accepted;
  17394. }
  17395. else
  17396. {
  17397. isSuccess = ConfigurationStatus_Rejected;
  17398. }
  17399. }
  17400. if(strcmp(key, "FreeVendIdtag") == 0)
  17401. {
  17402. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17403. {
  17404. strcpy(str, (const char*)value);
  17405. if(strlen(str) <= 20)
  17406. {
  17407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17408. isSuccess = ConfigurationStatus_Accepted;
  17409. }
  17410. else
  17411. {
  17412. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17413. isSuccess = ConfigurationStatus_Rejected;
  17414. }
  17415. }
  17416. else
  17417. {
  17418. isSuccess = ConfigurationStatus_Rejected;
  17419. }
  17420. }
  17421. if(strcmp(key, "OcppServer") == 0)
  17422. {
  17423. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17424. {
  17425. strcpy(str, (const char*)value);
  17426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17427. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17428. isSuccess = ConfigurationStatus_Accepted;
  17429. }
  17430. else
  17431. {
  17432. isSuccess = ConfigurationStatus_Rejected;
  17433. }
  17434. }
  17435. if(strcmp(key, "MaintainServer") == 0)
  17436. {
  17437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17438. {
  17439. strcpy(str, (const char*)value);
  17440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17441. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17442. isSuccess = ConfigurationStatus_Accepted;
  17443. }
  17444. else
  17445. {
  17446. isSuccess = ConfigurationStatus_Rejected;
  17447. }
  17448. }
  17449. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17450. {
  17451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17452. {
  17453. strcpy(str, (const char*)value);
  17454. for(int i = 0; str[i]; i++)
  17455. {
  17456. str[i] = tolower(str[i]);
  17457. }
  17458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17459. isSuccess = ConfigurationStatus_Accepted;
  17460. }
  17461. else
  17462. {
  17463. isSuccess = ConfigurationStatus_Rejected;
  17464. }
  17465. }
  17466. if(strcmp(key, "StatusNotificationInterval") == 0)
  17467. {
  17468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17469. {
  17470. check_ascii = value[0];
  17471. if( (check_ascii < 48) || (check_ascii > 57) )
  17472. {
  17473. isSuccess = ConfigurationStatus_Rejected;
  17474. }
  17475. else
  17476. {
  17477. if((atoi(value) == 0) || (atoi(value) >= 10))
  17478. {
  17479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17480. isSuccess = ConfigurationStatus_Accepted;
  17481. }
  17482. else
  17483. isSuccess = ConfigurationStatus_Rejected;
  17484. }
  17485. }
  17486. else
  17487. {
  17488. isSuccess = ConfigurationStatus_Rejected;
  17489. }
  17490. }
  17491. if(strcmp(key, "PreAuthAmount") == 0)
  17492. {
  17493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17494. {
  17495. check_ascii = value[0];
  17496. if( (check_ascii < 48) || (check_ascii > 57) )
  17497. {
  17498. isSuccess = ConfigurationStatus_Rejected;
  17499. }
  17500. else
  17501. {
  17502. if(atof(value) >= 0)
  17503. {
  17504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17505. isSuccess = ConfigurationStatus_Accepted;
  17506. }
  17507. else
  17508. isSuccess = ConfigurationStatus_Rejected;
  17509. }
  17510. }
  17511. else
  17512. {
  17513. isSuccess = ConfigurationStatus_Rejected;
  17514. }
  17515. }
  17516. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17517. {
  17518. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17519. {
  17520. check_ascii = value[0];
  17521. if( (check_ascii < 48) || (check_ascii > 57) )
  17522. {
  17523. isSuccess = ConfigurationStatus_Rejected;
  17524. }
  17525. else
  17526. {
  17527. if(atoi(value) >= 0)
  17528. {
  17529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  17530. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17531. isSuccess = ConfigurationStatus_Accepted;
  17532. }
  17533. else
  17534. isSuccess = ConfigurationStatus_Rejected;
  17535. }
  17536. }
  17537. else
  17538. {
  17539. isSuccess = ConfigurationStatus_Rejected;
  17540. }
  17541. }
  17542. if(strcmp(key, "PowerSharingServerIP") == 0)
  17543. {
  17544. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17545. {
  17546. strcpy(str, (const char*)value);
  17547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17548. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17549. isSuccess = ConfigurationStatus_Accepted;
  17550. }
  17551. else
  17552. {
  17553. isSuccess = ConfigurationStatus_Rejected;
  17554. }
  17555. }
  17556. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17557. {
  17558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17559. {
  17560. strcpy(str, (const char*)value);
  17561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17562. isSuccess = ConfigurationStatus_Accepted;
  17563. }
  17564. else
  17565. {
  17566. isSuccess = ConfigurationStatus_Rejected;
  17567. }
  17568. }
  17569. #if 0
  17570. //For OCPP Test Case
  17571. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17572. {
  17573. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17574. {
  17575. strcpy(str, (const char*)value);
  17576. for(int i = 0; str[i]; i++)
  17577. {
  17578. str[i] = tolower(str[i]);
  17579. }
  17580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17581. isSuccess = ConfigurationStatus_Accepted;
  17582. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17583. }
  17584. else
  17585. {
  17586. isSuccess = ConfigurationStatus_Rejected;
  17587. }
  17588. }
  17589. #endif
  17590. #if 1
  17591. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17592. {
  17593. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17594. {
  17595. strcpy(str, (const char*)value);
  17596. for(int i = 0; str[i]; i++)
  17597. {
  17598. str[i] = tolower(str[i]);
  17599. }
  17600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17601. isSuccess = ConfigurationStatus_Accepted;
  17602. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17603. }
  17604. else
  17605. {
  17606. isSuccess = ConfigurationStatus_Rejected;
  17607. }
  17608. }
  17609. #endif
  17610. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17611. {
  17612. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17613. {
  17614. check_ascii = value[0];
  17615. if( (check_ascii < 48) || (check_ascii > 57) )
  17616. {
  17617. isSuccess = ConfigurationStatus_Rejected;
  17618. }
  17619. else
  17620. {
  17621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17622. isSuccess = ConfigurationStatus_Accepted;
  17623. }
  17624. }
  17625. else
  17626. {
  17627. isSuccess = ConfigurationStatus_Rejected;
  17628. }
  17629. }
  17630. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17631. {
  17632. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17633. {
  17634. check_ascii = value[0];
  17635. if( (check_ascii < 48) || (check_ascii > 57) )
  17636. {
  17637. isSuccess = ConfigurationStatus_Rejected;
  17638. }
  17639. else
  17640. {
  17641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17642. isSuccess = ConfigurationStatus_Accepted;
  17643. }
  17644. }
  17645. else
  17646. {
  17647. isSuccess = ConfigurationStatus_Rejected;
  17648. }
  17649. }
  17650. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17651. {
  17652. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17653. {
  17654. strcpy(str, (const char*)value);
  17655. for(int i = 0; str[i]; i++)
  17656. {
  17657. str[i] = tolower(str[i]);
  17658. }
  17659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17660. isSuccess = ConfigurationStatus_Accepted;
  17661. }
  17662. else
  17663. {
  17664. isSuccess = ConfigurationStatus_Rejected;
  17665. }
  17666. }
  17667. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17668. {
  17669. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17670. {
  17671. check_ascii = value[0];
  17672. if( (check_ascii < 48) || (check_ascii > 57) )
  17673. {
  17674. isSuccess = ConfigurationStatus_Rejected;
  17675. }
  17676. else
  17677. {
  17678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17679. isSuccess = ConfigurationStatus_Accepted;
  17680. }
  17681. }
  17682. else
  17683. {
  17684. isSuccess = ConfigurationStatus_Rejected;
  17685. }
  17686. }
  17687. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17688. {
  17689. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17690. {
  17691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17692. isSuccess = ConfigurationStatus_Accepted;
  17693. }
  17694. else
  17695. {
  17696. isSuccess = ConfigurationStatus_Rejected;
  17697. }
  17698. }
  17699. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17700. {
  17701. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17702. {
  17703. check_ascii = value[0];
  17704. if( (check_ascii < 48) || (check_ascii > 57) )
  17705. {
  17706. isSuccess = ConfigurationStatus_Rejected;
  17707. }
  17708. else
  17709. {
  17710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17711. isSuccess = ConfigurationStatus_Accepted;
  17712. }
  17713. }
  17714. else
  17715. {
  17716. isSuccess = ConfigurationStatus_Rejected;
  17717. }
  17718. }
  17719. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17720. {
  17721. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17722. {
  17723. strcpy(str, (const char*)value);
  17724. for(int i = 0; str[i]; i++)
  17725. {
  17726. str[i] = tolower(str[i]);
  17727. }
  17728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17729. isSuccess = ConfigurationStatus_Accepted;
  17730. }
  17731. else
  17732. {
  17733. isSuccess = ConfigurationStatus_Rejected;
  17734. }
  17735. }
  17736. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17737. {
  17738. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17739. {
  17740. check_ascii = value[0];
  17741. if( (check_ascii < 48) || (check_ascii > 57) )
  17742. {
  17743. isSuccess = ConfigurationStatus_Rejected;
  17744. }
  17745. else
  17746. {
  17747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17748. isSuccess = ConfigurationStatus_Accepted;
  17749. }
  17750. }
  17751. else
  17752. {
  17753. isSuccess = ConfigurationStatus_Rejected;
  17754. }
  17755. }
  17756. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17757. return isSuccess;
  17758. }
  17759. int TransactionMessageAttemptsGet(void)
  17760. {
  17761. return TransactionMessageAttemptsValue;
  17762. }
  17763. int FirstHeartBeatResponse(void)
  17764. {
  17765. return FirstHeartBeat;
  17766. }
  17767. int TransactionMessageRetryIntervalGet(void)
  17768. {
  17769. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17770. }
  17771. int ReadHttpStatus(int sock)
  17772. {
  17773. //char c;
  17774. char buff[1024]="",*ptr=buff+1;
  17775. int bytes_received, status;
  17776. DEBUG_INFO("Begin Response ..\n");
  17777. while((bytes_received = recv(sock, ptr, 1, 0))){
  17778. if(bytes_received==-1){
  17779. perror("ReadHttpStatus");
  17780. exit(1);
  17781. }
  17782. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17783. ptr++;
  17784. }
  17785. *ptr=0;
  17786. ptr=buff+1;
  17787. sscanf(ptr,"%*s %d ", &status);
  17788. DEBUG_INFO("%s\n",ptr);
  17789. DEBUG_INFO("status=%d\n",status);
  17790. DEBUG_INFO("End Response ..\n");
  17791. return (bytes_received>0)?status:0;
  17792. }
  17793. //the only filed that it parsed is 'Content-Length'
  17794. int ParseHeader(int sock)
  17795. {
  17796. //char c;
  17797. char buff[1024]="",*ptr=buff+4;
  17798. int bytes_received;
  17799. DEBUG_INFO("Begin HEADER ..\n");
  17800. while((bytes_received = recv(sock, ptr, 1, 0))){
  17801. if(bytes_received==-1){
  17802. perror("Parse Header");
  17803. exit(1);
  17804. }
  17805. if(
  17806. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17807. (ptr[-1]=='\r') && (*ptr=='\n' )
  17808. ) break;
  17809. ptr++;
  17810. }
  17811. *ptr=0;
  17812. ptr=buff+4;
  17813. //printf("%s",ptr);
  17814. if(bytes_received){
  17815. ptr=strstr(ptr,"Content-Length:");
  17816. if(ptr){
  17817. sscanf(ptr,"%*s %d",&bytes_received);
  17818. }else
  17819. bytes_received=-1; //unknown size
  17820. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17821. }
  17822. DEBUG_INFO("End HEADER ..\n");
  17823. return bytes_received ;
  17824. }
  17825. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17826. {
  17827. int result = TRUE;
  17828. char rmFileCmd[100]={0};
  17829. char FilePath[100]={0};
  17830. char ftpbuf[200];
  17831. int systemresult;
  17832. sprintf(FilePath,"/mnt/%s",filename);
  17833. system("ping 8.8.8.8 &");
  17834. if((access(FilePath,F_OK))!=-1)
  17835. {
  17836. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17837. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17838. system(rmFileCmd);
  17839. }
  17840. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17841. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17842. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17843. systemresult = system(ftpbuf);
  17844. if(systemresult != 0)
  17845. {
  17846. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17847. result = FALSE;
  17848. }
  17849. system("pkill ping");
  17850. return result;
  17851. }
  17852. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  17853. {
  17854. int result = TRUE;
  17855. char rmFileCmd[100]={0};
  17856. char FilePath[100]={0};
  17857. char ftpbuf[200];
  17858. int systemresult;
  17859. sprintf(FilePath,"/mnt/%s",filename);
  17860. system("ping 8.8.8.8 &");
  17861. if((access(FilePath,F_OK))!=-1)
  17862. {
  17863. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17864. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17865. system(rmFileCmd);
  17866. }
  17867. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17868. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  17869. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17870. systemresult = system(ftpbuf);
  17871. if(systemresult != 0)
  17872. {
  17873. DEBUG_WARN("scp error!\n");
  17874. result = FALSE;
  17875. }
  17876. system("pkill ping");
  17877. return result;
  17878. }
  17879. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17880. {
  17881. int result = TRUE;
  17882. char rmFileCmd[100]={0};
  17883. char FilePath[100]={0};
  17884. char ftpbuf[200];
  17885. int systemresult;
  17886. sprintf(FilePath,"/mnt/%s",filename);
  17887. system("ping 8.8.8.8 &");
  17888. if((access(FilePath,F_OK))!=-1)
  17889. {
  17890. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17891. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17892. system(rmFileCmd);
  17893. }
  17894. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17895. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17896. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17897. systemresult = system(ftpbuf);
  17898. if(systemresult != 0)
  17899. {
  17900. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17901. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17902. systemresult = system(ftpbuf);
  17903. if(systemresult != 0)
  17904. {
  17905. DEBUG_WARN("FTP download fail!\n");
  17906. result = FALSE;
  17907. }
  17908. }
  17909. system("pkill ping");
  17910. return result;
  17911. }
  17912. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17913. {
  17914. char rmFileCmd[100]={0};
  17915. char FilePath[100]={0};
  17916. char buf[512];
  17917. int systemresult = 0;
  17918. //DEBUG_INFO("filename=%s\n",filename);
  17919. //DEBUG_INFO("url=%s\n",url);
  17920. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17921. if((access(FilePath,F_OK))!=-1)
  17922. {
  17923. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17924. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17925. system(rmFileCmd);
  17926. }
  17927. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17928. if(fp == NULL)
  17929. {
  17930. DEBUG_INFO("log is NULL\n");
  17931. return FALSE;
  17932. }
  17933. else
  17934. {
  17935. fprintf(fp, "%s\n", url);
  17936. fprintf(fp, "%s\n", filename);
  17937. fclose(fp);
  17938. }
  17939. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17940. if(phpFP == NULL)
  17941. {
  17942. DEBUG_INFO("PHP upload fail.\n");
  17943. return FALSE;
  17944. }
  17945. else
  17946. {
  17947. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17948. {
  17949. if(strstr(buf, "result") != NULL)
  17950. {
  17951. sscanf(buf, "result: %d", &systemresult);
  17952. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17953. }
  17954. }
  17955. pclose(phpFP);
  17956. }
  17957. if(systemresult != 1)
  17958. {
  17959. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17960. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17961. if(phpFP == NULL)
  17962. {
  17963. DEBUG_WARN("PHP PUT upload fail.\n");
  17964. return FALSE;
  17965. }
  17966. else
  17967. {
  17968. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17969. {
  17970. if(strstr(buf, "result") != NULL)
  17971. {
  17972. sscanf(buf, "result: %d", &systemresult);
  17973. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17974. }
  17975. }
  17976. pclose(phpFP);
  17977. }
  17978. }
  17979. if(systemresult != 1)
  17980. {
  17981. DEBUG_WARN("PHP PUT upload fail.\n");
  17982. return FALSE;
  17983. }
  17984. return TRUE;
  17985. }
  17986. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17987. {
  17988. int result = FALSE;
  17989. char ftpbuf[200];
  17990. int systemresult;
  17991. /*
  17992. // Domaind name transfer to IP address
  17993. struct hostent* server;
  17994. char *IPbuffer;
  17995. server = gethostbyname(location);
  17996. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17997. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17998. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17999. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18000. systemresult = system(ftpbuf);
  18001. if(systemresult != 0)
  18002. {
  18003. DEBUG_INFO("ftpput error!\n");
  18004. }
  18005. else
  18006. {
  18007. result = TRUE;
  18008. DEBUG_INFO("ftpput OK!\n");
  18009. }
  18010. return result;
  18011. }
  18012. int GetOcppServerURL()
  18013. {
  18014. int result = FALSE;
  18015. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18016. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18017. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  18018. struct yuarel url;
  18019. char urlStr[512];
  18020. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  18021. {
  18022. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  18023. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18024. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18025. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  18026. if(yuarel_parse(&url, urlStr) != -1)
  18027. {
  18028. sprintf(OcppProtocol, "%s", url.scheme);
  18029. sprintf(OcppHost, "%s", url.host);
  18030. if(url.path == NULL)
  18031. OcppTempPath[0] = '\0';
  18032. else
  18033. {
  18034. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  18035. {
  18036. sprintf(OcppTempPath, "%s/", url.path);
  18037. }
  18038. else
  18039. {
  18040. sprintf(OcppTempPath, "%s", url.path);
  18041. }
  18042. }
  18043. if(url.port == 0)
  18044. {
  18045. if(strcmp(OcppProtocol, "wss") == 0)
  18046. OcppPort = 443;
  18047. else
  18048. OcppPort = 80;
  18049. }
  18050. else
  18051. OcppPort = url.port;
  18052. result = TRUE;
  18053. }
  18054. }
  18055. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  18056. {
  18057. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  18058. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18059. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18060. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  18061. if(yuarel_parse(&url, urlStr) != -1)
  18062. {
  18063. sprintf(OcppProtocol, "%s", url.scheme);
  18064. sprintf(OcppHost, "%s", url.host);
  18065. if(url.path == NULL)
  18066. OcppTempPath[0] = '\0';
  18067. else
  18068. sprintf(OcppTempPath, "%s", url.path);
  18069. if(url.port == 0)
  18070. {
  18071. if(strcmp(OcppProtocol, "wss") == 0)
  18072. OcppPort = 443;
  18073. else
  18074. OcppPort = 80;
  18075. }
  18076. else
  18077. OcppPort = url.port;
  18078. result = TRUE;
  18079. }
  18080. }
  18081. else
  18082. {
  18083. strcpy(OcppHost,"");
  18084. }
  18085. return result;
  18086. }
  18087. int GetOcppPath()
  18088. {
  18089. int result = FALSE;
  18090. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18091. {
  18092. if(OcppTempPath == NULL)
  18093. {
  18094. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18095. }
  18096. else
  18097. {
  18098. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18099. }
  18100. result = TRUE;
  18101. goto End;
  18102. }
  18103. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  18104. {
  18105. if(OcppTempPath == NULL)
  18106. {
  18107. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  18108. }
  18109. else
  18110. {
  18111. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  18112. }
  18113. result = TRUE;
  18114. goto End;
  18115. }
  18116. else
  18117. {
  18118. strcpy(OcppPath,"");
  18119. }
  18120. End:
  18121. return result;
  18122. }
  18123. int GetOcppPort()
  18124. {
  18125. return OcppPort;
  18126. }
  18127. int GetOcppConnStatus(void)
  18128. {
  18129. return ShmOCPP16Data->OcppConnStatus;
  18130. }
  18131. void SetOcppConnStatus(uint8_t status)
  18132. {
  18133. ShmOCPP16Data->OcppConnStatus = status;
  18134. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18135. }
  18136. int GetHeartBeatWithNOResponse(void)
  18137. {
  18138. return HeartBeatWithNOResponse;
  18139. }
  18140. void SetHeartBeatWithNOResponse(void)
  18141. {
  18142. HeartBeatWithNOResponse = 0;
  18143. }
  18144. void GetStartTransactionIdTag(int gun_index)
  18145. {
  18146. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  18147. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18148. }
  18149. int GetStartTransactionId(int gun_index)
  18150. {
  18151. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18152. }
  18153. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  18154. {
  18155. char ch;
  18156. FILE *fptr1;
  18157. int temptransactionId;
  18158. char str[100]={0};
  18159. temptransactionId = 0;
  18160. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  18161. {
  18162. DEBUG_INFO("IdTag is empty.\n");
  18163. return temptransactionId;
  18164. }
  18165. /*------ Read the file ----------------*/
  18166. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  18167. if (!fptr1)
  18168. {
  18169. DEBUG_INFO("QueueTransactionId file open error.\n");
  18170. //printf(" File not found or unable to open the input file!!\n");
  18171. return temptransactionId;
  18172. }
  18173. ch=fgetc(fptr1);
  18174. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  18175. rewind(fptr1);
  18176. if(ch!=EOF)
  18177. {
  18178. // printf("%c",ch);
  18179. while (fgets(str, 100, fptr1) != NULL)
  18180. {
  18181. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18182. if(str[0]=='\0')
  18183. {
  18184. break;
  18185. }
  18186. char *revbuf[8] = {0}; // Variable store string split
  18187. int num = 0;// Quantity after string split
  18188. DEBUG_INFO("Transaction queue data= %s\n", str);
  18189. splitstring(str,",",revbuf,&num); // String split
  18190. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  18191. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  18192. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  18193. DEBUG_INFO("------------------------------\n");
  18194. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  18195. {
  18196. if(isStopTransaction)
  18197. {
  18198. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  18199. {
  18200. temptransactionId = atoi(revbuf[2]);
  18201. //break;
  18202. }
  18203. }
  18204. else
  18205. {
  18206. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  18207. {
  18208. temptransactionId = atoi(revbuf[2]);
  18209. //break;
  18210. }
  18211. }
  18212. }
  18213. }
  18214. }
  18215. else
  18216. DEBUG_INFO("EOF\n");
  18217. fclose(fptr1);
  18218. /*------- End of reading ---------------*/
  18219. return temptransactionId;
  18220. }
  18221. void SetTransactionIdZero(int transactionId)
  18222. {
  18223. char ch;
  18224. FILE *fptr1, *fptr2;
  18225. int temptransactionId = 0;
  18226. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  18227. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  18228. if (!fptr1)
  18229. {
  18230. //printf(" File not found or unable to open the input file!!\n");
  18231. return ;
  18232. }
  18233. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  18234. if (!fptr2)
  18235. {
  18236. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  18237. fclose(fptr1);
  18238. return ;
  18239. }
  18240. ch=fgetc(fptr1);
  18241. rewind(fptr1);
  18242. if(ch!=EOF)
  18243. {
  18244. // copy all contents to the temporary file except the specific line
  18245. while (fgets(str, 100, fptr1) != NULL)
  18246. {
  18247. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18248. if(str[0]=='\0')
  18249. {
  18250. break;
  18251. }
  18252. char *revbuf[8] = {0};
  18253. int num = 0;
  18254. strcpy(strtemp, str);
  18255. splitstring(str,",",revbuf,&num);
  18256. if(revbuf[2][0] != '\0')
  18257. {
  18258. temptransactionId = atoi(revbuf[2]);
  18259. if(transactionId != temptransactionId)
  18260. {
  18261. fprintf(fptr2, "%s\n", strtemp);
  18262. }
  18263. }
  18264. }
  18265. }
  18266. fclose(fptr1);
  18267. fclose(fptr2);
  18268. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  18269. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  18270. /*------ Read the file ----------------*/
  18271. }
  18272. int InternetDisconnect(void)
  18273. {
  18274. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  18275. }
  18276. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18277. void storeTempStopTransaction(int gun_index)
  18278. {
  18279. char guid[37]={0};
  18280. int tempIndex = 0;
  18281. char TempStopTransaction[256];
  18282. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18283. DEBUG_INFO("storeTempStopTransaction...\n");
  18284. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  18285. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  18286. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  18287. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18288. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18289. {
  18290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18291. {
  18292. tempIndex = ((gun_index==2) ? 1: 0);
  18293. }
  18294. else
  18295. {
  18296. tempIndex = gun_index;
  18297. }
  18298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18299. {
  18300. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18301. {
  18302. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  18303. }
  18304. }// END OF CHAdeMO_QUANTITY
  18305. }
  18306. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18307. {
  18308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18309. {
  18310. tempIndex = ((gun_index==2) ? 1: 0);
  18311. }
  18312. else
  18313. {
  18314. tempIndex = gun_index;
  18315. }
  18316. for (int index = 0; index < CCS_QUANTITY; index++)
  18317. {
  18318. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18319. {
  18320. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  18321. }
  18322. }// END OF CCS_QUANTITY
  18323. }
  18324. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18325. {
  18326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18327. {
  18328. tempIndex = ((gun_index==2) ? 1: 0);
  18329. }
  18330. else
  18331. {
  18332. tempIndex = gun_index;
  18333. }
  18334. for (int index = 0; index < GB_QUANTITY; index++)
  18335. {
  18336. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18337. {
  18338. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18339. }
  18340. }// END OF GB_QUANTITY
  18341. }
  18342. else if(gunType[gun_index] == GUN_TYPE_DO)
  18343. {
  18344. tempIndex = gun_index;
  18345. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18346. {
  18347. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18348. {
  18349. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18350. }
  18351. }
  18352. }
  18353. else
  18354. {
  18355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18356. {
  18357. tempIndex = 2;
  18358. }
  18359. else
  18360. {
  18361. tempIndex = gun_index;
  18362. }
  18363. for (int index = 0; index < AC_QUANTITY; index++)
  18364. {
  18365. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18366. {
  18367. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18368. }
  18369. }// END OF AC_QUANTITY
  18370. }
  18371. //Stop Transaction Time
  18372. struct timeval tmnow;
  18373. struct tm *tm;
  18374. char buf[28];//, usec_buf[6];
  18375. gettimeofday(&tmnow, NULL);
  18376. time_t t;
  18377. t = time(NULL);
  18378. /*UTC time and date*/
  18379. tm = gmtime(&t);
  18380. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18381. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  18382. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18383. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18384. random_uuid(guid);
  18385. /***********************************transactionData******************************************************/
  18386. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18388. //=================================
  18389. //1. Transaction_Begin
  18390. //=================================
  18391. //============================== Energy.Active.Import.Interval ===========================================
  18392. //=================================
  18393. //2. Transaction_End
  18394. //=================================
  18395. //2.1====================================== Current.Import L1 ==============================================
  18396. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18397. {
  18398. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  18399. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18400. {
  18401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18402. {
  18403. tempIndex = ((gun_index==2) ? 1: 0);
  18404. }
  18405. else
  18406. {
  18407. tempIndex = gun_index;
  18408. }
  18409. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18410. {
  18411. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18412. {
  18413. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18414. }
  18415. }// End of for CHAdeMO_QUANTITY
  18416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18417. }
  18418. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18419. {
  18420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18421. {
  18422. tempIndex = ((gun_index==2) ? 1: 0);
  18423. }
  18424. else
  18425. {
  18426. tempIndex = gun_index;
  18427. }
  18428. for (int index = 0; index < CCS_QUANTITY; index++)
  18429. {
  18430. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18431. {
  18432. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18433. }
  18434. }// End of for CCS_QUANTITY
  18435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18436. }
  18437. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18438. {
  18439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18440. {
  18441. tempIndex = ((gun_index==2) ? 1: 0);
  18442. }
  18443. else
  18444. {
  18445. tempIndex = gun_index;
  18446. }
  18447. for (int index = 0; index < GB_QUANTITY; index++)
  18448. {
  18449. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18450. {
  18451. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18452. }
  18453. }// End of for GB_QUANTITY
  18454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18455. }
  18456. else if(gunType[gun_index] == GUN_TYPE_DO)
  18457. {
  18458. tempIndex = gun_index;
  18459. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18460. {
  18461. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18462. {
  18463. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18464. }
  18465. }
  18466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18467. }
  18468. else
  18469. {
  18470. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18471. {
  18472. tempIndex = 2;
  18473. }
  18474. else
  18475. {
  18476. tempIndex = gun_index;
  18477. }
  18478. for (int index = 0; index < AC_QUANTITY; index++)
  18479. {
  18480. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18481. {
  18482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18483. }
  18484. }// End of for AC_QUANTITY
  18485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18486. }
  18487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18490. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18493. }
  18494. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18495. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18496. {
  18497. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18498. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18499. {
  18500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18501. {
  18502. tempIndex = ((gun_index==2) ? 1: 0);
  18503. }
  18504. else
  18505. {
  18506. tempIndex = gun_index;
  18507. }
  18508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18509. {
  18510. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18511. {
  18512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18513. }
  18514. }// END OF CHAdeMO_QUANTITY
  18515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18516. }
  18517. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18518. {
  18519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18520. {
  18521. tempIndex = ((gun_index==2) ? 1: 0);
  18522. }
  18523. else
  18524. {
  18525. tempIndex = gun_index;
  18526. }
  18527. for (int index = 0; index < CCS_QUANTITY; index++)
  18528. {
  18529. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18530. {
  18531. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18532. }
  18533. }// END OF CCS_QUANTITY
  18534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18535. }
  18536. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18537. {
  18538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18539. {
  18540. tempIndex = ((gun_index==2) ? 1: 0);
  18541. }
  18542. else
  18543. {
  18544. tempIndex = gun_index;
  18545. }
  18546. for (int index = 0; index < GB_QUANTITY; index++)
  18547. {
  18548. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18549. {
  18550. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18551. }
  18552. }// END OF GB_QUANTITY
  18553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18554. }
  18555. else if(gunType[gun_index] == GUN_TYPE_DO)
  18556. {
  18557. tempIndex = gun_index;
  18558. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18559. {
  18560. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18561. {
  18562. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18563. }
  18564. }
  18565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18566. }
  18567. else
  18568. {
  18569. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18570. {
  18571. tempIndex = 2;
  18572. }
  18573. else
  18574. {
  18575. tempIndex = gun_index;
  18576. }
  18577. for (int index = 0; index < AC_QUANTITY; index++)
  18578. {
  18579. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18580. {
  18581. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18582. }
  18583. }// END OF AC_QUANTITY
  18584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18585. }
  18586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18589. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18592. }
  18593. //2.3====================================== Power.Active.Import =========================================
  18594. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18595. {
  18596. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18597. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18598. {
  18599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18600. {
  18601. tempIndex = ((gun_index==2) ? 1: 0);
  18602. }
  18603. else
  18604. {
  18605. tempIndex = gun_index;
  18606. }
  18607. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18608. {
  18609. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18610. {
  18611. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18612. }
  18613. } // End for CHAdeMO_QUANTITY
  18614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18615. }
  18616. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18617. {
  18618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18619. {
  18620. tempIndex = ((gun_index==2) ? 1: 0);
  18621. }
  18622. else
  18623. {
  18624. tempIndex = gun_index;
  18625. }
  18626. for (int index = 0; index < CCS_QUANTITY; index++)
  18627. {
  18628. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18629. {
  18630. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18631. }
  18632. } // END for CCS_QUANTITY
  18633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18634. }
  18635. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18636. {
  18637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18638. {
  18639. tempIndex = ((gun_index==2) ? 1: 0);
  18640. }
  18641. else
  18642. {
  18643. tempIndex = gun_index;
  18644. }
  18645. for (int index = 0; index < GB_QUANTITY; index++)
  18646. {
  18647. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18648. {
  18649. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18650. }
  18651. }// END for GB_QUANTITY
  18652. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18653. }
  18654. else if(gunType[gun_index] == GUN_TYPE_DO)
  18655. {
  18656. tempIndex = gun_index;
  18657. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18658. {
  18659. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18660. {
  18661. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18662. }
  18663. }
  18664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18665. }
  18666. else
  18667. {
  18668. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18669. {
  18670. tempIndex = 2;
  18671. }
  18672. else
  18673. {
  18674. tempIndex = gun_index;
  18675. }
  18676. for (int index = 0; index < AC_QUANTITY; index++)
  18677. {
  18678. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18679. {
  18680. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18681. }
  18682. } // END for AC_QUANTITY
  18683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18684. }
  18685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18688. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18691. }
  18692. //2.4====================================== Voltage L1 ====================================================
  18693. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18694. {
  18695. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18696. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18697. {
  18698. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18699. {
  18700. tempIndex = ((gun_index==2) ? 1: 0);
  18701. }
  18702. else
  18703. {
  18704. tempIndex = gun_index;
  18705. }
  18706. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18707. {
  18708. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18709. {
  18710. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18711. }
  18712. } // END OF FOR CHAdeMO_QUANTITY
  18713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18714. }
  18715. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18716. {
  18717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18718. {
  18719. tempIndex = ((gun_index==2) ? 1: 0);
  18720. }
  18721. else
  18722. {
  18723. tempIndex = gun_index;
  18724. }
  18725. for (int index = 0; index < CCS_QUANTITY; index++)
  18726. {
  18727. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18728. {
  18729. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18730. }
  18731. } // END OF FOR CCS_QUANTITY
  18732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18733. }
  18734. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18735. {
  18736. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18737. {
  18738. tempIndex = ((gun_index==2) ? 1: 0);
  18739. }
  18740. else
  18741. {
  18742. tempIndex = gun_index;
  18743. }
  18744. for (int index = 0; index < GB_QUANTITY; index++)
  18745. {
  18746. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18747. {
  18748. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18749. }
  18750. } // END OF FOR GB_QUANTITY
  18751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18752. }
  18753. else if(gunType[gun_index] == GUN_TYPE_DO)
  18754. {
  18755. tempIndex = gun_index;
  18756. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18757. {
  18758. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18759. {
  18760. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18761. }
  18762. }
  18763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18764. }
  18765. else
  18766. {
  18767. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18768. {
  18769. tempIndex = 2;
  18770. }
  18771. else
  18772. {
  18773. tempIndex = gun_index;
  18774. }
  18775. for (int index = 0; index < AC_QUANTITY; index++)
  18776. {
  18777. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18778. {
  18779. 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
  18780. }
  18781. } // END OF FOR AC_QUANTITY
  18782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18783. }
  18784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18787. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18788. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18790. }
  18791. //2.5============================================== End SoC =========================================================
  18792. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18793. {
  18794. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18795. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  18796. {
  18797. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18798. {
  18799. tempIndex = ((gun_index==2) ? 1: 0);
  18800. }
  18801. else
  18802. {
  18803. tempIndex = gun_index;
  18804. }
  18805. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18806. {
  18807. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18808. {
  18809. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18810. {
  18811. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18812. }
  18813. }
  18814. }
  18815. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18816. {
  18817. for (int index = 0; index < CCS_QUANTITY; index++)
  18818. {
  18819. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18820. {
  18821. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18822. }
  18823. }
  18824. }
  18825. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18826. {
  18827. for (int index = 0; index < GB_QUANTITY; index++)
  18828. {
  18829. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18830. {
  18831. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18832. }
  18833. }
  18834. }
  18835. else if(gunType[gun_index] == GUN_TYPE_DO)
  18836. {
  18837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18838. {
  18839. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18840. {
  18841. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18842. }
  18843. }
  18844. }
  18845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18851. } // END FOR DC CASE
  18852. }
  18853. //2.6====================================== Current.Import L2 ==============================================
  18854. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18855. {
  18856. // AC 3 phase L2 current
  18857. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18858. {
  18859. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18860. {
  18861. tempIndex = 2;
  18862. }
  18863. else
  18864. {
  18865. tempIndex = gun_index;
  18866. }
  18867. for (int index = 0; index < AC_QUANTITY; index++)
  18868. {
  18869. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18870. {
  18871. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18872. }
  18873. }// End of for AC_QUANTITY
  18874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18875. }
  18876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18881. }
  18882. //2.7====================================== Current.Import L3 ==============================================
  18883. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18884. {
  18885. // AC 3 phase L3 current
  18886. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18887. {
  18888. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18889. {
  18890. tempIndex = 2;
  18891. }
  18892. else
  18893. {
  18894. tempIndex = gun_index;
  18895. }
  18896. for (int index = 0; index < AC_QUANTITY; index++)
  18897. {
  18898. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18899. {
  18900. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18901. }
  18902. }// End of for AC_QUANTITY
  18903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18904. }
  18905. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18907. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18908. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18910. }
  18911. //2.9====================================== Voltage L2 ====================================================
  18912. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18913. {
  18914. // AC 3 phase L2 volatge
  18915. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18916. {
  18917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18918. {
  18919. tempIndex = 2;
  18920. }
  18921. else
  18922. {
  18923. tempIndex = gun_index;
  18924. }
  18925. for (int index = 0; index < AC_QUANTITY; index++)
  18926. {
  18927. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18928. {
  18929. 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
  18930. }
  18931. } // END OF FOR AC_QUANTITY
  18932. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18933. }
  18934. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18939. }
  18940. //2.10====================================== Voltage L3 ====================================================
  18941. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18942. {
  18943. // AC 3 phase L3 volatge
  18944. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18945. {
  18946. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18947. {
  18948. tempIndex = 2;
  18949. }
  18950. else
  18951. {
  18952. tempIndex = gun_index;
  18953. }
  18954. for (int index = 0; index < AC_QUANTITY; index++)
  18955. {
  18956. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18957. {
  18958. 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
  18959. }
  18960. } // END OF FOR AC_QUANTITY
  18961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18962. }
  18963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18968. }
  18969. //====================== Start SoC ================================
  18970. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18971. {
  18972. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18973. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  18974. {
  18975. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18976. {
  18977. tempIndex = ((gun_index==2) ? 1: 0);
  18978. }
  18979. else
  18980. {
  18981. tempIndex = gun_index;
  18982. }
  18983. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18984. {
  18985. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18986. {
  18987. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18988. {
  18989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18990. }
  18991. }
  18992. }
  18993. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18994. {
  18995. for (int index = 0; index < CCS_QUANTITY; index++)
  18996. {
  18997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18998. {
  18999. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  19000. }
  19001. }
  19002. }
  19003. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19004. {
  19005. for (int index = 0; index < GB_QUANTITY; index++)
  19006. {
  19007. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19008. {
  19009. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  19010. }
  19011. }
  19012. }
  19013. else if(gunType[gun_index] == GUN_TYPE_DO)
  19014. {
  19015. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19016. {
  19017. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19018. {
  19019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  19020. }
  19021. }
  19022. }
  19023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  19024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  19025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  19026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  19027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  19028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19029. } // END FOR DC CASE
  19030. }
  19031. //======================================== Message create ==============================================
  19032. json_object *StopTransaction = json_object_new_object();
  19033. json_object *transactionDatas = json_object_new_array();
  19034. json_object *sampledValues = json_object_new_array();
  19035. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19036. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19037. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19038. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19039. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19040. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19041. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  19042. {
  19043. json_object *transactionData = json_object_new_object();
  19044. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  19045. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  19046. {
  19047. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  19048. {
  19049. json_object *sampledValue = json_object_new_object();
  19050. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  19051. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  19052. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  19053. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  19054. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  19055. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  19056. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  19057. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  19058. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  19059. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  19060. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  19061. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  19062. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  19063. json_object_array_add(sampledValues, sampledValue);
  19064. }
  19065. }
  19066. json_object_object_add(transactionData, "sampledValue", sampledValues);
  19067. json_object_array_add(transactionDatas, transactionData);
  19068. }
  19069. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19070. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19071. ,MESSAGE_TYPE_CALL
  19072. ,guid
  19073. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19074. json_object_put(StopTransaction);
  19075. // Check File "TempStopTransaction" Exist
  19076. if((access(TempStopTransaction,F_OK))!=-1)
  19077. {
  19078. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19079. fclose(fopen(TempStopTransaction, "w"));
  19080. }
  19081. else
  19082. {
  19083. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19084. FILE *log = fopen(TempStopTransaction, "w+");
  19085. if(log == NULL)
  19086. {
  19087. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19088. return ;
  19089. }
  19090. else
  19091. {
  19092. fclose(log);
  19093. }
  19094. }
  19095. //Add TempStopTransaction | Update TempStopTransaction
  19096. // open file for writing
  19097. FILE *outfile;
  19098. outfile = fopen (TempStopTransaction, "a");
  19099. //DEBUG_INFO("data = %s\n", queuedata);
  19100. fputs(queuedata, outfile);
  19101. fputs("\n", outfile);
  19102. fclose (outfile);
  19103. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19104. OCPP_updatePeriodEnergy(gun_index);
  19105. }
  19106. void checkTempStopTransaction(int gun_index)
  19107. {
  19108. FILE *fptr1;
  19109. char ch;
  19110. char str[QUEUE_MESSAGE_LENGTH]={0};
  19111. char guid[37]={0};
  19112. char tempdata[65]={0};
  19113. char connectorStr[2]={0};
  19114. char TempStopTransaction[256];
  19115. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19116. fptr1 = fopen(TempStopTransaction, "r");
  19117. //TempStopTransaction格式: 槍號,StopTransaction封包
  19118. if (!fptr1)
  19119. {
  19120. //printf(" File not found or unable to open the input file!!\n");
  19121. return ;
  19122. }
  19123. ch=fgetc(fptr1);
  19124. //printf(" Now the content of the file %s is : \n",fname);
  19125. rewind(fptr1);
  19126. if(ch!=EOF)
  19127. {
  19128. // copy all contents to the temporary file except the specific line
  19129. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19130. {
  19131. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19132. if(str[0]=='\0')
  19133. {
  19134. break;
  19135. }
  19136. //TempStopTransaction格式: 槍號,StopTransaction封包
  19137. strncpy(connectorStr, str, 1);
  19138. if(atoi(connectorStr) != (gun_index+1))
  19139. {
  19140. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19141. fclose(fptr1);
  19142. return ;
  19143. }
  19144. //random_uuid(guid);
  19145. strncpy(guid, str+6, 36); //copy guid
  19146. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19147. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19148. {
  19149. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19150. }
  19151. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19152. OCPP_insert_transaction_msg(NO, str);
  19153. memset(str,0,ARRAY_SIZE(str));
  19154. }
  19155. }
  19156. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19157. fclose(fptr1);
  19158. remove(TempStopTransaction); // remove the original file
  19159. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19160. }
  19161. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19162. {
  19163. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19164. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19165. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19166. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19167. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19168. }
  19169. int GetWebSocketPingInterval(void)
  19170. {
  19171. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19172. }
  19173. int GetServerSign(void)
  19174. {
  19175. return server_sign;
  19176. }
  19177. uint8_t GetOcppSecurityProfile()
  19178. {
  19179. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19180. }
  19181. void GetOcppChargerBoxId(uint8_t *data)
  19182. {
  19183. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19184. }
  19185. void GetOcppSecurityPassword(uint8_t *data)
  19186. {
  19187. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19188. }
  19189. void SetOcppVersion(uint8_t *version)
  19190. {
  19191. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19192. DEBUG_INFO("ocpp version: %s\n", version);
  19193. if(strstr((char*)version, "ocpp1.6") != NULL)
  19194. {
  19195. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19196. }
  19197. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19198. {
  19199. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19200. system("pkill OcppBackend");
  19201. }
  19202. }
  19203. void SetServerSign(int value)
  19204. {
  19205. server_sign = value;
  19206. }
  19207. int GetBootNotificationInterval(void)
  19208. {
  19209. return BootNotificationInterval;
  19210. }
  19211. int GetInternetConn(void)
  19212. {
  19213. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19214. }
  19215. int GetBackendConnectionTimeout(void)
  19216. {
  19217. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19218. }
  19219. int isConnectorInitMode(int gun_index)
  19220. {
  19221. int tempIndex = 0;
  19222. int result = TRUE;
  19223. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19224. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19225. {
  19226. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19227. {
  19228. tempIndex = ((gun_index==2) ? 1: 0);
  19229. }
  19230. else
  19231. {
  19232. tempIndex = gun_index;
  19233. }
  19234. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19235. {
  19236. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19237. {
  19238. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19239. } //end of the same index
  19240. }//end of for CHAdeMO_QUANTITY
  19241. }
  19242. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19243. {
  19244. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19245. {
  19246. tempIndex = ((gun_index==2) ? 1: 0);
  19247. }
  19248. else
  19249. {
  19250. tempIndex = gun_index;
  19251. }
  19252. for (int index = 0; index < CCS_QUANTITY; index++)
  19253. {
  19254. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19255. {
  19256. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19257. } //end of the same index
  19258. } // end of for CCS_QUANTITY
  19259. }
  19260. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19261. {
  19262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19263. {
  19264. tempIndex = ((gun_index==2) ? 1: 0);
  19265. }
  19266. else
  19267. {
  19268. tempIndex = gun_index;
  19269. }
  19270. for (int index = 0; index < GB_QUANTITY; index++)
  19271. {
  19272. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19273. {
  19274. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19275. } //end of the same index
  19276. } // end of for GB_QUANTITY
  19277. }
  19278. else if(gunType[gun_index] == GUN_TYPE_DO)
  19279. {
  19280. tempIndex = gun_index;
  19281. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19282. {
  19283. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19284. {
  19285. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19286. } //end of the same index
  19287. }
  19288. }
  19289. else
  19290. {
  19291. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19292. {
  19293. tempIndex = 2;
  19294. }
  19295. else
  19296. {
  19297. tempIndex = gun_index;
  19298. }
  19299. for (int index = 0; index < AC_QUANTITY; index++)
  19300. {
  19301. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19302. {
  19303. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19304. }//end of the same index
  19305. }//end of for AC_QUANTITY
  19306. }
  19307. return result;
  19308. }
  19309. void refreshProcDogTimer()
  19310. {
  19311. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  19312. }
  19313. void InitialSystemValue(void)
  19314. {
  19315. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  19316. locallistVersion=0;
  19317. BootNotificationInterval = 0;
  19318. authorizeRetryTimes = 0;
  19319. GunStatusInterval = 10;
  19320. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  19321. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19322. //Hear Beat
  19323. HeartBeatWithNOResponse = 0;
  19324. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  19325. FirstHeartBeat = 0;
  19326. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19327. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19328. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19329. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19330. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19331. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19332. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19333. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19334. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19335. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19336. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19337. //Status && ConnectorPlugIn Setting
  19338. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19339. {
  19340. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19341. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19342. }
  19343. for (int index = 0; index < CCS_QUANTITY; index++)
  19344. {
  19345. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19346. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19347. }
  19348. for (int index = 0; index < GB_QUANTITY; index++)
  19349. {
  19350. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19351. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19352. }
  19353. for (int index = 0; index < AC_QUANTITY; index++)
  19354. {
  19355. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19356. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19357. }
  19358. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19359. {
  19360. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19361. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19362. }
  19363. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19364. {
  19365. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19366. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19367. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19368. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19369. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19370. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  19371. }
  19372. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19373. refreshStartTimer(&clientTime.Heartbeat);
  19374. sleep(1);
  19375. }
  19376. void LWS_Send(char *str)
  19377. {
  19378. //=====================================================
  19379. // Check InternetConn 0: disconnected, 1: connected
  19380. //====================================================
  19381. if(GetOcppConnStatus() == 0)
  19382. {
  19383. DEBUG_INFO("offline now !!!\n");
  19384. return;
  19385. }
  19386. // Only disable isWebsocketSendable operation initiated by charger
  19387. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19388. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19389. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19390. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19391. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19392. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19393. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19394. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19395. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19396. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19397. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19398. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19399. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19400. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19401. {
  19402. isWebsocketSendable = 0;
  19403. }
  19404. pthread_mutex_lock(&lock_send);
  19405. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19406. sprintf((char *)SendBuffer, "%s", str);
  19407. SendBufLen = strlen(str);
  19408. pthread_mutex_unlock(&lock_send);
  19409. lws_callback_on_writable(wsi_client);
  19410. //lws_service(context, 0);
  19411. //sleep(1);
  19412. }
  19413. void LWS_SendNow(char *str)
  19414. {
  19415. //=====================================================
  19416. // Check InternetConn 0: disconnected, 1: connected
  19417. //====================================================
  19418. if(GetOcppConnStatus() == 0)
  19419. {
  19420. DEBUG_INFO("offline now !!!\n");
  19421. return;
  19422. }
  19423. // Only disable isWebsocketSendable operation initiated by charger
  19424. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19425. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19426. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19427. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19428. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19429. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19430. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19431. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19432. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19433. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19434. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19435. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19436. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19437. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19438. {
  19439. isWebsocketSendable = 0;
  19440. }
  19441. pthread_mutex_lock(&lock_send);
  19442. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19443. sprintf((char *)SendBuffer, "%s", str);
  19444. SendBufLen = strlen(str);
  19445. pthread_mutex_unlock(&lock_send);
  19446. lws_callback_on_writable(wsi_client);
  19447. lws_service(context, 0);
  19448. //sleep(1);
  19449. }