MessageHandler.c 936 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376
  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. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //============================================
  80. // OCPP MeterValue request flag
  81. //============================================
  82. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  83. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  84. //=============================================
  85. // OCPP HeartBeat Response Not Receive Counts
  86. //============================================
  87. static int HeartBeatWithNOResponse = 0;
  88. extern sqlite3 *db;
  89. int TransactionMessageAttemptsGet(void);
  90. int TransactionMessageRetryIntervalGet(void);
  91. int GetOcppConnStatus(void);
  92. void SetOcppConnStatus(uint8_t status);
  93. int setKeyValue(char *key, char *value);
  94. void OCPP_get_TableAuthlocalAllData(void);
  95. void processUnkownKey(void);
  96. struct InterLock
  97. {
  98. unsigned char isGetDiagnosticGoing:1;
  99. unsigned char isUpdateFirmwareGoing:1;
  100. }interLock;
  101. struct ClientTime
  102. {
  103. struct timespec Heartbeat;
  104. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  105. struct timespec StartTransaction;
  106. struct timespec StopTransaction;
  107. struct timespec MeterValues[CONNECTOR_QUANTITY];
  108. struct timespec RemoteStartWait;
  109. struct timespec TcciQueryDeduct;
  110. }clientTime;
  111. typedef union
  112. {
  113. //Operations Initiated by Central System
  114. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  115. struct
  116. {
  117. //CsMsgValue[0]
  118. unsigned char StatusNotificationReq:1; //bit 0,
  119. unsigned char StatusNotificationConf:1; //bit 1,
  120. unsigned char TriggerMeterValue:1; //bit 2,
  121. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  122. unsigned char isOnCharging:1; //bit 4,
  123. unsigned char :3; //bit5~7
  124. }bits[CONNECTOR_QUANTITY];
  125. }CpinitiateMsg;
  126. CpinitiateMsg cpinitateMsg;
  127. //GetConfiguration Array
  128. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  129. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  131. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  132. #if 0
  133. static char *ChargePointErrorCodeStr[] = {
  134. MACROSTR(ConnectorLockFailure),
  135. MACROSTR(EVCommunicationError),
  136. MACROSTR(GroundFailure),
  137. MACROSTR(HighTemperature),
  138. MACROSTR(InternalError),
  139. MACROSTR(LocalListConflict),
  140. MACROSTR(NoError),
  141. MACROSTR(OtherError),
  142. MACROSTR(OverCurrentFailure),
  143. MACROSTR(OverVoltage),
  144. MACROSTR(PowerMeterFailure),
  145. MACROSTR(PowerSwitchFailure),
  146. MACROSTR(ReaderFailure),
  147. MACROSTR(ResetFailure),
  148. MACROSTR(UnderVoltage),
  149. MACROSTR(WeakSignal)
  150. };
  151. #endif
  152. static char * ChargePointStatusStr[] = {
  153. MACROSTR(Available),
  154. MACROSTR(Preparing),
  155. MACROSTR(Charging),
  156. MACROSTR(SuspendedEVSE),
  157. MACROSTR(SuspendedEV),
  158. MACROSTR(Finishing),
  159. MACROSTR(Reserved),
  160. MACROSTR(Unavailable),
  161. MACROSTR(Faulted)
  162. };
  163. static char *RegistrationStatusStr[] = {
  164. MACROSTR(Accepted),
  165. MACROSTR(Pending),
  166. MACROSTR(Rejected)
  167. };
  168. static char *AvailabilityTypeStr[] = {
  169. MACROSTR(Inoperative),
  170. MACROSTR(Operative)
  171. };
  172. static char *AvailabilityStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(Scheduled)
  176. };
  177. static char *ConfigurationStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(RebootRequired),
  181. MACROSTR(NotSupported)
  182. };
  183. static char *ClearCacheStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected)
  186. };
  187. static char *ChargingProfilePurposeTypeStr[] = {
  188. MACROSTR(ChargePointMaxProfile),
  189. MACROSTR(TxDefaultProfile),
  190. MACROSTR(TxProfile)
  191. };
  192. static char *ChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Rejected),
  195. MACROSTR(NotSupported)
  196. };
  197. static char *ClearChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Unknown)
  200. };
  201. static char *GetCompositeScheduleStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Rejected)
  204. };
  205. static char *UpdateTypeStr[] = {
  206. MACROSTR(Differential),
  207. MACROSTR(Full)
  208. };
  209. static char *UpdateStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Failed),
  212. MACROSTR(NotSupported),
  213. MACROSTR(VersionMismatch)
  214. };
  215. static char *RemoteStartStopStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Rejected)
  218. };
  219. static char *ReservationStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Faulted),
  222. MACROSTR(Occupied),
  223. MACROSTR(Rejected),
  224. MACROSTR(Unavailable)
  225. };
  226. static char *ResetTypeStr[] = {
  227. MACROSTR(Hard),
  228. MACROSTR(Soft)
  229. };
  230. static char *ResetStatusStr[] = {
  231. MACROSTR(Accepted),
  232. MACROSTR(Rejected)
  233. };
  234. static char * DiagnosticsStatusStr[] = {
  235. MACROSTR(Idle),
  236. MACROSTR(Uploaded),
  237. MACROSTR(UploadFailed),
  238. MACROSTR(Uploading)
  239. };
  240. static char * FirmwareStatusStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(Idle),
  245. MACROSTR(InstallationFailed),
  246. MACROSTR(Installing),
  247. MACROSTR(Installed)
  248. };
  249. static char * MessageTriggerStr[] = {
  250. MACROSTR(BootNotification),
  251. MACROSTR(DiagnosticsStatusNotification),
  252. MACROSTR(FirmwareStatusNotification),
  253. MACROSTR(Heartbeat),
  254. MACROSTR(MeterValues),
  255. MACROSTR(StatusNotification)
  256. };
  257. static char * TriggerMessageStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected),
  260. MACROSTR(NotImplemented)
  261. };
  262. static char * UnlockStatusStr[] = {
  263. MACROSTR(Unlocked),
  264. MACROSTR(UnlockFailed),
  265. MACROSTR(NotSupported)
  266. };
  267. #if 0
  268. static char * StopTransactionReasonStr[] = {
  269. MACROSTR(EmergencyStop),
  270. MACROSTR(EVDisconnected),
  271. MACROSTR(HardReset),
  272. MACROSTR(Local),
  273. MACROSTR(Other),
  274. MACROSTR(PowerLoss),
  275. MACROSTR(Reboot),
  276. MACROSTR(Remote),
  277. MACROSTR(SoftReset),
  278. MACROSTR(UnlockCommand),
  279. MACROSTR(DeAuthorized)
  280. };
  281. #endif
  282. static char * CancelReservationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Rejected)
  285. };
  286. static char * ReadingContextStr[] = {
  287. MACROSTR(Interruption.Begin),
  288. MACROSTR(Interruption.End),
  289. MACROSTR(Other),
  290. MACROSTR(Sample.Clock),
  291. MACROSTR(Sample.Periodic),
  292. MACROSTR(Transaction.Begin),
  293. MACROSTR(Transaction.End),
  294. MACROSTR(Trigger)
  295. };
  296. static char * ValueFormatStr[] = {
  297. MACROSTR(Raw),
  298. MACROSTR(SignedData)
  299. };
  300. static char * MeasurandStr[] = {
  301. MACROSTR(Current.Export),
  302. MACROSTR(Current.Import),
  303. MACROSTR(Current.Offered),
  304. MACROSTR(Energy.Active.Export.Register),
  305. MACROSTR(Energy.Active.Import.Register),
  306. MACROSTR(Energy.Reactive.Export.Register),
  307. MACROSTR(Energy.Reactive.Import.Register),
  308. MACROSTR(Energy.Active.Export.Interval),
  309. MACROSTR(Energy.Active.Import.Interval),
  310. MACROSTR(Energy.Reactive.Export.Interval),
  311. MACROSTR(Energy.Reactive.Import.Interval),
  312. MACROSTR(Frequency),
  313. MACROSTR(Power.Active.Export),
  314. MACROSTR(Power.Active.Import),
  315. MACROSTR(Power.Factor),
  316. MACROSTR(Power.Offered),
  317. MACROSTR(Power.Reactive.ExportMACROSTR),
  318. MACROSTR(Power.Reactive.Import),
  319. MACROSTR(RPM),
  320. MACROSTR(SoC),
  321. MACROSTR(Temperature),
  322. MACROSTR(Voltage)
  323. };
  324. static char * LocationStr[] = {
  325. MACROSTR(Body),
  326. MACROSTR(Cable),
  327. MACROSTR(EV),
  328. MACROSTR(Inlet),
  329. MACROSTR(Outlet)
  330. };
  331. static char * PhaseStr[] = {
  332. MACROSTR(L1),
  333. MACROSTR(L2),
  334. MACROSTR(L3),
  335. MACROSTR(N),
  336. MACROSTR(L1-N),
  337. MACROSTR(L2-N),
  338. MACROSTR(L3-N),
  339. MACROSTR(L1-L2),
  340. MACROSTR(L2-L3),
  341. MACROSTR(L3-L1)
  342. };
  343. static char * UnitOfMeasureStr[] = {
  344. MACROSTR(Wh),
  345. MACROSTR(kWh),
  346. MACROSTR(varh),
  347. MACROSTR(kvarh),
  348. MACROSTR(W),
  349. MACROSTR(kW),
  350. MACROSTR(VA),
  351. MACROSTR(kVA),
  352. MACROSTR(var),
  353. MACROSTR(kvar),
  354. MACROSTR(A),
  355. MACROSTR(V),
  356. MACROSTR(Celsius),
  357. MACROSTR(Fahrenheit),
  358. MACROSTR(K),
  359. MACROSTR(Percent)
  360. };
  361. //=========================================
  362. // TTIA routine
  363. //=========================================
  364. int sendTTIAInfo(uint8_t gun_index)
  365. {
  366. static int sn = 0;
  367. int result = FAIL;
  368. struct hostent *server;
  369. int udp_socket_fd;
  370. struct sockaddr_in dest_addr = {0};
  371. uint8_t tx_buf[80] = {0};
  372. uint8_t logBuf[256]= {0};
  373. uint8_t tx_len, tempIndex, socStart, socEnd;
  374. uint16_t PresentChargedEnergy;
  375. struct tm tmStart, tmEnd;
  376. DEBUG_INFO("sendTTIAInfo...\n");
  377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  378. {
  379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  380. {
  381. tempIndex = ((gun_index==2) ? 1: 0);
  382. }
  383. else
  384. {
  385. tempIndex = gun_index;
  386. }
  387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  388. {
  389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  390. {
  391. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  392. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  393. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  394. }
  395. }
  396. }
  397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  398. {
  399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  400. {
  401. tempIndex = ((gun_index==2) ? 1: 0);
  402. }
  403. else
  404. {
  405. tempIndex = gun_index;
  406. }
  407. for (int index = 0; index < CCS_QUANTITY; index++)
  408. {
  409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  410. {
  411. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  412. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  413. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  414. }
  415. }
  416. }
  417. else if(gunType[gun_index] == GUN_TYPE_GBT)
  418. {
  419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  420. {
  421. tempIndex = ((gun_index==2) ? 1: 0);
  422. }
  423. else
  424. {
  425. tempIndex = gun_index;
  426. }
  427. for (int index = 0; index < GB_QUANTITY; index++)
  428. {
  429. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  430. {
  431. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  432. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  433. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  434. }
  435. }
  436. }
  437. else if(gunType[gun_index] == GUN_TYPE_DO)
  438. {
  439. tempIndex = gun_index;
  440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  441. {
  442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  443. {
  444. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  445. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  446. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  447. }
  448. }
  449. }
  450. else
  451. {
  452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  453. {
  454. tempIndex = 2;
  455. }
  456. else
  457. {
  458. tempIndex = gun_index;
  459. }
  460. for (int index = 0; index < AC_QUANTITY; index++)
  461. {
  462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  463. {
  464. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  465. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  466. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  467. }
  468. }// END
  469. }
  470. // Message assembly
  471. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  472. tx_buf[4] = 0x02; // Protocol Version
  473. tx_buf[5] = 0xb0; // Message ID
  474. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  475. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  476. tx_buf[8] = 0x00; // CarID low byte
  477. tx_buf[9] = 0x00; // CarID high byte
  478. tx_buf[10] = 0x00; // ID Storage
  479. tx_buf[11] = 0x00; // Driver lowest byte
  480. tx_buf[12] = 0x00; // Driver 2nd byte
  481. tx_buf[13] = 0x00; // Driver 3rd byte
  482. tx_buf[14] = 0x00; // Driver highest byte
  483. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  484. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  485. tx_buf[17] = 0x00; // Reserve
  486. tx_buf[18] = 60 & 0xff; // Payload length low byte
  487. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  488. // EVSE provider
  489. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  490. // EVSE provider
  491. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  492. // EVSE id
  493. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  494. // Connector id
  495. tx_buf[37] = gun_index;
  496. // EVSE station
  497. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  498. // Vehicle SN
  499. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  500. // Mileage
  501. tx_buf[61] = 0x00; // lowest byte
  502. tx_buf[62] = 0x00; // 2nd byte
  503. tx_buf[63] = 0x00; // highest byte
  504. // Start date time 6 bytes
  505. 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))
  506. {
  507. struct tm *tmTarget;
  508. struct timeb tbTarget;
  509. tmStart.tm_year -= 1900;
  510. tmStart.tm_mon -= 1;
  511. tmStart.tm_gmtoff = 0;
  512. tbTarget.time = mktime(&tmStart);
  513. tbTarget.timezone = 0;
  514. tbTarget.time += (8*3600);
  515. tmTarget = gmtime(&tbTarget.time);
  516. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  517. tx_buf[65] = (tmTarget->tm_mon+1);
  518. tx_buf[66] = tmTarget->tm_mday;
  519. tx_buf[67] = tmTarget->tm_hour;
  520. tx_buf[68] = tmTarget->tm_min;
  521. tx_buf[69] = tmTarget->tm_sec;
  522. }
  523. // Stop date time 6 bytes
  524. 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))
  525. {
  526. struct tm *tmTarget;
  527. struct timeb tbTarget;
  528. tmEnd.tm_year -= 1900;
  529. tmEnd.tm_mon -= 1;
  530. tmEnd.tm_gmtoff = 0;
  531. tbTarget.time = mktime(&tmEnd);
  532. tbTarget.timezone = 0;
  533. tbTarget.time += (8*3600);
  534. tmTarget = gmtime(&tbTarget.time);
  535. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  536. tx_buf[71] = (tmTarget->tm_mon+1);
  537. tx_buf[72] = tmTarget->tm_mday;
  538. tx_buf[73] = tmTarget->tm_hour;
  539. tx_buf[74] = tmTarget->tm_min;
  540. tx_buf[75] = tmTarget->tm_sec;
  541. }
  542. // Session energy 2 bytes
  543. tx_buf[76] = PresentChargedEnergy & 0xff;
  544. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  545. // Start SOC 1 byte
  546. tx_buf[78] = socStart;
  547. // Stop SOC 1 byte
  548. tx_buf[79] = socEnd;
  549. // Open socket
  550. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  551. if(udp_socket_fd == -1)
  552. {
  553. DEBUG_ERROR("UDP socket create failed!\n");
  554. }
  555. else
  556. {
  557. // Get server DNS entry
  558. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  559. if (server == NULL)
  560. {
  561. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  562. }
  563. else
  564. {
  565. // Build the server's Internet address
  566. bzero((char *) &dest_addr, sizeof(dest_addr));
  567. dest_addr.sin_family = AF_INET;
  568. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  569. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  570. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  571. {
  572. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  573. {
  574. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  575. }
  576. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  577. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  578. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  579. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  580. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  581. DEBUG_TTIA_INFO("---------- Header ----------\n");
  582. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  583. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  584. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  585. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  586. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  587. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  588. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  589. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  590. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  591. DEBUG_TTIA_INFO("Len: 0x3C\n");
  592. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  593. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  594. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  595. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  596. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  597. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  598. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  599. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  600. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  601. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  602. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  603. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  604. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  605. DEBUG_TTIA_INFO("=========================================\n");
  606. sn++;
  607. result = PASS;
  608. }
  609. else
  610. {
  611. DEBUG_ERROR("UDP sent out fail.\n");
  612. }
  613. }
  614. }
  615. return result;
  616. }
  617. //=========================================
  618. // Save configuration
  619. //=========================================
  620. int runShellCmd(const char*cmd)
  621. {
  622. int result = FAIL;
  623. char buf[256];
  624. FILE *fp;
  625. fp = popen(cmd, "r");
  626. if(fp != NULL)
  627. {
  628. while(fgets(buf, sizeof(buf), fp) != NULL)
  629. {
  630. DEBUG_INFO("%s\n", buf);
  631. }
  632. result = PASS;
  633. }
  634. pclose(fp);
  635. return result;
  636. }
  637. int StoreUsrConfigData(struct SysConfigData *UsrData)
  638. {
  639. int result = PASS;
  640. int fd,wrd;
  641. unsigned int i,Chk;
  642. unsigned char *ptr, *BufTmp;
  643. int MtdBlockSize = 0x300000;
  644. Chk=0;
  645. ptr=(unsigned char *)UsrData;
  646. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  647. {
  648. memset(BufTmp,0,MtdBlockSize);
  649. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  650. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  651. Chk+=*(BufTmp+i);
  652. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  653. // Output configuration to file.
  654. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  655. if (fd < 0)
  656. {
  657. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  658. free(BufTmp);
  659. return 0;
  660. }
  661. wrd=write(fd, BufTmp, MtdBlockSize);
  662. close(fd);
  663. if(wrd<MtdBlockSize)
  664. {
  665. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  666. free(BufTmp);
  667. return 0;
  668. }
  669. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  670. DEBUG_INFO("Erase /dev/mtd10.\n");
  671. runShellCmd("flash_erase /dev/mtd10 0 0");
  672. DEBUG_INFO("Write /dev/mtd10.\n");
  673. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  674. DEBUG_INFO("Erase /dev/mtd11.\n");
  675. runShellCmd("flash_erase /dev/mtd11 0 0");
  676. DEBUG_INFO("Write /dev/mtd11.\n");
  677. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  678. system("rm -f /mnt/EvseConfig.bin");
  679. DEBUG_INFO("EvseConfig write to flash OK\n");
  680. }
  681. else
  682. {
  683. DEBUG_ERROR("alloc BlockSize NG\r\n");
  684. result = FAIL;
  685. }
  686. if(BufTmp!=NULL)
  687. free(BufTmp);
  688. return result;
  689. }
  690. //=========================================
  691. // Sqlite3 related function
  692. //=========================================
  693. static int selectSqlCount = 0;
  694. static int callback(void *data, int argc, char **argv, char **azColName){
  695. int i;
  696. //printf("%s: ", (const char*)data);
  697. selectSqlCount = argc;
  698. for(i = 0; i<argc; i++){
  699. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  700. }
  701. //printf("\n");
  702. return 0;
  703. }
  704. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  705. //int i;
  706. //printf("%s:\n", (const char*)data);
  707. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  708. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  709. return 0;
  710. }
  711. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  712. //printf("%s:\n", (const char*)data);
  713. //idTag
  714. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  715. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  716. //parentIdTag
  717. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  718. //expir_date
  719. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  720. //status
  721. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  722. //version
  723. if(columenCount > 5)
  724. idTagQuery.listVersionInt = atoi(columnValue[5]);
  725. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  726. return 0;
  727. }
  728. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  729. {
  730. // localversion = argv[5] ? atoi(argv[5]) : 0;
  731. // printf("localversion=%d\n", localversion);
  732. return 0;
  733. }
  734. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  735. {
  736. for (int i = 0; i < n_columns; i++)
  737. {
  738. DEBUG_INFO("%s\t", col_values[i]);
  739. }
  740. DEBUG_INFO("\n");
  741. return 0;
  742. }
  743. int OCPP_cleanLocalCache()
  744. {
  745. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  746. char *errMsg = 0;
  747. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  748. if (SQLITE_OK != rc)
  749. {
  750. DEBUG_INFO("SQL error: %s\n",errMsg);
  751. return FALSE;
  752. }
  753. return TRUE;
  754. }
  755. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  756. {
  757. int isSuccess = TRUE;
  758. int ret = 0;
  759. //const char* data = "Callback function called";
  760. char sql[300];
  761. char zErrMsg[200];
  762. memset(sql, 0, 300);
  763. memset(zErrMsg, 0, 200);
  764. 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);
  765. //* Execute SQL statement */
  766. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  767. if( ret != SQLITE_OK )
  768. {
  769. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  770. isSuccess = FALSE;
  771. }
  772. return isSuccess;
  773. }
  774. void OCPP_getIdTagFromLocalCache(char idTag[])
  775. {
  776. int rc = 0;
  777. char sql[100];
  778. char zErrMsg[100];
  779. memset(sql, 0, 100);
  780. memset(zErrMsg, 0, 100);
  781. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  782. memset(&idTagQuery, 0, sizeof(idTagQuery));
  783. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  784. /* Execute SQL statement */
  785. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  786. if( rc != SQLITE_OK )
  787. {
  788. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  789. }
  790. }
  791. void OCPP_getListVerion()
  792. {
  793. int rc = 0;
  794. // const char* data = "Callback function called";
  795. char sql[100];
  796. char zErrMsg[100];
  797. memset(sql, 0, 100);
  798. memset(zErrMsg, 0, 100);
  799. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  800. /* Execute SQL statement */
  801. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  802. if( rc != SQLITE_OK )
  803. {
  804. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  805. }
  806. }
  807. void OCPP_get_TableAuthlocalAllData(void)
  808. {
  809. int rc = 0;
  810. char sql[100];
  811. char zErrMsg[100];
  812. memset(sql, 0, 100);
  813. memset(zErrMsg, 0, 100);
  814. sprintf(sql,"select * from ocpp_auth_local ");
  815. /* Execute SQL statement */
  816. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  817. if( rc != SQLITE_OK )
  818. {
  819. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  820. }
  821. //return ver;
  822. }
  823. int OCPP_cleanLocalList()
  824. {
  825. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  826. char *errMsg = 0;
  827. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  828. if (SQLITE_OK != rc)
  829. {
  830. DEBUG_INFO("%s\n",errMsg);
  831. return FALSE;
  832. }
  833. return TRUE;
  834. }
  835. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  836. {
  837. int isSuccess = FALSE;
  838. int ret = 0;
  839. //const char* data = "Callback function called";
  840. char sql[300];
  841. char zErrMsg[200];
  842. memset(sql, 0, 300);
  843. memset(zErrMsg, 0, 200);
  844. 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);
  845. //* Execute SQL statement */
  846. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  847. if( ret != SQLITE_OK )
  848. {
  849. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  850. return isSuccess;
  851. }
  852. memset(sql, 0, 300);
  853. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  854. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  855. if( ret != SQLITE_OK )
  856. {
  857. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  858. return isSuccess;
  859. }
  860. isSuccess = TRUE;
  861. return isSuccess;
  862. }
  863. void OCPP_getIdTagFromLocalList(char idTag[])
  864. {
  865. int rc = 0;
  866. // const char* data = "Callback function called";
  867. char sql[100];
  868. char zErrMsg[100];
  869. memset(sql, 0, 100);
  870. memset(zErrMsg, 0, 100);
  871. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  872. memset(&idTagQuery, 0, sizeof(idTagQuery));
  873. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  874. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  875. /* Execute SQL statement */
  876. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  877. if( rc != SQLITE_OK )
  878. {
  879. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  880. }
  881. //return ver;
  882. }
  883. void OCPP_deleteIdTagFromLocalList(char idTag[])
  884. {
  885. //int ver = 0;
  886. //int isSuccess = FALSE;
  887. int rc = 0;
  888. char sql[100];
  889. char zErrMsg[100];
  890. memset(sql, 0, 100);
  891. memset(zErrMsg, 0, 100);
  892. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  893. //* Execute SQL statement */
  894. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  895. if( rc != SQLITE_OK )
  896. {
  897. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  898. }
  899. }
  900. int getCurrentYear()
  901. {
  902. int result = 0;
  903. time_t CurrentTime;
  904. struct tm *tm;
  905. CurrentTime = time(NULL);
  906. tm=localtime(&CurrentTime);
  907. result = (tm->tm_year + 1900);
  908. return result;
  909. }
  910. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  911. {
  912. int result = PASS;
  913. char* errMsg = NULL;
  914. char sqlStr[8192];
  915. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  916. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  917. {
  918. result = FAIL;
  919. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  920. }
  921. 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));
  922. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  923. {
  924. result = FAIL;
  925. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  926. }
  927. return result;
  928. }
  929. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  930. {
  931. int isSuccess = TRUE;
  932. int tempIndex;
  933. json_object *EnergyDataTransfer = json_object_new_object();
  934. json_object *periodEnergys = json_object_new_object();
  935. char sql[1024];
  936. char zErrMsg[200];
  937. memset(sql, 0, ARRAY_SIZE(sql));
  938. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  940. {
  941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  942. {
  943. tempIndex = ((gun_index==2) ? 1: 0);
  944. }
  945. else
  946. {
  947. tempIndex = gun_index;
  948. }
  949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  950. {
  951. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  952. {
  953. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  954. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  955. {
  956. uint8_t period[3];
  957. sprintf((char*)period, "%d", idxPeriod);
  958. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  959. }
  960. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  961. } //end of the same index
  962. }//end of for CHAdeMO_QUANTITY
  963. }
  964. else if(gunType[gun_index] == GUN_TYPE_CCS)
  965. {
  966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  967. {
  968. tempIndex = ((gun_index==2) ? 1: 0);
  969. }
  970. else
  971. {
  972. tempIndex = gun_index;
  973. }
  974. for (int index = 0; index < CCS_QUANTITY; index++)
  975. {
  976. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  977. {
  978. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  979. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  980. {
  981. uint8_t period[3];
  982. sprintf((char*)period, "%d", idxPeriod);
  983. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  984. }
  985. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  986. } //end of the same index
  987. } // end of for CCS_QUANTITY
  988. }
  989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  990. {
  991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  992. {
  993. tempIndex = ((gun_index==2) ? 1: 0);
  994. }
  995. else
  996. {
  997. tempIndex = gun_index;
  998. }
  999. for (int index = 0; index < GB_QUANTITY; index++)
  1000. {
  1001. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1002. {
  1003. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1004. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1005. {
  1006. uint8_t period[3];
  1007. sprintf((char*)period, "%d", idxPeriod);
  1008. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1009. }
  1010. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1011. } //end of the same index
  1012. } // end of for GB_QUANTITY
  1013. }
  1014. else if(gunType[gun_index] == GUN_TYPE_DO)
  1015. {
  1016. tempIndex = gun_index;
  1017. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1018. {
  1019. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1020. {
  1021. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1022. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1023. {
  1024. uint8_t period[3];
  1025. sprintf((char*)period, "%d", idxPeriod);
  1026. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1027. }
  1028. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1029. } //end of the same index
  1030. }
  1031. }
  1032. else
  1033. {
  1034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1035. {
  1036. tempIndex = 2;
  1037. }
  1038. else
  1039. {
  1040. tempIndex = gun_index;
  1041. }
  1042. for (int index = 0; index < AC_QUANTITY; index++)
  1043. {
  1044. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1045. {
  1046. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1047. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1048. {
  1049. uint8_t period[3];
  1050. sprintf((char*)period, "%d", idxPeriod);
  1051. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1052. }
  1053. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1054. }//end of the same index
  1055. }//end of for AC_QUANTITY
  1056. }
  1057. 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));
  1058. json_object_put(EnergyDataTransfer);
  1059. //* Execute SQL statement */
  1060. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1061. {
  1062. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1063. isSuccess = FALSE;
  1064. }
  1065. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1066. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1067. {
  1068. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1069. isSuccess = FALSE;
  1070. }
  1071. return isSuccess;
  1072. }
  1073. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1074. {
  1075. int isSuccess = TRUE;
  1076. char sql[512];
  1077. char zErrMsg[200];
  1078. int rows, cols;
  1079. char **resultData;
  1080. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1081. /* Execute SQL statement */
  1082. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1083. {
  1084. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1085. isSuccess = FALSE;
  1086. }
  1087. else
  1088. {
  1089. if((rows > 0) && (atoi(resultData[4]) > 0))
  1090. {
  1091. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1092. }
  1093. else
  1094. {
  1095. DEBUG_WARN("There is not match transaction data.\n");
  1096. isSuccess = FALSE;
  1097. }
  1098. }
  1099. return isSuccess;
  1100. }
  1101. 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)
  1102. {
  1103. int result = PASS;
  1104. char* errMsg = NULL;
  1105. char sqlStr[8192];
  1106. sprintf(sqlStr, "insert 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');",
  1107. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1108. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1109. {
  1110. result = FAIL;
  1111. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1112. }
  1113. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1114. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1115. {
  1116. result = FAIL;
  1117. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1118. }
  1119. return result;
  1120. }
  1121. int OCPP_update_deduct_info(int txId, char *creditNo)
  1122. {
  1123. int result = PASS;
  1124. char* errMsg = NULL;
  1125. char sqlStr[8192];
  1126. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1127. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1128. {
  1129. result = FAIL;
  1130. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1131. }
  1132. return result;
  1133. }
  1134. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1135. {
  1136. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1137. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1138. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1139. atoi(columnValue[1]),
  1140. columnValue[2],
  1141. atoi(columnValue[3])==1?"true":"false",
  1142. atoi(columnValue[4])==1?"true":"false",
  1143. columnValue[5],
  1144. columnValue[9]);
  1145. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1146. return 0;
  1147. }
  1148. void OCPP_query_deduct_info()
  1149. {
  1150. int rc = 0;
  1151. char sql[100];
  1152. char zErrMsg[100];
  1153. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1154. /* Execute SQL statement */
  1155. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1156. if( rc != SQLITE_OK )
  1157. {
  1158. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1159. }
  1160. }
  1161. void reportReaderStatus(int gun_index)
  1162. {
  1163. struct timeval tmnow;
  1164. struct tm *tm;
  1165. char buf[28];//, usec_buf[6];
  1166. gettimeofday(&tmnow, NULL);
  1167. time_t t;
  1168. t = time(NULL);
  1169. /*UTC time and date*/
  1170. tm = gmtime(&t);
  1171. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1172. #if 0 // remove temporally
  1173. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1174. strcat(buf,".");
  1175. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1176. strcat(buf,usec_buf);
  1177. #endif
  1178. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1179. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  1180. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1181. (gun_index+1),
  1182. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1183. buf,
  1184. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1185. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1186. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1187. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1188. }
  1189. //==========================================
  1190. // Check time passed since today
  1191. //==========================================
  1192. long long DiffTimebWithNow(struct timeb ST)
  1193. {
  1194. //return milli-second
  1195. struct timeb ET;
  1196. long long StartTime,StopTime;
  1197. ftime(&ET);
  1198. StartTime=(long long)ST.time;
  1199. StopTime=(long long)ET.time;
  1200. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1201. }
  1202. int getTimePassSinceToday(uint8_t gun_index)
  1203. {
  1204. int result = -1;
  1205. static time_t lastTime[4];
  1206. time_t t;
  1207. struct tm *tmStartToday;
  1208. struct timeb tbStartToday;
  1209. t=time(NULL);
  1210. if(difftime(t, lastTime[gun_index])>0)
  1211. {
  1212. tmStartToday=localtime(&t);
  1213. tmStartToday->tm_hour = 0;
  1214. tmStartToday->tm_min = 0;
  1215. tmStartToday->tm_sec = 0;
  1216. tbStartToday.time = mktime(tmStartToday);
  1217. tbStartToday.millitm = 0;
  1218. result = DiffTimebWithNow(tbStartToday)/1000;
  1219. lastTime[gun_index] = t;
  1220. }
  1221. return result;
  1222. }
  1223. void getNowDatetime(uint8_t *data)
  1224. {
  1225. time_t t = time(NULL);
  1226. struct tm tm = *localtime(&t);
  1227. 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);
  1228. }
  1229. int syncDateTimeRTC(uint8_t *data)
  1230. {
  1231. struct ParsingResult
  1232. {
  1233. int result;
  1234. int scanedElement;
  1235. int year;
  1236. int month;
  1237. int mday;
  1238. int hour;
  1239. int min;
  1240. int sec;
  1241. int tz_hour;
  1242. int tz_min;
  1243. float minSec;
  1244. }result;
  1245. struct tm tmOrg;
  1246. struct tm *tmTarget;
  1247. struct timeb tbTarget;
  1248. char buf[128];
  1249. memset(&result, 0x00, sizeof(struct ParsingResult));
  1250. result.result = PASS;
  1251. if(strstr((char*)data, ".") != NULL)
  1252. {
  1253. // Original data with mini second
  1254. if(strstr((char*)data, "Z") != NULL)
  1255. {
  1256. // Original data with Z
  1257. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1258. &result.year,
  1259. &result.month,
  1260. &result.mday,
  1261. &result.hour,
  1262. &result.min,
  1263. &result.sec,
  1264. &result.minSec);
  1265. }
  1266. else
  1267. {
  1268. // Original data without Z
  1269. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1270. &result.year,
  1271. &result.month,
  1272. &result.mday,
  1273. &result.hour,
  1274. &result.min,
  1275. &result.sec,
  1276. &result.minSec,
  1277. &result.tz_hour,
  1278. &result.tz_min);
  1279. }
  1280. }
  1281. else
  1282. {
  1283. // Original data without mini second
  1284. if(strstr((char*)data, "Z") != NULL)
  1285. {
  1286. // Original data with Z
  1287. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1288. &result.year,
  1289. &result.month,
  1290. &result.mday,
  1291. &result.hour,
  1292. &result.min,
  1293. &result.sec);
  1294. }
  1295. else
  1296. {
  1297. // Original data without Z
  1298. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1299. &result.year,
  1300. &result.month,
  1301. &result.mday,
  1302. &result.hour,
  1303. &result.min,
  1304. &result.sec,
  1305. &result.tz_hour,
  1306. &result.tz_min);
  1307. }
  1308. }
  1309. tmOrg.tm_year = result.year - 1900;
  1310. tmOrg.tm_mon = result.month - 1;
  1311. tmOrg.tm_mday = result.mday;
  1312. tmOrg.tm_hour = result.hour;
  1313. tmOrg.tm_min = result.min;
  1314. tmOrg.tm_sec = result.sec;
  1315. tmOrg.tm_gmtoff = 0;
  1316. tbTarget.time = mktime(&tmOrg);
  1317. tbTarget.timezone = 0;
  1318. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1319. tmTarget = gmtime(&tbTarget.time);
  1320. 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);
  1321. //DEBUG_INFO(" org date time: %s\n", data);
  1322. //DEBUG_INFO("parse date time: %s\n", buf);
  1323. system(buf);
  1324. system("/sbin/hwclock -w --systohc");
  1325. if(result.scanedElement < 6)
  1326. result.result = FAIL;
  1327. return result.result;
  1328. }
  1329. //==========================================
  1330. // GetCompositeSchedule logic related function
  1331. //==========================================
  1332. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1333. {
  1334. //return milli-second
  1335. unsigned int StartTime,StopTime;
  1336. StartTime=(unsigned int)ST.time;
  1337. StopTime=(unsigned int)ET.time;
  1338. return (StopTime-StartTime);
  1339. }
  1340. int DiffTimebWithNowSec(struct timeb ST)
  1341. {
  1342. //return milli-second
  1343. struct timeb ET;
  1344. unsigned int StartTime,StopTime;
  1345. ftime(&ET);
  1346. StartTime=(unsigned int)ST.time;
  1347. StopTime=(unsigned int)ET.time;
  1348. return (StopTime-StartTime);
  1349. }
  1350. int getStartStop(uint8_t *start, uint8_t *stop)
  1351. {
  1352. int result = -1;
  1353. struct tm tmStart;
  1354. struct timeb tbStart;
  1355. struct tm tmStop;
  1356. struct timeb tbStop;
  1357. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1358. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1359. {
  1360. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  1361. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  1362. tmStart.tm_year -= 1900;
  1363. tmStart.tm_mon -= 1;
  1364. tbStart.time = mktime(&tmStart);
  1365. tbStart.millitm = 0;
  1366. tmStop.tm_year -= 1900;
  1367. tmStop.tm_mon -= 1;
  1368. tbStop.time = mktime(&tmStop);
  1369. tbStop.millitm = 0;
  1370. result = DiffTimebSec(tbStart, tbStop);
  1371. //DEBUG_INFO("getStartStop(): %d\n", result);
  1372. }
  1373. else
  1374. {
  1375. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1376. }
  1377. return result;
  1378. }
  1379. int isOvertNow(uint8_t *start)
  1380. {
  1381. int result = NO;
  1382. struct ParsingResult
  1383. {
  1384. int result;
  1385. int scanedElement;
  1386. int year;
  1387. int month;
  1388. int mday;
  1389. int hour;
  1390. int min;
  1391. int sec;
  1392. int tz_hour;
  1393. int tz_min;
  1394. float minSec;
  1395. }parsingResult;
  1396. struct tm tmStart;
  1397. struct timeb tbStart;
  1398. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1399. if(strstr((char*)start, ".") != NULL)
  1400. {
  1401. // Original data with mini second
  1402. if(strstr((char*)start, "Z") != NULL)
  1403. {
  1404. // Original data with Z
  1405. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1406. &parsingResult.year,
  1407. &parsingResult.month,
  1408. &parsingResult.mday,
  1409. &parsingResult.hour,
  1410. &parsingResult.min,
  1411. &parsingResult.sec,
  1412. &parsingResult.minSec);
  1413. }
  1414. else
  1415. {
  1416. // Original data without Z
  1417. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1418. &parsingResult.year,
  1419. &parsingResult.month,
  1420. &parsingResult.mday,
  1421. &parsingResult.hour,
  1422. &parsingResult.min,
  1423. &parsingResult.sec,
  1424. &parsingResult.minSec,
  1425. &parsingResult.tz_hour,
  1426. &parsingResult.tz_min);
  1427. }
  1428. }
  1429. else
  1430. {
  1431. // Original data without mini second
  1432. if(strstr((char*)start, "Z") != NULL)
  1433. {
  1434. // Original data with Z
  1435. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1436. &parsingResult.year,
  1437. &parsingResult.month,
  1438. &parsingResult.mday,
  1439. &parsingResult.hour,
  1440. &parsingResult.min,
  1441. &parsingResult.sec);
  1442. }
  1443. else
  1444. {
  1445. // Original data without Z
  1446. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1447. &parsingResult.year,
  1448. &parsingResult.month,
  1449. &parsingResult.mday,
  1450. &parsingResult.hour,
  1451. &parsingResult.min,
  1452. &parsingResult.sec,
  1453. &parsingResult.tz_hour,
  1454. &parsingResult.tz_min);
  1455. }
  1456. }
  1457. if(parsingResult.scanedElement >= 6)
  1458. {
  1459. tmStart.tm_year = parsingResult.year - 1900;
  1460. tmStart.tm_mon = parsingResult.month - 1;
  1461. tmStart.tm_mday = parsingResult.mday;
  1462. tmStart.tm_hour = parsingResult.hour;
  1463. tmStart.tm_min = parsingResult.min;
  1464. tmStart.tm_sec = parsingResult.sec;
  1465. tmStart.tm_gmtoff = 0;
  1466. tbStart.time = mktime(&tmStart);
  1467. tbStart.timezone = 0;
  1468. tbStart.millitm = 0;
  1469. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1470. if(DiffTimebWithNowSec(tbStart) <= 0)
  1471. result = NO;
  1472. else
  1473. result = YES;
  1474. }
  1475. else
  1476. {
  1477. DEBUG_WARN("Start date parsing error.\n");
  1478. }
  1479. return result;
  1480. }
  1481. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1482. {
  1483. int result = -1;
  1484. struct tm tmStart;
  1485. struct timeb tbStart;
  1486. struct tm tmStop;
  1487. struct timeb tbStop;
  1488. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1489. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1490. {
  1491. tmStart.tm_year -= 1900;
  1492. tmStart.tm_mon -= 1;
  1493. tbStart.time = mktime(&tmStart);
  1494. tbStart.millitm = 0;
  1495. tmStop.tm_year -= 1900;
  1496. tmStop.tm_mon -= 1;
  1497. tbStop.time = mktime(&tmStop);
  1498. tbStop.millitm = 0;
  1499. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1500. }
  1501. return result;
  1502. }
  1503. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1504. {
  1505. FILE *fp;
  1506. char profileFileName[128];
  1507. char *line = NULL;
  1508. size_t len = 0;
  1509. time_t CurrentTime;
  1510. struct tm *tmComposite;
  1511. struct StructChargingProfile maxProfile;
  1512. struct StructChargingProfile compositeProfile;
  1513. uint8_t limitMax=0;
  1514. int compositePeriodIdx = 0;
  1515. CurrentTime = time(NULL);
  1516. tmComposite=localtime(&CurrentTime);
  1517. 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);
  1518. if(isUnitA)
  1519. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1520. else
  1521. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1522. compositeProfile.ChargingSchedule.Duration = durationReq;
  1523. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1524. {
  1525. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1526. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1527. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1528. }
  1529. compositeProfile.ChargingProfileId = 0;
  1530. compositeProfile.StackLevel = 99 ;
  1531. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1532. maxProfile.ChargingProfileId = -1;
  1533. maxProfile.ChargingSchedule.Duration = -1;
  1534. system("rm -f /tmp/*.json");
  1535. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1536. // Search max profile
  1537. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1538. if((access(profileFileName, F_OK))!=-1)
  1539. {
  1540. fp = fopen(profileFileName, "r");
  1541. while(getline(&line, &len, fp) != -1)
  1542. {
  1543. json_object *obj = NULL;
  1544. obj = json_tokener_parse(line);
  1545. if(is_error(obj))
  1546. {
  1547. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1548. }
  1549. else
  1550. {
  1551. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1552. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1553. )
  1554. {
  1555. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1556. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1557. )
  1558. {
  1559. struct tm tmFrom, tmTo;
  1560. struct timeb tbFrom, tbTo;
  1561. 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) &&
  1562. (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))
  1563. {
  1564. tmFrom.tm_year -= 1900;
  1565. tmFrom.tm_mon -= 1;
  1566. tbFrom.time = mktime(&tmFrom);
  1567. tmTo.tm_year -= 1900;
  1568. tmTo.tm_mon -= 1;
  1569. tbTo.time = mktime(&tmTo);
  1570. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1571. {
  1572. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1573. {
  1574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1575. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1576. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1577. }
  1578. maxProfile.ChargingProfileId = -1;
  1579. maxProfile.StackLevel = -1;
  1580. if(maxProfile.ChargingProfileId == -1)
  1581. DEBUG_INFO("MaxProfile found.\n");
  1582. else
  1583. DEBUG_INFO("MaxProfile updated.\n");
  1584. // Required item
  1585. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1586. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1587. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1588. if(isUnitA)
  1589. {
  1590. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1591. 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++)
  1592. {
  1593. 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"));
  1594. 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?
  1595. 3:
  1596. 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")));
  1597. 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")));
  1598. }
  1599. }
  1600. else
  1601. {
  1602. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1603. 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++)
  1604. {
  1605. 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"));
  1606. 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?
  1607. 3:
  1608. 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")));
  1609. 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));
  1610. }
  1611. }
  1612. // Optional item
  1613. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1614. {
  1615. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1616. }
  1617. else
  1618. {
  1619. sprintf((char*)maxProfile.ValidFrom, " ");
  1620. }
  1621. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1622. {
  1623. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1624. }
  1625. else
  1626. {
  1627. sprintf((char*)maxProfile.ValidTo, " ");
  1628. }
  1629. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1630. {
  1631. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1632. }
  1633. else
  1634. {
  1635. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1636. }
  1637. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1638. {
  1639. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1640. }
  1641. else
  1642. {
  1643. maxProfile.TransactionId = -1;
  1644. }
  1645. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1646. {
  1647. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1648. }
  1649. else
  1650. {
  1651. maxProfile.ChargingSchedule.Duration = 86400;
  1652. }
  1653. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1654. {
  1655. 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")));
  1656. }
  1657. else
  1658. {
  1659. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1660. }
  1661. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1662. {
  1663. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1664. }
  1665. else
  1666. {
  1667. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1668. }
  1669. }
  1670. }
  1671. }
  1672. else
  1673. {
  1674. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1675. {
  1676. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1677. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1678. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1679. }
  1680. maxProfile.ChargingProfileId = -1;
  1681. maxProfile.StackLevel = -1;
  1682. if(maxProfile.ChargingProfileId == -1)
  1683. DEBUG_INFO("MaxProfile found.\n");
  1684. else
  1685. DEBUG_INFO("MaxProfile updated.\n");
  1686. // Required item
  1687. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1688. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1689. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1690. if(isUnitA)
  1691. {
  1692. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1693. 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++)
  1694. {
  1695. 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"));
  1696. 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?
  1697. 3:
  1698. 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")));
  1699. 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")));
  1700. }
  1701. }
  1702. else
  1703. {
  1704. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1705. 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++)
  1706. {
  1707. 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"));
  1708. 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?
  1709. 3:
  1710. 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")));
  1711. 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));
  1712. }
  1713. }
  1714. // Optional item
  1715. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1716. {
  1717. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1718. }
  1719. else
  1720. {
  1721. sprintf((char*)maxProfile.ValidFrom, " ");
  1722. }
  1723. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1724. {
  1725. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1726. }
  1727. else
  1728. {
  1729. sprintf((char*)maxProfile.ValidTo, " ");
  1730. }
  1731. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1732. {
  1733. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1734. }
  1735. else
  1736. {
  1737. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1738. }
  1739. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1740. {
  1741. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1742. }
  1743. else
  1744. {
  1745. maxProfile.TransactionId = -1;
  1746. }
  1747. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1748. {
  1749. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1750. }
  1751. else
  1752. {
  1753. maxProfile.ChargingSchedule.Duration = 86400;
  1754. }
  1755. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1756. {
  1757. 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")));
  1758. }
  1759. else
  1760. {
  1761. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1762. }
  1763. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1764. {
  1765. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1766. }
  1767. else
  1768. {
  1769. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1770. }
  1771. }
  1772. }
  1773. }
  1774. json_object_put(obj);
  1775. }
  1776. fclose(fp);
  1777. /*
  1778. if(maxProfile.ChargingProfileId !=-1)
  1779. {
  1780. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1781. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1782. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1783. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1784. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1785. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1786. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1787. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1788. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1789. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1790. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1791. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1792. {
  1793. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1794. {
  1795. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1796. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1797. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1798. }
  1799. }
  1800. }
  1801. else
  1802. DEBUG_INFO("MaxProfile not found.\n");
  1803. DEBUG_INFO("------------------------------------\n");*/
  1804. }
  1805. if(maxProfile.ChargingProfileId != -1)
  1806. {
  1807. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1808. {
  1809. if(maxProfile.ChargingSchedule.Duration != -1)
  1810. {
  1811. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1812. 0:
  1813. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1814. }
  1815. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1816. {
  1817. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1818. {
  1819. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1820. 0:
  1821. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1822. if(idxPeriod > 0)
  1823. {
  1824. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1825. {
  1826. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1833. {
  1834. if(maxProfile.ChargingSchedule.Duration != -1)
  1835. {
  1836. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1837. }
  1838. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1839. {
  1840. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1841. {
  1842. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1843. if(idxPeriod > 0)
  1844. {
  1845. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1846. {
  1847. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1848. }
  1849. }
  1850. }
  1851. }
  1852. }
  1853. else
  1854. {
  1855. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1856. {
  1857. if(maxProfile.ChargingSchedule.Duration != -1)
  1858. {
  1859. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1860. 0:
  1861. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1862. }
  1863. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1864. {
  1865. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1866. {
  1867. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1868. 0:
  1869. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1870. if(idxPeriod > 0)
  1871. {
  1872. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1873. {
  1874. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1875. }
  1876. }
  1877. }
  1878. }
  1879. }
  1880. else
  1881. {
  1882. if(maxProfile.ChargingSchedule.Duration != -1)
  1883. {
  1884. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1885. 0:
  1886. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1887. }
  1888. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1889. {
  1890. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1891. {
  1892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1893. 0:
  1894. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1895. if(idxPeriod > 0)
  1896. {
  1897. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1898. {
  1899. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1900. }
  1901. }
  1902. }
  1903. }
  1904. }
  1905. }
  1906. /*
  1907. DEBUG_INFO("MaxProfile after align.\n");
  1908. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1909. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1910. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1911. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1912. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1913. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1914. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1915. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1916. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1917. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1918. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1919. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1920. {
  1921. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1922. {
  1923. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1924. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1925. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1926. }
  1927. }
  1928. DEBUG_INFO("------------------------------------\n");*/
  1929. }
  1930. // Find each profile period quantity
  1931. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1932. {
  1933. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1934. limitMax = idx+1;
  1935. }
  1936. if(maxProfile.ChargingProfileId != -1)
  1937. {
  1938. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1939. {
  1940. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1941. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1942. (maxProfile.ChargingSchedule.Duration > 0))
  1943. {
  1944. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1945. {
  1946. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1947. compositePeriodIdx++;
  1948. }
  1949. else
  1950. {
  1951. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1952. }
  1953. }
  1954. }
  1955. }
  1956. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1957. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1958. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1959. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1960. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1961. {
  1962. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1963. {
  1964. compositeProfile.ChargingProfileId = 1;
  1965. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1966. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1967. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1968. }
  1969. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1970. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1971. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1972. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1973. }
  1974. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1975. if(line)
  1976. free(line);
  1977. }
  1978. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1979. {
  1980. FILE *fp;
  1981. char profileFileName[128];
  1982. char *line = NULL;
  1983. size_t len = 0;
  1984. time_t CurrentTime;
  1985. struct tm *tmComposite;
  1986. struct StructChargingProfile maxProfile;
  1987. struct StructChargingProfile defaultTxProfile;
  1988. struct StructChargingProfile txProfile;
  1989. struct StructChargingProfile compositeProfile;
  1990. struct StructChargingSchedulePeriod tmpPeriod;
  1991. uint8_t limitMax=0;
  1992. uint8_t limitDef=0;
  1993. uint8_t limitTx=0;
  1994. int compositePeriodIdx = 0;
  1995. CurrentTime = time(NULL);
  1996. tmComposite=localtime(&CurrentTime);
  1997. 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);
  1998. if(isUnitA)
  1999. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2000. else
  2001. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2002. compositeProfile.ChargingSchedule.Duration = durationReq;
  2003. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2004. {
  2005. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2006. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2007. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2008. }
  2009. compositeProfile.ChargingProfileId = 0;
  2010. compositeProfile.StackLevel = 99 ;
  2011. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2012. maxProfile.ChargingProfileId = -1;
  2013. defaultTxProfile.ChargingProfileId = -1;
  2014. txProfile.ChargingProfileId = -1;
  2015. maxProfile.ChargingSchedule.Duration = -1;
  2016. defaultTxProfile.ChargingSchedule.Duration = -1;
  2017. txProfile.ChargingSchedule.Duration = -1;
  2018. system("rm -f /tmp/*.json");
  2019. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2020. /*
  2021. * Search valid charging profile
  2022. */
  2023. //DEBUG_INFO("====================================\n");
  2024. // Search tx profile
  2025. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2026. if((access(profileFileName, F_OK))!=-1)
  2027. {
  2028. fp = fopen(profileFileName, "r");
  2029. while(getline(&line, &len, fp) != -1)
  2030. {
  2031. json_object *obj = NULL;
  2032. obj = json_tokener_parse(line);
  2033. if(is_error(obj))
  2034. {
  2035. DEBUG_ERROR("Parse txProfile from file error.\n");
  2036. }
  2037. else
  2038. {
  2039. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2040. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2041. )
  2042. {
  2043. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2044. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2045. )
  2046. {
  2047. struct tm tmFrom, tmTo;
  2048. struct timeb tbFrom, tbTo;
  2049. 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) &&
  2050. (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))
  2051. {
  2052. tmFrom.tm_year -= 1900;
  2053. tmFrom.tm_mon -= 1;
  2054. tbFrom.time = mktime(&tmFrom);
  2055. tmTo.tm_year -= 1900;
  2056. tmTo.tm_mon -= 1;
  2057. tbTo.time = mktime(&tmTo);
  2058. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2059. {
  2060. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2061. {
  2062. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2063. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2064. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2065. }
  2066. txProfile.ChargingProfileId = -1;
  2067. txProfile.StackLevel = -1;
  2068. if(txProfile.ChargingProfileId == -1)
  2069. DEBUG_INFO("TxProfile found.\n");
  2070. else
  2071. DEBUG_INFO("TxProfile updated.\n");
  2072. // Required item
  2073. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2074. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2075. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2076. if(isUnitA)
  2077. {
  2078. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2079. 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++)
  2080. {
  2081. 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"));
  2082. 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?
  2083. 3:
  2084. 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")));
  2085. 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")));
  2086. }
  2087. }
  2088. else
  2089. {
  2090. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2091. 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++)
  2092. {
  2093. 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"));
  2094. 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?
  2095. 3:
  2096. 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")));
  2097. 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));
  2098. }
  2099. }
  2100. // Optional item
  2101. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2102. {
  2103. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2104. }
  2105. else
  2106. {
  2107. sprintf((char*)txProfile.ValidFrom, " ");
  2108. }
  2109. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2110. {
  2111. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2112. }
  2113. else
  2114. {
  2115. sprintf((char*)txProfile.ValidTo, " ");
  2116. }
  2117. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2118. {
  2119. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2120. }
  2121. else
  2122. {
  2123. sprintf((char*)txProfile.RecurrencyKind, " ");
  2124. }
  2125. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2126. {
  2127. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2128. }
  2129. else
  2130. {
  2131. txProfile.TransactionId = -1;
  2132. }
  2133. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2134. {
  2135. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2136. }
  2137. else
  2138. {
  2139. txProfile.ChargingSchedule.Duration = 86400;
  2140. }
  2141. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2142. {
  2143. 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")));
  2144. }
  2145. else
  2146. {
  2147. 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));
  2148. }
  2149. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2150. {
  2151. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2152. }
  2153. else
  2154. {
  2155. txProfile.ChargingSchedule.MinChargingRate = -1;
  2156. }
  2157. }
  2158. }
  2159. }
  2160. else
  2161. {
  2162. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2163. {
  2164. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2165. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2166. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2167. }
  2168. txProfile.ChargingProfileId = -1;
  2169. txProfile.StackLevel = -1;
  2170. if(txProfile.ChargingProfileId == -1)
  2171. DEBUG_INFO("TxProfile found.\n");
  2172. else
  2173. DEBUG_INFO("TxProfile updated.\n");
  2174. // Required item
  2175. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2176. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2177. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2178. if(isUnitA)
  2179. {
  2180. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2181. 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++)
  2182. {
  2183. 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"));
  2184. 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?
  2185. 3:
  2186. 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")));
  2187. 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")));
  2188. }
  2189. }
  2190. else
  2191. {
  2192. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2193. 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++)
  2194. {
  2195. 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"));
  2196. 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?
  2197. 3:
  2198. 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")));
  2199. 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));
  2200. }
  2201. }
  2202. // Optional item
  2203. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2204. {
  2205. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2206. }
  2207. else
  2208. {
  2209. sprintf((char*)txProfile.ValidFrom, " ");
  2210. }
  2211. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2212. {
  2213. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2214. }
  2215. else
  2216. {
  2217. sprintf((char*)txProfile.ValidTo, " ");
  2218. }
  2219. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2220. {
  2221. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2222. }
  2223. else
  2224. {
  2225. sprintf((char*)txProfile.RecurrencyKind, " ");
  2226. }
  2227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2228. {
  2229. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2230. }
  2231. else
  2232. {
  2233. txProfile.TransactionId = -1;
  2234. }
  2235. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2236. {
  2237. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2238. }
  2239. else
  2240. {
  2241. txProfile.ChargingSchedule.Duration = 86400;
  2242. }
  2243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2244. {
  2245. 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")));
  2246. }
  2247. else
  2248. {
  2249. 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));
  2250. }
  2251. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2252. {
  2253. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2254. }
  2255. else
  2256. {
  2257. txProfile.ChargingSchedule.MinChargingRate = -1;
  2258. }
  2259. }
  2260. }
  2261. }
  2262. json_object_put(obj);
  2263. }
  2264. fclose(fp);
  2265. /*
  2266. if(txProfile.ChargingProfileId != -1)
  2267. {
  2268. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2269. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2270. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2271. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2272. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2273. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2274. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2275. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2276. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2277. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2278. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2279. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2280. {
  2281. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2282. {
  2283. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2284. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2285. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2286. }
  2287. }
  2288. }
  2289. else
  2290. DEBUG_INFO("TxProfile not found.\n");*/
  2291. }
  2292. // Search default tx profile
  2293. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2294. if((access(profileFileName, F_OK))==-1)
  2295. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2296. if((access(profileFileName, F_OK))!=-1)
  2297. {
  2298. fp = fopen(profileFileName, "r");
  2299. while(getline(&line, &len, fp) != -1)
  2300. {
  2301. json_object *obj = NULL;
  2302. obj = json_tokener_parse(line);
  2303. if(is_error(obj))
  2304. {
  2305. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2306. }
  2307. else
  2308. {
  2309. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2310. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2311. )
  2312. {
  2313. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2314. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2315. )
  2316. {
  2317. struct tm tmFrom, tmTo;
  2318. struct timeb tbFrom, tbTo;
  2319. 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) &&
  2320. (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))
  2321. {
  2322. tmFrom.tm_year -= 1900;
  2323. tmFrom.tm_mon -= 1;
  2324. tbFrom.time = mktime(&tmFrom);
  2325. tmTo.tm_year -= 1900;
  2326. tmTo.tm_mon -= 1;
  2327. tbTo.time = mktime(&tmTo);
  2328. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2329. {
  2330. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2331. {
  2332. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2333. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2334. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2335. }
  2336. defaultTxProfile.ChargingProfileId = -1;
  2337. defaultTxProfile.StackLevel = -1;
  2338. if(defaultTxProfile.ChargingProfileId == -1)
  2339. DEBUG_INFO("TxDefaultProfile found.\n");
  2340. else
  2341. DEBUG_INFO("TxDefaultProfile updated.\n");
  2342. // Required item
  2343. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2344. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2345. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2346. if(isUnitA)
  2347. {
  2348. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2349. 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++)
  2350. {
  2351. 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"));
  2352. 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?
  2353. 3:
  2354. 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")));
  2355. 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")));
  2356. }
  2357. }
  2358. else
  2359. {
  2360. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2361. 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++)
  2362. {
  2363. 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"));
  2364. 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?
  2365. 3:
  2366. 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")));
  2367. 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));
  2368. }
  2369. }
  2370. // Optional item
  2371. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2372. {
  2373. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2374. }
  2375. else
  2376. {
  2377. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2378. }
  2379. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2380. {
  2381. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2382. }
  2383. else
  2384. {
  2385. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2386. }
  2387. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2388. {
  2389. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2390. }
  2391. else
  2392. {
  2393. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2394. }
  2395. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2396. {
  2397. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2398. }
  2399. else
  2400. {
  2401. defaultTxProfile.TransactionId = -1;
  2402. }
  2403. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2404. {
  2405. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2406. }
  2407. else
  2408. {
  2409. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2410. }
  2411. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2412. {
  2413. 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")));
  2414. }
  2415. else
  2416. {
  2417. 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));
  2418. }
  2419. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2420. {
  2421. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2422. }
  2423. else
  2424. {
  2425. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2426. }
  2427. }
  2428. }
  2429. }
  2430. else
  2431. {
  2432. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2433. {
  2434. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2435. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2436. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2437. }
  2438. defaultTxProfile.ChargingProfileId = -1;
  2439. defaultTxProfile.StackLevel = -1;
  2440. if(defaultTxProfile.ChargingProfileId == -1)
  2441. DEBUG_INFO("TxDefaultProfile found.\n");
  2442. else
  2443. DEBUG_INFO("TxDefaultProfile updated.\n");
  2444. // Required item
  2445. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2446. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2447. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2448. if(isUnitA)
  2449. {
  2450. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2451. 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++)
  2452. {
  2453. 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"));
  2454. 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?
  2455. 3:
  2456. 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")));
  2457. 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")));
  2458. }
  2459. }
  2460. else
  2461. {
  2462. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2463. 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++)
  2464. {
  2465. 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"));
  2466. 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?
  2467. 3:
  2468. 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")));
  2469. 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));
  2470. }
  2471. }
  2472. // Optional item
  2473. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2474. {
  2475. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2476. }
  2477. else
  2478. {
  2479. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2480. }
  2481. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2482. {
  2483. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2484. }
  2485. else
  2486. {
  2487. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2488. }
  2489. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2490. {
  2491. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2492. }
  2493. else
  2494. {
  2495. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2496. }
  2497. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2498. {
  2499. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2500. }
  2501. else
  2502. {
  2503. defaultTxProfile.TransactionId = -1;
  2504. }
  2505. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2506. {
  2507. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2508. }
  2509. else
  2510. {
  2511. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2512. }
  2513. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2514. {
  2515. 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")));
  2516. }
  2517. else
  2518. {
  2519. 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));
  2520. }
  2521. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2522. {
  2523. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2524. }
  2525. else
  2526. {
  2527. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2528. }
  2529. }
  2530. }
  2531. }
  2532. json_object_put(obj);
  2533. }
  2534. fclose(fp);
  2535. /*
  2536. if(defaultTxProfile.ChargingProfileId != -1)
  2537. {
  2538. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2539. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2540. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2541. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2542. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2543. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2544. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2545. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2546. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2547. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2548. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2549. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2550. {
  2551. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2552. {
  2553. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2554. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2555. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2556. }
  2557. }
  2558. }
  2559. else
  2560. DEBUG_INFO("TxDefaultProfile not found.\n");
  2561. DEBUG_INFO("------------------------------------\n");*/
  2562. }
  2563. // Search max profile
  2564. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2565. if((access(profileFileName, F_OK))!=-1)
  2566. {
  2567. fp = fopen(profileFileName, "r");
  2568. while(getline(&line, &len, fp) != -1)
  2569. {
  2570. json_object *obj = NULL;
  2571. obj = json_tokener_parse(line);
  2572. if(is_error(obj))
  2573. {
  2574. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2575. }
  2576. else
  2577. {
  2578. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2579. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2580. )
  2581. {
  2582. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2583. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2584. )
  2585. {
  2586. struct tm tmFrom, tmTo;
  2587. struct timeb tbFrom, tbTo;
  2588. 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) &&
  2589. (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))
  2590. {
  2591. tmFrom.tm_year -= 1900;
  2592. tmFrom.tm_mon -= 1;
  2593. tbFrom.time = mktime(&tmFrom);
  2594. tmTo.tm_year -= 1900;
  2595. tmTo.tm_mon -= 1;
  2596. tbTo.time = mktime(&tmTo);
  2597. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2598. {
  2599. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2600. {
  2601. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2602. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2604. }
  2605. maxProfile.ChargingProfileId = -1;
  2606. maxProfile.StackLevel = -1;
  2607. if(maxProfile.ChargingProfileId == -1)
  2608. DEBUG_INFO("MaxProfile found.\n");
  2609. else
  2610. DEBUG_INFO("MaxProfile updated.\n");
  2611. // Required item
  2612. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2613. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2614. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2615. if(isUnitA)
  2616. {
  2617. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2618. 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++)
  2619. {
  2620. 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"));
  2621. 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?
  2622. 3:
  2623. 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")));
  2624. 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")));
  2625. }
  2626. }
  2627. else
  2628. {
  2629. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2630. 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++)
  2631. {
  2632. 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"));
  2633. 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?
  2634. 3:
  2635. 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")));
  2636. 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));
  2637. }
  2638. }
  2639. // Optional item
  2640. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2641. {
  2642. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2643. }
  2644. else
  2645. {
  2646. sprintf((char*)maxProfile.ValidFrom, " ");
  2647. }
  2648. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2649. {
  2650. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2651. }
  2652. else
  2653. {
  2654. sprintf((char*)maxProfile.ValidTo, " ");
  2655. }
  2656. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2657. {
  2658. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2659. }
  2660. else
  2661. {
  2662. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2663. }
  2664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2665. {
  2666. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2667. }
  2668. else
  2669. {
  2670. maxProfile.TransactionId = -1;
  2671. }
  2672. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2673. {
  2674. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2675. }
  2676. else
  2677. {
  2678. maxProfile.ChargingSchedule.Duration = 86400;
  2679. }
  2680. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2681. {
  2682. 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")));
  2683. }
  2684. else
  2685. {
  2686. 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));
  2687. }
  2688. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2689. {
  2690. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2691. }
  2692. else
  2693. {
  2694. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2695. }
  2696. }
  2697. }
  2698. }
  2699. else
  2700. {
  2701. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2702. {
  2703. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2704. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2705. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2706. }
  2707. maxProfile.ChargingProfileId = -1;
  2708. maxProfile.StackLevel = -1;
  2709. if(maxProfile.ChargingProfileId == -1)
  2710. DEBUG_INFO("MaxProfile found.\n");
  2711. else
  2712. DEBUG_INFO("MaxProfile updated.\n");
  2713. // Required item
  2714. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2715. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2716. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2717. if(isUnitA)
  2718. {
  2719. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2720. 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++)
  2721. {
  2722. 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"));
  2723. 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?
  2724. 3:
  2725. 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")));
  2726. 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")));
  2727. }
  2728. }
  2729. else
  2730. {
  2731. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2732. 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++)
  2733. {
  2734. 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"));
  2735. 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?
  2736. 3:
  2737. 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")));
  2738. 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));
  2739. }
  2740. }
  2741. // Optional item
  2742. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2743. {
  2744. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2745. }
  2746. else
  2747. {
  2748. sprintf((char*)maxProfile.ValidFrom, " ");
  2749. }
  2750. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2751. {
  2752. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2753. }
  2754. else
  2755. {
  2756. sprintf((char*)maxProfile.ValidTo, " ");
  2757. }
  2758. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2759. {
  2760. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2761. }
  2762. else
  2763. {
  2764. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2765. }
  2766. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2767. {
  2768. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2769. }
  2770. else
  2771. {
  2772. maxProfile.TransactionId = -1;
  2773. }
  2774. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2775. {
  2776. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2777. }
  2778. else
  2779. {
  2780. maxProfile.ChargingSchedule.Duration = 86400;
  2781. }
  2782. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2783. {
  2784. 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")));
  2785. }
  2786. else
  2787. {
  2788. 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));
  2789. }
  2790. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2791. {
  2792. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2793. }
  2794. else
  2795. {
  2796. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2797. }
  2798. }
  2799. }
  2800. }
  2801. json_object_put(obj);
  2802. }
  2803. fclose(fp);
  2804. /*
  2805. if(maxProfile.ChargingProfileId !=-1)
  2806. {
  2807. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2808. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2809. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2810. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2811. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2812. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2813. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2814. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2815. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2816. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2817. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2818. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2819. {
  2820. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2821. {
  2822. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2823. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2824. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2825. }
  2826. }
  2827. }
  2828. else
  2829. DEBUG_INFO("MaxProfile not found.\n");
  2830. DEBUG_INFO("------------------------------------\n");*/
  2831. }
  2832. /*
  2833. * Align found profile start schedule & periods
  2834. */
  2835. //DEBUG_INFO("====================================\n");
  2836. /*
  2837. // For local test usage, force modify found profile start schedule info
  2838. 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);
  2839. 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);
  2840. 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);
  2841. */
  2842. if(txProfile.ChargingProfileId != -1)
  2843. {
  2844. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2845. {
  2846. if(txProfile.ChargingSchedule.Duration != -1)
  2847. {
  2848. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2849. 0:
  2850. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2851. }
  2852. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2853. {
  2854. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2855. {
  2856. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2857. 0:
  2858. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2859. if(idxPeriod > 0)
  2860. {
  2861. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2862. {
  2863. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2864. }
  2865. }
  2866. }
  2867. }
  2868. }
  2869. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2870. {
  2871. if(txProfile.ChargingSchedule.Duration != -1)
  2872. {
  2873. 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?
  2874. 0:
  2875. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2876. }
  2877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2878. {
  2879. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2880. {
  2881. 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?
  2882. 0:
  2883. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2884. if(idxPeriod > 0)
  2885. {
  2886. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2887. {
  2888. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2889. }
  2890. }
  2891. }
  2892. }
  2893. }
  2894. else
  2895. {
  2896. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2897. {
  2898. if(txProfile.ChargingSchedule.Duration != -1)
  2899. {
  2900. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2901. 0:
  2902. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2903. }
  2904. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2905. {
  2906. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2907. {
  2908. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2909. 0:
  2910. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2911. if(idxPeriod > 0)
  2912. {
  2913. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2914. {
  2915. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2916. }
  2917. }
  2918. }
  2919. }
  2920. }
  2921. else
  2922. {
  2923. if(txProfile.ChargingSchedule.Duration != -1)
  2924. {
  2925. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2926. 0:
  2927. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2928. }
  2929. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2930. {
  2931. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2932. {
  2933. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2934. 0:
  2935. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2936. if(idxPeriod > 0)
  2937. {
  2938. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2939. {
  2940. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2941. }
  2942. }
  2943. }
  2944. }
  2945. }
  2946. }
  2947. /*
  2948. DEBUG_INFO("txProfile after align.\n");
  2949. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2950. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2951. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2952. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2953. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2954. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2955. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2956. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2957. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2958. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2959. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2960. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2961. {
  2962. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2963. {
  2964. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2965. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2966. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2967. }
  2968. }*/
  2969. }
  2970. if(defaultTxProfile.ChargingProfileId != -1)
  2971. {
  2972. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2973. {
  2974. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2975. {
  2976. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2977. 0:
  2978. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2979. }
  2980. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2981. {
  2982. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2983. {
  2984. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2985. 0:
  2986. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2987. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2988. {
  2989. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2990. }
  2991. if(idxPeriod > 0)
  2992. {
  2993. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2994. {
  2995. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2996. }
  2997. }
  2998. }
  2999. }
  3000. }
  3001. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3002. {
  3003. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3004. {
  3005. 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?
  3006. 0:
  3007. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3008. }
  3009. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3010. {
  3011. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3012. {
  3013. 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?
  3014. 0:
  3015. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3016. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3017. {
  3018. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3019. }
  3020. if(idxPeriod > 0)
  3021. {
  3022. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3023. {
  3024. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3025. }
  3026. }
  3027. }
  3028. }
  3029. }
  3030. else
  3031. {
  3032. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3033. {
  3034. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3035. {
  3036. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3037. 0:
  3038. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3039. }
  3040. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3041. {
  3042. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3043. {
  3044. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3045. 0:
  3046. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3047. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3048. {
  3049. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3050. }
  3051. if(idxPeriod > 0)
  3052. {
  3053. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3054. {
  3055. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3056. }
  3057. }
  3058. }
  3059. }
  3060. }
  3061. else
  3062. {
  3063. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3064. {
  3065. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3066. 0:
  3067. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3068. }
  3069. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3070. {
  3071. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3072. {
  3073. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3074. 0:
  3075. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3076. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  3077. {
  3078. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3079. }
  3080. if(idxPeriod > 0)
  3081. {
  3082. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3083. {
  3084. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3085. }
  3086. }
  3087. }
  3088. }
  3089. }
  3090. }
  3091. /*
  3092. DEBUG_INFO("defaultTxProfile after align.\n");
  3093. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3094. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3095. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3096. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3097. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3098. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3099. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3100. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3101. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3102. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3103. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3104. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3105. {
  3106. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3107. {
  3108. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3109. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3110. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3111. }
  3112. }
  3113. DEBUG_INFO("------------------------------------\n");*/
  3114. }
  3115. if(maxProfile.ChargingProfileId != -1)
  3116. {
  3117. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3118. {
  3119. if(maxProfile.ChargingSchedule.Duration != -1)
  3120. {
  3121. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3122. 0:
  3123. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3124. }
  3125. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3126. {
  3127. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3128. {
  3129. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3130. 0:
  3131. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3132. if(idxPeriod > 0)
  3133. {
  3134. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3135. {
  3136. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3137. }
  3138. }
  3139. }
  3140. }
  3141. }
  3142. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3143. {
  3144. if(maxProfile.ChargingSchedule.Duration != -1)
  3145. {
  3146. 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?
  3147. 0:
  3148. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3149. }
  3150. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3151. {
  3152. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3153. {
  3154. 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?
  3155. 0:
  3156. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3157. if(idxPeriod > 0)
  3158. {
  3159. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3160. {
  3161. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3162. }
  3163. }
  3164. }
  3165. }
  3166. }
  3167. else
  3168. {
  3169. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3170. {
  3171. if(maxProfile.ChargingSchedule.Duration != -1)
  3172. {
  3173. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3174. 0:
  3175. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3176. }
  3177. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3178. {
  3179. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3180. {
  3181. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3182. 0:
  3183. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3184. if(idxPeriod > 0)
  3185. {
  3186. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3187. {
  3188. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3189. }
  3190. }
  3191. }
  3192. }
  3193. }
  3194. else
  3195. {
  3196. if(maxProfile.ChargingSchedule.Duration != -1)
  3197. {
  3198. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3199. 0:
  3200. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3201. }
  3202. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3203. {
  3204. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3205. {
  3206. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3207. 0:
  3208. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3209. if(idxPeriod > 0)
  3210. {
  3211. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3212. {
  3213. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3214. }
  3215. }
  3216. }
  3217. }
  3218. }
  3219. }
  3220. /*
  3221. DEBUG_INFO("MaxProfile after align.\n");
  3222. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3223. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3224. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3225. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3226. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3227. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3228. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3229. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3230. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3231. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3232. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3233. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3234. {
  3235. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3236. {
  3237. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3238. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3239. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3240. }
  3241. }
  3242. DEBUG_INFO("------------------------------------\n");*/
  3243. }
  3244. /*
  3245. * Merge to conposite schedule
  3246. */
  3247. //DEBUG_INFO("====================================\n");
  3248. // Find each profile period quantity
  3249. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3250. {
  3251. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3252. limitMax = idx+1;
  3253. }
  3254. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3255. {
  3256. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3257. limitDef = idx+1;
  3258. }
  3259. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3260. {
  3261. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3262. limitTx = idx+1;
  3263. }
  3264. // TxProfile found, composite schedule based on it
  3265. if(txProfile.ChargingProfileId != -1)
  3266. {
  3267. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3268. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3269. {
  3270. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3271. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3272. (txProfile.ChargingSchedule.Duration > 0))
  3273. {
  3274. if(maxProfile.ChargingProfileId != -1)
  3275. {
  3276. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3277. {
  3278. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3279. {
  3280. if((maxProfile.ChargingSchedule.Duration > 0))
  3281. {
  3282. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3283. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3284. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3285. }
  3286. else
  3287. {
  3288. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3289. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3290. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3291. }
  3292. }
  3293. if(idxMaxPeriod == (limitMax-1))
  3294. {
  3295. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3296. {
  3297. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3298. {
  3299. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3300. compositePeriodIdx++;
  3301. }
  3302. else
  3303. {
  3304. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3305. }
  3306. }
  3307. }
  3308. }
  3309. }
  3310. else
  3311. {
  3312. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3313. {
  3314. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3315. compositePeriodIdx++;
  3316. }
  3317. else
  3318. {
  3319. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3320. }
  3321. }
  3322. }
  3323. if(idxTxPeriod == (limitTx-1))
  3324. {
  3325. if(defaultTxProfile.ChargingProfileId != -1)
  3326. {
  3327. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3328. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3329. {
  3330. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3331. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3332. (defaultTxProfile.ChargingSchedule.Duration>0))
  3333. {
  3334. if(maxProfile.ChargingProfileId != -1)
  3335. {
  3336. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3337. {
  3338. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3339. {
  3340. if((maxProfile.ChargingSchedule.Duration > 0))
  3341. {
  3342. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3343. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3344. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3345. }
  3346. else
  3347. {
  3348. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3349. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3350. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3351. }
  3352. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3353. {
  3354. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3355. {
  3356. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3357. compositePeriodIdx++;
  3358. }
  3359. else
  3360. {
  3361. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3362. }
  3363. }
  3364. // Delete duplicate period
  3365. if(compositePeriodIdx > 1)
  3366. {
  3367. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3368. {
  3369. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3370. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3371. compositePeriodIdx -= 1;
  3372. }
  3373. }
  3374. }
  3375. else
  3376. {
  3377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3378. {
  3379. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3380. compositePeriodIdx++;
  3381. }
  3382. else
  3383. {
  3384. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3385. }
  3386. break;
  3387. }
  3388. }
  3389. }
  3390. else
  3391. {
  3392. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3393. {
  3394. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3395. compositePeriodIdx++;
  3396. }
  3397. else
  3398. {
  3399. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3400. }
  3401. }
  3402. }
  3403. }
  3404. }
  3405. }
  3406. }
  3407. }
  3408. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3409. else if(defaultTxProfile.ChargingProfileId != -1)
  3410. {
  3411. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3412. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3413. {
  3414. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3415. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3416. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3417. {
  3418. if(maxProfile.ChargingProfileId != -1)
  3419. {
  3420. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3421. {
  3422. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3423. {
  3424. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3425. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3426. if((maxProfile.ChargingSchedule.Duration > 0))
  3427. {
  3428. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3429. }
  3430. else
  3431. {
  3432. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3433. }
  3434. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3435. {
  3436. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3437. {
  3438. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3439. compositePeriodIdx++;
  3440. }
  3441. else
  3442. {
  3443. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3444. }
  3445. }
  3446. // Delete duplicate period
  3447. if(compositePeriodIdx > 1)
  3448. {
  3449. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3450. {
  3451. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3452. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3453. compositePeriodIdx -= 1;
  3454. }
  3455. }
  3456. }
  3457. else
  3458. {
  3459. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3460. {
  3461. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3462. compositePeriodIdx++;
  3463. }
  3464. else
  3465. {
  3466. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3467. }
  3468. break;
  3469. }
  3470. }
  3471. }
  3472. else
  3473. {
  3474. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3475. {
  3476. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3477. compositePeriodIdx++;
  3478. }
  3479. else
  3480. {
  3481. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3482. }
  3483. }
  3484. }
  3485. }
  3486. }
  3487. // Fill other period by MaxProfile
  3488. if(maxProfile.ChargingProfileId != -1)
  3489. {
  3490. if(compositePeriodIdx==0)
  3491. {
  3492. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3493. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3494. {
  3495. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3496. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3497. (maxProfile.ChargingSchedule.Duration > 0))
  3498. {
  3499. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3500. {
  3501. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3502. compositePeriodIdx++;
  3503. }
  3504. else
  3505. {
  3506. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3507. }
  3508. }
  3509. }
  3510. }
  3511. else
  3512. {
  3513. int lastCompositePeriodIdx = compositePeriodIdx;
  3514. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3515. {
  3516. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3517. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3518. (maxProfile.ChargingSchedule.Duration > 0))
  3519. {
  3520. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3521. {
  3522. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3523. {
  3524. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3525. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3526. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3527. }
  3528. else
  3529. {
  3530. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3531. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3532. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3533. }
  3534. }
  3535. if(tmpPeriod.Limit != -1)
  3536. {
  3537. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3538. {
  3539. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3540. {
  3541. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3542. compositePeriodIdx++;
  3543. }
  3544. else
  3545. {
  3546. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3547. }
  3548. }
  3549. // Delete duplicate period
  3550. if(compositePeriodIdx > 1)
  3551. {
  3552. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3553. {
  3554. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3555. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3556. compositePeriodIdx -= 1;
  3557. }
  3558. }
  3559. }
  3560. }
  3561. }
  3562. }
  3563. }
  3564. compositeProfile.ChargingSchedule.Duration = durationReq;
  3565. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3566. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3567. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3568. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3569. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3570. {
  3571. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3572. {
  3573. compositeProfile.ChargingProfileId = 1;
  3574. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3575. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3576. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3577. }
  3578. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3579. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3580. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3581. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3582. }
  3583. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3584. if(line)
  3585. free(line);
  3586. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3587. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3588. }
  3589. //==========================================
  3590. // Init all share memory
  3591. //==========================================
  3592. int InitShareMemory()
  3593. {
  3594. int result = PASS;
  3595. int MeterSMId;
  3596. //creat ShmSysConfigAndInfo
  3597. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3598. {
  3599. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3600. result = FAIL;
  3601. }
  3602. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3603. {
  3604. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3605. result = FAIL;
  3606. }
  3607. else
  3608. {}
  3609. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3610. {
  3611. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3612. result = FAIL;
  3613. }
  3614. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3615. {
  3616. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3617. result = FAIL;
  3618. }
  3619. else
  3620. {}
  3621. //creat ShmPsuData
  3622. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3623. {
  3624. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3625. result = FAIL;
  3626. }
  3627. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3628. {
  3629. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3630. result = FAIL;
  3631. }
  3632. else
  3633. {}
  3634. //creat ShmOCPP16Data
  3635. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3636. {
  3637. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3638. result = FAIL;
  3639. }
  3640. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3641. {
  3642. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3643. result = FAIL;
  3644. }
  3645. else
  3646. {}
  3647. /****************************** For Initial Settings************************************************/
  3648. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3649. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3650. // allocate Configuration memory address
  3651. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3652. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3653. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3654. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3655. //offline MeterValue Interval
  3656. TempMeterValueInterval = 0;
  3657. return result;
  3658. }
  3659. int ProcessShareMemory()
  3660. {
  3661. int result = PASS;
  3662. if(InitShareMemory() == FAIL)
  3663. {
  3664. DEBUG_ERROR("InitShareMemory NG\n");
  3665. if(ShmStatusCodeData!=NULL)
  3666. {
  3667. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3668. }
  3669. result = FAIL;
  3670. }
  3671. // Model name parsing
  3672. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3673. {
  3674. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3675. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3676. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3677. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3678. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3679. ) // 'D' means DC
  3680. {
  3681. // DO series
  3682. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3683. {
  3684. SystemInitial += 1;
  3685. gunTotalNumber += 1;
  3686. gunType[gun_index] = GUN_TYPE_DO;
  3687. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3688. {
  3689. case Gun_Type_Chademo:
  3690. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3691. break;
  3692. case Gun_Type_CCS_2:
  3693. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3694. break;
  3695. case Gun_Type_GB:
  3696. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3697. break;
  3698. case Gun_Type_AC:
  3699. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3700. break;
  3701. default:
  3702. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3703. break;
  3704. }
  3705. }
  3706. }
  3707. else
  3708. {
  3709. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3710. {
  3711. SystemInitial += 1;
  3712. gunTotalNumber += 1;
  3713. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3714. {
  3715. case Gun_Type_Chademo:
  3716. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3717. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3718. break;
  3719. case Gun_Type_CCS_2:
  3720. gunType[gun_index] = GUN_TYPE_CCS;
  3721. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3722. break;
  3723. case Gun_Type_GB:
  3724. gunType[gun_index] = GUN_TYPE_GBT;
  3725. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3726. break;
  3727. case Gun_Type_AC:
  3728. gunType[gun_index] = GUN_TYPE_AC;
  3729. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3730. break;
  3731. default:
  3732. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3733. break;
  3734. }
  3735. }
  3736. }
  3737. }
  3738. else
  3739. {
  3740. DEBUG_ERROR("Model name parsing fail.\n");
  3741. result = FAIL;
  3742. }
  3743. if(result != PASS)sleep(5);
  3744. return result;
  3745. }
  3746. void checkRemoteStart(uint8_t connectorIdInt)
  3747. {
  3748. uint8_t tempIndex;
  3749. int result = PASS;
  3750. char cmdBuf[512];
  3751. //check Transaction active
  3752. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3753. {
  3754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3755. {
  3756. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3757. }
  3758. else
  3759. {
  3760. tempIndex = connectorIdInt -1;
  3761. }
  3762. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3763. {
  3764. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3765. {
  3766. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3767. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3768. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3769. {
  3770. //Reserved
  3771. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3772. }
  3773. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3774. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3775. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3776. {
  3777. //Reserved
  3778. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3779. result = FAIL;
  3780. goto end;
  3781. }
  3782. else
  3783. {
  3784. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3785. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3786. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3787. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3788. {
  3789. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3790. result = FAIL;
  3791. goto end;
  3792. }
  3793. }//END FOR ELSE
  3794. }
  3795. }// END FOR CHAdeMO_QUANTITY
  3796. }
  3797. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3798. {
  3799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3800. {
  3801. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3802. }
  3803. else
  3804. {
  3805. tempIndex = connectorIdInt -1;
  3806. }
  3807. for (int index = 0; index < CCS_QUANTITY; index++)
  3808. {
  3809. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3810. {
  3811. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3812. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3813. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3814. {
  3815. //Reserved
  3816. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3817. }
  3818. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3819. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3820. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3821. {
  3822. //Reserved
  3823. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3824. result = FAIL;
  3825. goto end;
  3826. }
  3827. else
  3828. {
  3829. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3830. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3831. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3832. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3833. {
  3834. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3835. result = FAIL;
  3836. goto end;
  3837. }
  3838. }// END FOR ELSE
  3839. }
  3840. }// END FOR CCS_QUANTITY
  3841. }
  3842. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3843. {
  3844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3845. {
  3846. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3847. }
  3848. else
  3849. {
  3850. tempIndex = connectorIdInt -1;
  3851. }
  3852. for (int index = 0; index < GB_QUANTITY; index++)
  3853. {
  3854. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3855. {
  3856. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3857. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3858. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3859. {
  3860. //Reserved
  3861. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3862. }
  3863. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3864. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3865. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3866. {
  3867. //Reserved
  3868. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3869. result = FAIL;
  3870. goto end;
  3871. }
  3872. else
  3873. {
  3874. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3875. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3876. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3877. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3878. {
  3879. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3880. result = FAIL;
  3881. goto end;
  3882. }
  3883. }// END FOR ELSE
  3884. }
  3885. } // END FOR GB_QUANTITY
  3886. }
  3887. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3888. {
  3889. tempIndex = connectorIdInt -1;
  3890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3891. {
  3892. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3893. {
  3894. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3895. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3896. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3897. {
  3898. //Reserved
  3899. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3900. }
  3901. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3902. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3903. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3904. {
  3905. //Reserved
  3906. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3907. result = FAIL;
  3908. goto end;
  3909. }
  3910. else
  3911. {
  3912. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3913. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3914. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3915. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3916. {
  3917. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3918. result = FAIL;
  3919. goto end;
  3920. }
  3921. }// END FOR ELSE
  3922. }
  3923. } // END FOR GB_QUANTITY
  3924. }
  3925. else
  3926. {
  3927. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3928. {
  3929. tempIndex = 2;
  3930. }
  3931. else
  3932. {
  3933. tempIndex = connectorIdInt -1;
  3934. }
  3935. for (int index = 0; index < AC_QUANTITY; index++)
  3936. {
  3937. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3938. {
  3939. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3940. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3941. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3942. {
  3943. //Reserved
  3944. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3945. }
  3946. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3947. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3948. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3949. {
  3950. //Reserved
  3951. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3952. result = FAIL;
  3953. goto end;
  3954. }
  3955. else
  3956. {
  3957. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3958. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3959. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3960. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3961. {
  3962. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3963. result = FAIL;
  3964. goto end;
  3965. }
  3966. }//END FOR ELSE
  3967. }
  3968. }// END FOR AC_QUANTITY
  3969. }
  3970. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3971. {
  3972. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3973. {
  3974. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3975. {
  3976. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3977. system(cmdBuf);
  3978. }
  3979. }
  3980. else
  3981. {
  3982. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3983. result = FAIL;
  3984. }
  3985. }
  3986. end:
  3987. if(result == PASS)
  3988. {
  3989. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3990. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3991. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3992. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3993. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3994. }
  3995. }
  3996. void CheckSystemValue(void)
  3997. {
  3998. char filenmae[100]={0};
  3999. char str[100]={0};
  4000. int tempIndex = 0;
  4001. //===============================
  4002. // send Heartbeat
  4003. //===============================
  4004. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4005. {
  4006. //parameter for test
  4007. sendHeartbeatRequest(0);
  4008. //===========================
  4009. // Reset Waiting Time
  4010. //===========================
  4011. HeartBeatWithNOResponse += 1;
  4012. }
  4013. //===============================
  4014. // Credit deduct report
  4015. //===============================
  4016. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4017. {
  4018. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4019. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4020. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4021. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4022. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4023. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4024. }
  4025. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4026. {
  4027. OCPP_query_deduct_info();
  4028. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4029. }
  4030. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4031. {
  4032. // ClockAlign MeterValue
  4033. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4034. {
  4035. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4036. {
  4037. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4038. {
  4039. tempIndex = ((gun_index==2) ? 1: 0);
  4040. }
  4041. else
  4042. {
  4043. tempIndex = gun_index;
  4044. }
  4045. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4046. {
  4047. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4048. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4049. {
  4050. reqClockAlignMeter[gun_index] = 1;
  4051. }
  4052. }// End for CHAdeMO
  4053. }
  4054. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4055. {
  4056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4057. {
  4058. tempIndex = ((gun_index==2) ? 1: 0);
  4059. }
  4060. else
  4061. {
  4062. tempIndex = gun_index;
  4063. }
  4064. for (int index = 0; index < CCS_QUANTITY; index++)
  4065. {
  4066. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4067. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4068. {
  4069. reqClockAlignMeter[gun_index] = 1;
  4070. }
  4071. } // End for CCS
  4072. }
  4073. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4074. {
  4075. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4076. {
  4077. tempIndex = ((gun_index==2) ? 1: 0);
  4078. }
  4079. else
  4080. {
  4081. tempIndex = gun_index;
  4082. }
  4083. for (int index = 0; index < GB_QUANTITY; index++)
  4084. {
  4085. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4086. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4087. {
  4088. reqClockAlignMeter[gun_index] = 1;
  4089. }
  4090. }// End for GB
  4091. }
  4092. else if(gunType[gun_index] == GUN_TYPE_DO)
  4093. {
  4094. tempIndex = gun_index;
  4095. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4096. {
  4097. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4098. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4099. {
  4100. reqClockAlignMeter[gun_index] = 1;
  4101. }
  4102. }
  4103. }
  4104. else
  4105. {
  4106. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4107. {
  4108. tempIndex = 2;
  4109. }
  4110. else
  4111. {
  4112. tempIndex = gun_index;
  4113. }
  4114. for (int index = 0; index < AC_QUANTITY; index++)
  4115. {
  4116. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4117. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4118. {
  4119. reqClockAlignMeter[gun_index] = 1;
  4120. }
  4121. }//End for AC
  4122. }
  4123. }
  4124. }
  4125. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4126. {
  4127. //==========================================
  4128. // Check remote start without connector id
  4129. //==========================================
  4130. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4131. {
  4132. int connectorIdInt = -1;
  4133. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4134. {
  4135. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4136. {
  4137. connectorIdInt = (gun_index+1);
  4138. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4139. checkRemoteStart(connectorIdInt);
  4140. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4141. break;
  4142. }
  4143. }
  4144. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4145. {
  4146. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4147. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4148. }
  4149. }
  4150. //==========================================
  4151. // csu trigger DataTransferReq
  4152. //==========================================
  4153. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4154. {
  4155. sendDataTransferRequest(gun_index);
  4156. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4157. }
  4158. //==========================================
  4159. // CSU Trigger Authorize Request
  4160. //==========================================
  4161. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4162. {
  4163. sendAuthorizeRequest(0);
  4164. authorizeRetryTimes = authorizeRetryTimes + 1;
  4165. if(authorizeRetryTimes < 3)
  4166. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4167. }
  4168. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4169. {
  4170. authorizeRetryTimes = 0;
  4171. SetOcppConnStatus(FALSE);
  4172. server_sign = FALSE;
  4173. }
  4174. 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))
  4175. {
  4176. sendAuthorizeRequest(0);
  4177. }
  4178. //==========================================
  4179. // Charger start transaction
  4180. //==========================================
  4181. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4182. {
  4183. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4184. sendStartTransactionRequest(gun_index);
  4185. refreshStartTimer(&clientTime.StartTransaction);
  4186. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4187. storeTempStopTransaction(gun_index);
  4188. }
  4189. //==========================================
  4190. // Charger stop transaction
  4191. //==========================================
  4192. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4193. {
  4194. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4195. sendStopTransactionRequest(gun_index);
  4196. OCPP_updatePeriodEnergy(gun_index);
  4197. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4198. refreshStartTimer(&clientTime.StopTransaction);
  4199. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4200. }
  4201. //==========================================
  4202. // Charger status report
  4203. //==========================================
  4204. //--- Check Mode Change ---//
  4205. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4206. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4207. {
  4208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4209. {
  4210. tempIndex = ((gun_index==2) ? 1: 0);
  4211. }
  4212. else
  4213. {
  4214. tempIndex = gun_index;
  4215. }
  4216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4217. {
  4218. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4219. {
  4220. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4221. {
  4222. // Sent unplug message for California pricing logic
  4223. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4224. {
  4225. uint8_t ts[20];
  4226. getNowDatetime(ts);
  4227. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4228. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4229. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4230. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4231. }
  4232. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4233. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4234. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4235. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4236. {
  4237. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4238. if((access(filenmae,F_OK))!=-1)
  4239. {
  4240. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4241. sprintf(str,"rm -f %s",filenmae);
  4242. system(str);
  4243. }
  4244. }
  4245. }
  4246. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4247. #if 1 // for TempStopTransaction
  4248. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4249. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4250. {
  4251. checkTempStopTransaction(gun_index);
  4252. }
  4253. #endif
  4254. }
  4255. }
  4256. }
  4257. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4258. {
  4259. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4260. {
  4261. tempIndex = ((gun_index==2) ? 1: 0);
  4262. }
  4263. else
  4264. {
  4265. tempIndex = gun_index;
  4266. }
  4267. for (int index = 0; index < CCS_QUANTITY; index++)
  4268. {
  4269. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4270. {
  4271. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  4272. {
  4273. // Sent unplug message for California pricing logic
  4274. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4275. {
  4276. uint8_t ts[20];
  4277. getNowDatetime(ts);
  4278. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4279. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4280. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4281. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4282. }
  4283. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4284. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4285. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4286. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4287. {
  4288. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4289. if((access(filenmae,F_OK))!=-1)
  4290. {
  4291. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4292. sprintf(str,"rm -f %s",filenmae);
  4293. system(str);
  4294. }
  4295. }
  4296. }
  4297. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4298. #if 1 // for TempStopTransaction
  4299. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4300. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4301. {
  4302. checkTempStopTransaction(gun_index);
  4303. }
  4304. #endif
  4305. }
  4306. }
  4307. }
  4308. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4309. {
  4310. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4311. {
  4312. tempIndex = ((gun_index==2) ? 1: 0);
  4313. }
  4314. else
  4315. {
  4316. tempIndex = gun_index;
  4317. }
  4318. for (int index = 0; index < GB_QUANTITY; index++)
  4319. {
  4320. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4321. {
  4322. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4323. {
  4324. // Sent unplug message for California pricing logic
  4325. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4326. {
  4327. uint8_t ts[20];
  4328. getNowDatetime(ts);
  4329. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4330. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4331. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4332. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4333. }
  4334. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4335. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4336. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4337. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4338. {
  4339. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4340. if((access(filenmae,F_OK))!=-1)
  4341. {
  4342. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4343. sprintf(str,"rm -f %s",filenmae);
  4344. system(str);
  4345. }
  4346. }
  4347. }
  4348. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4349. #if 1 // for TempStopTransaction
  4350. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4351. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4352. {
  4353. checkTempStopTransaction(gun_index);
  4354. }
  4355. #endif
  4356. }
  4357. }
  4358. }
  4359. else if(gunType[gun_index] == GUN_TYPE_DO)
  4360. {
  4361. tempIndex = gun_index;
  4362. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4363. {
  4364. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4365. {
  4366. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4367. {
  4368. // Sent unplug message for California pricing logic
  4369. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4370. {
  4371. uint8_t ts[20];
  4372. getNowDatetime(ts);
  4373. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4374. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4375. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4376. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4377. }
  4378. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4379. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4380. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4381. 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
  4382. {
  4383. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4384. if((access(filenmae,F_OK))!=-1)
  4385. {
  4386. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4387. sprintf(str,"rm -f %s",filenmae);
  4388. system(str);
  4389. }
  4390. }
  4391. }
  4392. 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);
  4393. #if 1 // for TempStopTransaction
  4394. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4395. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4396. {
  4397. checkTempStopTransaction(gun_index);
  4398. }
  4399. #endif
  4400. }
  4401. }
  4402. }
  4403. else
  4404. {
  4405. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4406. {
  4407. tempIndex = 2;
  4408. }
  4409. else
  4410. {
  4411. tempIndex = gun_index;
  4412. }
  4413. for (int index = 0; index < AC_QUANTITY; index++)
  4414. {
  4415. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4416. {
  4417. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4418. {
  4419. // Sent unplug message for California pricing logic
  4420. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4421. {
  4422. uint8_t ts[20];
  4423. getNowDatetime(ts);
  4424. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4425. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4426. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4427. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4428. }
  4429. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4430. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4431. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4432. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4433. {
  4434. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4435. if((access(filenmae,F_OK))!=-1)
  4436. {
  4437. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4438. sprintf(str,"rm -f %s",filenmae);
  4439. system(str);
  4440. }
  4441. }
  4442. }
  4443. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4444. #if 1 // for TempStopTransaction
  4445. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4446. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4447. {
  4448. checkTempStopTransaction(gun_index);
  4449. }
  4450. #endif
  4451. }
  4452. }// END
  4453. }
  4454. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4455. (
  4456. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4457. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4458. )
  4459. )
  4460. {
  4461. if(SystemInitial > 0)
  4462. SystemInitial -= 1;
  4463. sendStatusNotificationRequest(gun_index);
  4464. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4465. }
  4466. //==============================================
  4467. // TCCI reader status report
  4468. //==============================================
  4469. if(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4470. {
  4471. reportReaderStatus(gun_index);
  4472. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4473. }
  4474. //==============================================
  4475. // CSU Trigger Smart Charging Profile
  4476. //==============================================
  4477. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4478. {
  4479. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4480. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4481. }
  4482. //==============================================
  4483. // Meter report
  4484. //==============================================
  4485. // Trigger MeterValue
  4486. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4487. {
  4488. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4489. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4490. }
  4491. // Clock-aligned Meter value
  4492. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4493. {
  4494. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4495. reqClockAlignMeter[gun_index] = 0;
  4496. }
  4497. // Sample period MeterValue
  4498. 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))))
  4499. {
  4500. //check Transaction active
  4501. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4502. {
  4503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4504. {
  4505. tempIndex = ((gun_index==2) ? 1: 0);
  4506. }
  4507. else
  4508. {
  4509. tempIndex = gun_index;
  4510. }
  4511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4512. {
  4513. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4514. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4515. {
  4516. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4517. {
  4518. reqSampleMeter[gun_index] = 1;
  4519. }
  4520. }
  4521. }// End for CHAdeMO
  4522. }
  4523. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  4534. {
  4535. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4536. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4537. {
  4538. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4539. {
  4540. reqSampleMeter[gun_index] = 1;
  4541. }
  4542. }
  4543. } // End for CCS
  4544. }
  4545. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4546. {
  4547. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4548. {
  4549. tempIndex = ((gun_index==2) ? 1: 0);
  4550. }
  4551. else
  4552. {
  4553. tempIndex = gun_index;
  4554. }
  4555. for (int index = 0; index < GB_QUANTITY; index++)
  4556. {
  4557. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4558. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4559. {
  4560. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4561. {
  4562. reqSampleMeter[gun_index] = 1;
  4563. }
  4564. }
  4565. }// End for GB
  4566. }
  4567. else if(gunType[gun_index] == GUN_TYPE_DO)
  4568. {
  4569. tempIndex = gun_index;
  4570. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4571. {
  4572. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4573. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4574. {
  4575. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4576. {
  4577. reqSampleMeter[gun_index] = 1;
  4578. }
  4579. }
  4580. }
  4581. }
  4582. else
  4583. {
  4584. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4585. {
  4586. tempIndex = 2;
  4587. }
  4588. else
  4589. {
  4590. tempIndex = gun_index;
  4591. }
  4592. for (int index = 0; index < AC_QUANTITY; index++)
  4593. {
  4594. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4595. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4596. {
  4597. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4598. {
  4599. reqSampleMeter[gun_index] = 1;
  4600. }
  4601. }
  4602. }//End for AC
  4603. }
  4604. if(reqSampleMeter[gun_index] == 1)
  4605. {
  4606. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4607. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4608. storeTempStopTransaction(gun_index);
  4609. reqSampleMeter[gun_index] = 0;
  4610. }
  4611. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4612. }
  4613. //==============================================
  4614. // Check Connector reserved
  4615. //==============================================
  4616. //===============================
  4617. // Check if Reserve is expired
  4618. //===============================
  4619. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4620. {
  4621. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4622. {
  4623. DEBUG_INFO("reserve expired.\n");
  4624. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4625. }
  4626. }//END OF Check if Reserve is expired
  4627. //==========================================
  4628. // csu trigger FirmwareStatusNotificationReq
  4629. //==========================================
  4630. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4631. {
  4632. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4633. }
  4634. //==========================================
  4635. // csu trigger DiagnosticsStatusNotificationReq
  4636. //==========================================
  4637. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4638. {
  4639. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4640. }
  4641. //==========================================
  4642. // csu trigger CancelReservationConf
  4643. //==========================================
  4644. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4645. {
  4646. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4647. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4648. }
  4649. //==========================================
  4650. // csu trigger ChangeAvailabilityConf
  4651. //==========================================
  4652. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4653. {
  4654. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4655. }
  4656. //==========================================
  4657. // csu trigger UnlockConnectorConf
  4658. //==========================================
  4659. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4660. {
  4661. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4662. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4663. }
  4664. //==========================================
  4665. // csu trigger ReserveNowConf
  4666. //==========================================
  4667. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4668. {
  4669. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4670. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4671. }
  4672. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4673. {
  4674. sendSignCertificateRequest();
  4675. }
  4676. }
  4677. }
  4678. //==========================================
  4679. // send request routine
  4680. //==========================================
  4681. int sendAuthorizeRequest(int gun_index)
  4682. {
  4683. mtrace();
  4684. int result = FAIL;
  4685. char message[100]={0};
  4686. char guid[37];
  4687. char tempdata[65]={0};
  4688. DEBUG_INFO("sendAuthorizeRequest...\n");
  4689. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4690. //Local Authorize
  4691. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4692. {
  4693. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4694. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4695. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4696. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4697. result = PASS;
  4698. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4699. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4700. authorizeRetryTimes = 0;
  4701. return result;
  4702. }
  4703. 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))||
  4704. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4705. {
  4706. // Query from cache
  4707. DEBUG_INFO("Authorize from cache.\n");
  4708. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4709. // Query from list
  4710. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4711. {
  4712. DEBUG_INFO("Authorize from list.\n");
  4713. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4714. }
  4715. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4716. {
  4717. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4718. {
  4719. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4720. }
  4721. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4722. {
  4723. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4724. }
  4725. if(!GetOcppConnStatus())
  4726. {
  4727. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4728. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4729. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4730. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4731. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4732. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4733. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4734. authorizeRetryTimes = 0;
  4735. return result;
  4736. }
  4737. }
  4738. else
  4739. {
  4740. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4741. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4742. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4743. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4744. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4745. else
  4746. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4747. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4748. result = PASS;
  4749. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4750. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4751. authorizeRetryTimes = 0;
  4752. return result;
  4753. }
  4754. }
  4755. //initialize struct Authorize
  4756. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4757. //get data from shared memory
  4758. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4759. random_uuid(guid);
  4760. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4761. LWS_Send(message);
  4762. sprintf(tempdata, "Authorize,%d", gun_index);
  4763. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4764. {
  4765. result = PASS;
  4766. DEBUG_INFO("Authorize mapItem pass\n");
  4767. }
  4768. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4769. return result;
  4770. }
  4771. int sendBootNotificationRequest(void)
  4772. {
  4773. mtrace();
  4774. int result = FAIL;
  4775. char message[500]={0}, payload[700]={0};
  4776. char guid[37]={0};
  4777. char tempdata[65]={0};
  4778. // Fill BootNotification fields
  4779. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4780. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4781. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4782. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4783. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4784. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4785. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4786. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4787. ShmOCPP16Data->ChargeBoxId
  4788. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4789. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4790. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4791. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4792. ,ShmOCPP16Data->BootNotification.CpIccid
  4793. ,ShmOCPP16Data->BootNotification.CpImsi);
  4794. random_uuid(guid);
  4795. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4796. LWS_Send(message);
  4797. sprintf(tempdata, "BootNotification,0");
  4798. 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*/)
  4799. {
  4800. result = PASS;
  4801. }
  4802. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4803. strcpy(queuedata,message);
  4804. return result;
  4805. }
  4806. int sendDataTransferRequest(int gun_index)
  4807. {
  4808. mtrace();
  4809. char message[1000]={0};
  4810. char guid[37]={0};
  4811. char tempdata[65]={0};
  4812. int result = FAIL;
  4813. random_uuid(guid);
  4814. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4815. MESSAGE_TYPE_CALL,
  4816. guid,
  4817. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4818. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4819. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4820. LWS_Send(message);
  4821. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4822. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4823. {
  4824. result = PASS;
  4825. DEBUG_INFO("DataTransfer mapItem pass\n");
  4826. }
  4827. return result;
  4828. }
  4829. int sendDiagnosticsStatusNotificationRequest(char *status)
  4830. {
  4831. mtrace();
  4832. int result = FAIL;
  4833. char message[110]={0};
  4834. char guid[37]={0};
  4835. char tempdata[65]={0};
  4836. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4837. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4838. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4839. random_uuid(guid);
  4840. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4841. LWS_SendNow(message);
  4842. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4843. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4844. {
  4845. result = PASS;
  4846. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4847. }
  4848. //#ifdef SystemLogMessage
  4849. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4850. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4851. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4852. //#endif
  4853. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4854. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4855. //record status
  4856. if(strcmp(status,"Idle")==0)
  4857. {
  4858. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4859. }
  4860. else if(strcmp(status,"Uploaded")==0)
  4861. {
  4862. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4863. }
  4864. else if(strcmp(status,"UploadFailed")==0)
  4865. {
  4866. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4867. }
  4868. else if(strcmp(status,"Uploading")==0)
  4869. {
  4870. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4871. }
  4872. return result;
  4873. }
  4874. int sendFirmwareStatusNotificationRequest(char *status)
  4875. {
  4876. mtrace();
  4877. int result = FAIL;
  4878. char message[110]={0};
  4879. char guid[37]={0};
  4880. char tempdata[65]={0};
  4881. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4882. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4883. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4884. random_uuid(guid);
  4885. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4886. LWS_SendNow(message);
  4887. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4888. 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*/)
  4889. {
  4890. result = PASS;
  4891. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4892. }
  4893. //#ifdef SystemLogMessage
  4894. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4895. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4896. //#endif
  4897. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4898. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4899. //record status
  4900. if(strcmp(status,"Downloaded")==0)
  4901. {
  4902. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4903. }
  4904. else if(strcmp(status,"DownloadFailed")==0)
  4905. {
  4906. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4907. }
  4908. else if(strcmp(status,"Downloading")==0)
  4909. {
  4910. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4911. }
  4912. else if(strcmp(status,"Idle")==0)
  4913. {
  4914. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4915. }
  4916. else if(strcmp(status,"InstallationFailed")==0)
  4917. {
  4918. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4919. }
  4920. else if(strcmp(status,"Installing")==0)
  4921. {
  4922. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4923. }
  4924. else if(strcmp(status,"Installed")==0)
  4925. {
  4926. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4927. }
  4928. return result;
  4929. }
  4930. int sendHeartbeatRequest(int gun_index)
  4931. {
  4932. mtrace();
  4933. int result = FAIL;
  4934. char message[80]={0};
  4935. char guid[37]={0};
  4936. char tempdata[65]={0};
  4937. random_uuid(guid);
  4938. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4939. , MESSAGE_TYPE_CALL
  4940. , guid );
  4941. LWS_Send(message);
  4942. sprintf(tempdata, "Heartbeat,%d", 0);
  4943. 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*/)
  4944. {
  4945. result = PASS;
  4946. }
  4947. return result;
  4948. }
  4949. int sendStartTransactionRequest(int gun_index)
  4950. {
  4951. mtrace();
  4952. int result = FAIL;
  4953. char message[250]={0};
  4954. char guid[37]={0};
  4955. struct timeval tmnow;
  4956. struct tm *tm;
  4957. char buf[28];//, usec_buf[6];
  4958. char tempdata[65]={0};
  4959. int tempIndex = 0;
  4960. DEBUG_INFO("sendStartTransactionRequest...\n");
  4961. gettimeofday(&tmnow, NULL);
  4962. time_t t;
  4963. t = time(NULL);
  4964. /*UTC time and date*/
  4965. tm = gmtime(&t);
  4966. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4967. #if 0 // remove temporally
  4968. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4969. strcat(buf,".");
  4970. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4971. strcat(buf,usec_buf);
  4972. #endif
  4973. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4974. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4975. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4976. // clear StartTransaction Response
  4977. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4978. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4979. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4980. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4981. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4982. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4983. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4984. {
  4985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4986. {
  4987. tempIndex = ((gun_index==2) ? 1: 0);
  4988. }
  4989. else
  4990. {
  4991. tempIndex = gun_index;
  4992. }
  4993. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4994. {
  4995. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4996. {
  4997. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4998. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4999. }
  5000. }
  5001. }
  5002. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5003. {
  5004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5005. {
  5006. tempIndex = ((gun_index==2) ? 1: 0);
  5007. }
  5008. else
  5009. {
  5010. tempIndex = gun_index;
  5011. }
  5012. for (int index = 0; index < CCS_QUANTITY; index++)
  5013. {
  5014. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5015. {
  5016. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5017. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5018. }
  5019. }
  5020. }
  5021. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5022. {
  5023. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5024. {
  5025. tempIndex = ((gun_index==2) ? 1: 0);
  5026. }
  5027. else
  5028. {
  5029. tempIndex = gun_index;
  5030. }
  5031. for (int index = 0; index < GB_QUANTITY; index++)
  5032. {
  5033. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5034. {
  5035. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5036. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5037. }
  5038. }
  5039. }
  5040. else if(gunType[gun_index] == GUN_TYPE_DO)
  5041. {
  5042. tempIndex = gun_index;
  5043. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5044. {
  5045. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5046. {
  5047. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5048. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5049. }
  5050. }
  5051. }
  5052. else
  5053. {
  5054. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5055. {
  5056. tempIndex = 2;
  5057. }
  5058. else
  5059. {
  5060. tempIndex = gun_index;
  5061. }
  5062. for (int index = 0; index < AC_QUANTITY; index++)
  5063. {
  5064. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5065. {
  5066. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5067. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5068. }
  5069. }
  5070. }
  5071. random_uuid(guid);
  5072. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5073. {
  5074. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5075. , gun_index +1
  5076. , MESSAGE_TYPE_CALL
  5077. , guid
  5078. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5079. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5080. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5081. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5082. }
  5083. else
  5084. {
  5085. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5086. , gun_index +1
  5087. , MESSAGE_TYPE_CALL
  5088. , guid
  5089. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5090. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5091. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5092. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5093. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5094. }
  5095. #if 1
  5096. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5097. 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*/)
  5098. {
  5099. result = PASS;
  5100. }
  5101. #endif
  5102. strcpy(queuedata, message);
  5103. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5104. OCPP_insert_transaction_msg(YES, queuedata);
  5105. return result;
  5106. }
  5107. int sendStatusNotificationRequest(int gun_index)
  5108. {
  5109. mtrace();
  5110. int result = FAIL;
  5111. char message[600]={0};
  5112. char guid[37];
  5113. int currentStatus = 0;
  5114. struct timeval tmnow;
  5115. struct tm *tm;
  5116. char buf[28];//, usec_buf[6];
  5117. char tempdata[65]={0};
  5118. int tempIndex = 0;
  5119. uint8_t isStateChanged = TRUE;
  5120. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5121. gettimeofday(&tmnow, NULL);
  5122. time_t t;
  5123. t = time(NULL);
  5124. /*UTC time and date*/
  5125. tm = gmtime(&t);
  5126. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5127. #if 0 // remove temporally
  5128. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5129. strcat(buf,".");
  5130. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5131. strcat(buf,usec_buf);
  5132. #endif
  5133. //printf("%s",buf);
  5134. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5135. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5136. // it's option
  5137. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5138. /*
  5139. enum _SYSTEM_STATUS
  5140. {
  5141. S_BOOTING = 0,
  5142. S_IDLE, = 1
  5143. S_AUTHORIZING, =2
  5144. S_REASSIGN_CHECK, =3
  5145. S_REASSIGN, =4
  5146. S_PRECHARGE, =5
  5147. S_PREPARING_FOR_EV, =6
  5148. S_PREPARING_FOR_EVSE, =7
  5149. S_CHARGING, =8
  5150. S_TERMINATING, =9
  5151. S_COMPLETE, =10
  5152. S_ALARM, =11
  5153. S_FAULT =12
  5154. }
  5155. */
  5156. //check Transaction active
  5157. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5158. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5159. {
  5160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5161. {
  5162. tempIndex = ((gun_index==2) ? 1: 0);
  5163. }
  5164. else
  5165. {
  5166. tempIndex = gun_index;
  5167. }
  5168. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5169. {
  5170. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5171. {
  5172. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5173. {
  5174. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5175. {
  5176. currentStatus = Preparing; //OCPP Status: Preparing
  5177. }
  5178. else
  5179. {
  5180. currentStatus = Available; //OCPP Status: Available
  5181. }
  5182. }
  5183. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5184. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5185. ) //S_PRECHARGE
  5186. {
  5187. currentStatus = Preparing; //OCPP Status: Preparing
  5188. }
  5189. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5190. {
  5191. currentStatus = Charging; //OCPP Status: Charging
  5192. }
  5193. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5194. {
  5195. currentStatus = Finishing; //OCPP Status: Finishing
  5196. }
  5197. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5198. {
  5199. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5200. }
  5201. 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
  5202. {
  5203. currentStatus = Unavailable; //OCPP Status: Unavailable
  5204. }
  5205. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5206. {
  5207. currentStatus = Faulted; //OCPP Status: Faulted
  5208. }
  5209. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5210. {
  5211. currentStatus = Reserved; //OCPP Status: Reserved
  5212. }
  5213. } //end of the same index
  5214. }//end of for CHAdeMO_QUANTITY
  5215. }
  5216. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5217. {
  5218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5219. {
  5220. tempIndex = ((gun_index==2) ? 1: 0);
  5221. }
  5222. else
  5223. {
  5224. tempIndex = gun_index;
  5225. }
  5226. for (int index = 0; index < CCS_QUANTITY; index++)
  5227. {
  5228. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5229. {
  5230. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5231. {
  5232. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5233. {
  5234. currentStatus = Preparing; //OCPP Status: Preparing
  5235. }
  5236. else
  5237. {
  5238. currentStatus = Available; //OCPP Status: Available
  5239. }
  5240. }
  5241. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5242. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5243. ) //S_PRECHARGE
  5244. {
  5245. currentStatus = Preparing; //OCPP Status: Preparing
  5246. }
  5247. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5248. {
  5249. currentStatus = Charging; //OCPP Status: Charging
  5250. }
  5251. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5252. {
  5253. currentStatus = Finishing; //OCPP Status: Finishing
  5254. }
  5255. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5256. {
  5257. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5258. }
  5259. 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
  5260. {
  5261. currentStatus = Unavailable; //OCPP Status : Unavailable
  5262. }
  5263. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5264. {
  5265. currentStatus = Faulted; //OCPP Status: Faulted
  5266. }
  5267. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5268. {
  5269. currentStatus = Reserved; //OCPP Status: Reserved
  5270. }
  5271. } //end of the same index
  5272. } // end of for CCS_QUANTITY
  5273. }
  5274. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5275. {
  5276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5277. {
  5278. tempIndex = ((gun_index==2) ? 1: 0);
  5279. }
  5280. else
  5281. {
  5282. tempIndex = gun_index;
  5283. }
  5284. for (int index = 0; index < GB_QUANTITY; index++)
  5285. {
  5286. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5287. {
  5288. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5289. {
  5290. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5291. {
  5292. currentStatus = Preparing; //OCPP Status: Preparing
  5293. }
  5294. else
  5295. {
  5296. currentStatus = Available; //OCPP Status: Available
  5297. }
  5298. }
  5299. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5300. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5301. ) //S_PRECHARGE
  5302. {
  5303. currentStatus = Preparing; //OCPP Status: Preparing
  5304. }
  5305. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5306. {
  5307. currentStatus = Charging; //OCPP Status: Charging
  5308. }
  5309. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5310. {
  5311. currentStatus = Finishing; //OCPP Status: Finishing
  5312. }
  5313. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5314. {
  5315. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5316. }
  5317. 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
  5318. {
  5319. currentStatus = Unavailable; //OCPP Status: Unavailable
  5320. }
  5321. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5322. {
  5323. currentStatus = Faulted; //OCPP Status: Faulted
  5324. }
  5325. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5326. {
  5327. currentStatus = Reserved; //OCPP Status: Reserved
  5328. }
  5329. } //end of the same index
  5330. } // end of for GB_QUANTITY
  5331. }
  5332. else if(gunType[gun_index] == GUN_TYPE_DO)
  5333. {
  5334. tempIndex = gun_index;
  5335. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5336. {
  5337. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5338. {
  5339. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5340. {
  5341. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5342. {
  5343. currentStatus = Preparing; //OCPP Status: Preparing
  5344. }
  5345. else
  5346. {
  5347. currentStatus = Available; //OCPP Status: Available
  5348. }
  5349. }
  5350. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5351. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5352. ) //S_PRECHARGE
  5353. {
  5354. currentStatus = Preparing; //OCPP Status: Preparing
  5355. }
  5356. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5357. {
  5358. currentStatus = Charging; //OCPP Status: Charging
  5359. }
  5360. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5361. {
  5362. currentStatus = Finishing; //OCPP Status: Finishing
  5363. }
  5364. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5365. {
  5366. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5367. }
  5368. 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
  5369. {
  5370. currentStatus = Unavailable; //OCPP Status: Unavailable
  5371. }
  5372. 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
  5373. {
  5374. currentStatus = Faulted; //OCPP Status: Faulted
  5375. }
  5376. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5377. {
  5378. currentStatus = Reserved; //OCPP Status: Reserved
  5379. }
  5380. } //end of the same index
  5381. }
  5382. }
  5383. else
  5384. {
  5385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5386. {
  5387. tempIndex = 2;
  5388. }
  5389. else
  5390. {
  5391. tempIndex = gun_index;
  5392. }
  5393. for (int index = 0; index < AC_QUANTITY; index++)
  5394. {
  5395. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5396. {
  5397. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5398. {
  5399. 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))
  5400. {
  5401. currentStatus = Preparing; //OCPP Status: Preparing
  5402. }
  5403. else
  5404. {
  5405. currentStatus = Available; //OCPP Status: Available
  5406. }
  5407. }
  5408. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5409. {
  5410. currentStatus = Preparing; //OCPP Status: Preparing
  5411. }
  5412. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5413. {
  5414. currentStatus = Charging; //OCPP Status: Charging
  5415. }
  5416. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5417. {
  5418. currentStatus = Finishing; //OCPP Status: Finishing
  5419. }
  5420. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5421. {
  5422. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5423. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5424. else
  5425. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5426. }
  5427. 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
  5428. {
  5429. currentStatus = Unavailable; //OCPP Status: Unavailable
  5430. }
  5431. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5432. {
  5433. currentStatus = Faulted; //OCPP Status: Faulted
  5434. }
  5435. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5436. {
  5437. currentStatus = Reserved; //OCPP Status: Reserved
  5438. }
  5439. }//end of the same index
  5440. }//end of for AC_QUANTITY
  5441. }
  5442. //it's option
  5443. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5444. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5445. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5446. {
  5447. isStateChanged = FALSE;
  5448. }
  5449. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5450. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5451. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5452. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5453. random_uuid(guid);
  5454. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5455. , MESSAGE_TYPE_CALL
  5456. , guid
  5457. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5458. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5459. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5460. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5461. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5462. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5463. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5464. if((server_sign == TRUE) && isStateChanged)
  5465. {
  5466. LWS_Send(message);
  5467. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5468. 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*/)
  5469. {
  5470. //DEBUG_ERROR("statusNotification mapitem pass");
  5471. result = PASS;
  5472. }
  5473. }
  5474. else
  5475. {
  5476. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5477. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5478. result = PASS;
  5479. }
  5480. return result;
  5481. }
  5482. int sendStopTransactionRequest(int gun_index)
  5483. {
  5484. mtrace();
  5485. int result = FAIL;
  5486. //char message[1500]={0};
  5487. char guid[37]={0};
  5488. char tempdata[65]={0};
  5489. int tempIndex = 0;
  5490. char TempStopTransaction[256];
  5491. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5492. //int idx_sample=0;
  5493. DEBUG_INFO("sendStopTransactionRequest \n");
  5494. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5495. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5496. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5497. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5498. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5499. {
  5500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5501. {
  5502. tempIndex = ((gun_index==2) ? 1: 0);
  5503. }
  5504. else
  5505. {
  5506. tempIndex = gun_index;
  5507. }
  5508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5509. {
  5510. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5511. {
  5512. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5513. }
  5514. }// END OF CHAdeMO_QUANTITY
  5515. }
  5516. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5517. {
  5518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5519. {
  5520. tempIndex = ((gun_index==2) ? 1: 0);
  5521. }
  5522. else
  5523. {
  5524. tempIndex = gun_index;
  5525. }
  5526. for (int index = 0; index < CCS_QUANTITY; index++)
  5527. {
  5528. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5529. {
  5530. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5531. }
  5532. }// END OF CCS_QUANTITY
  5533. }
  5534. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5535. {
  5536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5537. {
  5538. tempIndex = ((gun_index==2) ? 1: 0);
  5539. }
  5540. else
  5541. {
  5542. tempIndex = gun_index;
  5543. }
  5544. for (int index = 0; index < GB_QUANTITY; index++)
  5545. {
  5546. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5547. {
  5548. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5549. }
  5550. }// END OF GB_QUANTITY
  5551. }
  5552. else if(gunType[gun_index] == GUN_TYPE_DO)
  5553. {
  5554. tempIndex = gun_index;
  5555. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5556. {
  5557. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5558. {
  5559. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5560. }
  5561. }// END OF GB_QUANTITY
  5562. }
  5563. else
  5564. {
  5565. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5566. {
  5567. tempIndex = 2;
  5568. }
  5569. else
  5570. {
  5571. tempIndex = gun_index;
  5572. }
  5573. for (int index = 0; index < AC_QUANTITY; index++)
  5574. {
  5575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5576. {
  5577. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5578. }
  5579. }// END OF AC_QUANTITY
  5580. }
  5581. //====================================== Stop Transaction Time =====================================================
  5582. struct timeval tmnow;
  5583. struct tm *tm;
  5584. char buf[28];//, usec_buf[6];
  5585. gettimeofday(&tmnow, NULL);
  5586. time_t t;
  5587. t = time(NULL);
  5588. /*UTC time and date*/
  5589. tm = gmtime(&t);
  5590. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5592. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5593. random_uuid(guid);
  5594. /***********************************transactionData******************************************************/
  5595. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5597. //=================================
  5598. // Transaction_Begin
  5599. //=================================
  5600. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5601. {
  5602. //============================================ Energy.Active.Import.Interval ================================
  5603. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  5607. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5608. 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))
  5609. {
  5610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5611. }
  5612. else
  5613. {
  5614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5615. }
  5616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5618. }
  5619. //=================================
  5620. // Transaction_End
  5621. //=================================
  5622. // ================================= Current.Import L1 ===============================================
  5623. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5624. {
  5625. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5626. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5627. {
  5628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5629. {
  5630. tempIndex = ((gun_index==2) ? 1: 0);
  5631. }
  5632. else
  5633. {
  5634. tempIndex = gun_index;
  5635. }
  5636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5637. {
  5638. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5639. {
  5640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5641. }
  5642. }// End of for CHAdeMO_QUANTITY
  5643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5644. }
  5645. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5646. {
  5647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5648. {
  5649. tempIndex = ((gun_index==2) ? 1: 0);
  5650. }
  5651. else
  5652. {
  5653. tempIndex = gun_index;
  5654. }
  5655. for (int index = 0; index < CCS_QUANTITY; index++)
  5656. {
  5657. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5658. {
  5659. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5660. }
  5661. }// End of for CCS_QUANTITY
  5662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5663. }
  5664. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5665. {
  5666. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5667. {
  5668. tempIndex = ((gun_index==2) ? 1: 0);
  5669. }
  5670. else
  5671. {
  5672. tempIndex = gun_index;
  5673. }
  5674. for (int index = 0; index < GB_QUANTITY; index++)
  5675. {
  5676. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5677. {
  5678. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5679. }
  5680. }// End of for GB_QUANTITY
  5681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5682. }
  5683. else if(gunType[gun_index] == GUN_TYPE_DO)
  5684. {
  5685. tempIndex = gun_index;
  5686. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5687. {
  5688. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5689. {
  5690. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5691. }
  5692. }
  5693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5694. }
  5695. else
  5696. {
  5697. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5698. {
  5699. tempIndex = 2;
  5700. }
  5701. else
  5702. {
  5703. tempIndex = gun_index;
  5704. }
  5705. for (int index = 0; index < AC_QUANTITY; index++)
  5706. {
  5707. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5708. {
  5709. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5710. }
  5711. }// End of for AC_QUANTITY
  5712. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5713. }
  5714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5719. }
  5720. // ================================= Energy.Active.Import.Interval ==============================================
  5721. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5722. {
  5723. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5724. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5725. {
  5726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5727. {
  5728. tempIndex = ((gun_index==2) ? 1: 0);
  5729. }
  5730. else
  5731. {
  5732. tempIndex = gun_index;
  5733. }
  5734. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5735. {
  5736. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5737. {
  5738. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5739. }
  5740. }// END OF CHAdeMO_QUANTITY
  5741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5742. }
  5743. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5744. {
  5745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5746. {
  5747. tempIndex = ((gun_index==2) ? 1: 0);
  5748. }
  5749. else
  5750. {
  5751. tempIndex = gun_index;
  5752. }
  5753. for (int index = 0; index < CCS_QUANTITY; index++)
  5754. {
  5755. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5756. {
  5757. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5758. }
  5759. }// END OF CCS_QUANTITY
  5760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5761. }
  5762. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5763. {
  5764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5765. {
  5766. tempIndex = ((gun_index==2) ? 1: 0);
  5767. }
  5768. else
  5769. {
  5770. tempIndex = gun_index;
  5771. }
  5772. for (int index = 0; index < GB_QUANTITY; index++)
  5773. {
  5774. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5775. {
  5776. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5777. }
  5778. }// END OF GB_QUANTITY
  5779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5780. }
  5781. else if(gunType[gun_index] == GUN_TYPE_DO)
  5782. {
  5783. tempIndex = gun_index;
  5784. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5785. {
  5786. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5787. {
  5788. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5789. }
  5790. }
  5791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5792. }
  5793. else
  5794. {
  5795. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5796. {
  5797. tempIndex = 2;
  5798. }
  5799. else
  5800. {
  5801. tempIndex = gun_index;
  5802. }
  5803. for (int index = 0; index < AC_QUANTITY; index++)
  5804. {
  5805. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5806. {
  5807. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5808. }
  5809. }// END OF AC_QUANTITY
  5810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5811. }
  5812. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5817. }
  5818. //=================================== Power.Active.Import ==================================================
  5819. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5820. {
  5821. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5822. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5823. {
  5824. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5825. {
  5826. tempIndex = ((gun_index==2) ? 1: 0);
  5827. }
  5828. else
  5829. {
  5830. tempIndex = gun_index;
  5831. }
  5832. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5833. {
  5834. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5835. {
  5836. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5837. }
  5838. } // End for CHAdeMO_QUANTITY
  5839. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5840. }
  5841. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5842. {
  5843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5844. {
  5845. tempIndex = ((gun_index==2) ? 1: 0);
  5846. }
  5847. else
  5848. {
  5849. tempIndex = gun_index;
  5850. }
  5851. for (int index = 0; index < CCS_QUANTITY; index++)
  5852. {
  5853. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5854. {
  5855. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5856. }
  5857. } // END for CCS_QUANTITY
  5858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5859. }
  5860. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5861. {
  5862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5863. {
  5864. tempIndex = ((gun_index==2) ? 1: 0);
  5865. }
  5866. else
  5867. {
  5868. tempIndex = gun_index;
  5869. }
  5870. for (int index = 0; index < GB_QUANTITY; index++)
  5871. {
  5872. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5873. {
  5874. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5875. }
  5876. }// END for GB_QUANTITY
  5877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5878. }
  5879. else if(gunType[gun_index] == GUN_TYPE_DO)
  5880. {
  5881. tempIndex = gun_index;
  5882. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5883. {
  5884. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5885. {
  5886. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5887. }
  5888. }
  5889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5890. }
  5891. else
  5892. {
  5893. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5894. {
  5895. tempIndex = 2;
  5896. }
  5897. else
  5898. {
  5899. tempIndex = gun_index;
  5900. }
  5901. for (int index = 0; index < AC_QUANTITY; index++)
  5902. {
  5903. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5904. {
  5905. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5906. }
  5907. } // END for AC_QUANTITY
  5908. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5909. }
  5910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5914. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5915. }
  5916. //============================ Voltage L1 ====================================
  5917. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5918. {
  5919. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5920. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5921. {
  5922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5923. {
  5924. tempIndex = ((gun_index==2) ? 1: 0);
  5925. }
  5926. else
  5927. {
  5928. tempIndex = gun_index;
  5929. }
  5930. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5931. {
  5932. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5933. {
  5934. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5935. }
  5936. } // END OF FOR CHAdeMO_QUANTITY
  5937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5938. }
  5939. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5940. {
  5941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5942. {
  5943. tempIndex = ((gun_index==2) ? 1: 0);
  5944. }
  5945. else
  5946. {
  5947. tempIndex = gun_index;
  5948. }
  5949. for (int index = 0; index < CCS_QUANTITY; index++)
  5950. {
  5951. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5952. {
  5953. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5954. }
  5955. } // END OF FOR CCS_QUANTITY
  5956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5957. }
  5958. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5959. {
  5960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5961. {
  5962. tempIndex = ((gun_index==2) ? 1: 0);
  5963. }
  5964. else
  5965. {
  5966. tempIndex = gun_index;
  5967. }
  5968. for (int index = 0; index < GB_QUANTITY; index++)
  5969. {
  5970. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5971. {
  5972. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5973. }
  5974. } // END OF FOR GB_QUANTITY
  5975. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5976. }
  5977. else if(gunType[gun_index] == GUN_TYPE_DO)
  5978. {
  5979. tempIndex = gun_index;
  5980. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5981. {
  5982. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5983. {
  5984. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5985. }
  5986. }
  5987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5988. }
  5989. else
  5990. {
  5991. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5992. {
  5993. tempIndex = 2;
  5994. }
  5995. else
  5996. {
  5997. tempIndex = gun_index;
  5998. }
  5999. for (int index = 0; index < AC_QUANTITY; index++)
  6000. {
  6001. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6002. {
  6003. 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
  6004. }
  6005. } // END OF FOR AC_QUANTITY
  6006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6007. }
  6008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6013. }
  6014. //====================== End SoC ================================
  6015. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6016. {
  6017. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6018. 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))
  6019. {
  6020. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6021. {
  6022. tempIndex = ((gun_index==2) ? 1: 0);
  6023. }
  6024. else
  6025. {
  6026. tempIndex = gun_index;
  6027. }
  6028. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6029. {
  6030. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6031. {
  6032. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6033. {
  6034. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6035. }
  6036. }
  6037. }
  6038. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6039. {
  6040. for (int index = 0; index < CCS_QUANTITY; index++)
  6041. {
  6042. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6043. {
  6044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6045. }
  6046. }
  6047. }
  6048. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6049. {
  6050. for (int index = 0; index < GB_QUANTITY; index++)
  6051. {
  6052. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6053. {
  6054. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6055. }
  6056. }
  6057. }
  6058. else if(gunType[gun_index] == GUN_TYPE_DO)
  6059. {
  6060. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6061. {
  6062. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6063. {
  6064. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6065. }
  6066. }
  6067. }
  6068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6074. } // END FOR DC CASE
  6075. }
  6076. // ================================= Current.Import L2 ===============================================
  6077. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6078. {
  6079. // AC 3 phse L2 current
  6080. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6081. {
  6082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6083. {
  6084. tempIndex = 2;
  6085. }
  6086. else
  6087. {
  6088. tempIndex = gun_index;
  6089. }
  6090. for (int index = 0; index < AC_QUANTITY; index++)
  6091. {
  6092. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6093. {
  6094. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6095. }
  6096. }// End of for AC_QUANTITY
  6097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6098. }
  6099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6104. }
  6105. // ================================= Current.Import L3 ===============================================
  6106. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6107. {
  6108. // AC 3 phse L3 current
  6109. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6110. {
  6111. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6112. {
  6113. tempIndex = 2;
  6114. }
  6115. else
  6116. {
  6117. tempIndex = gun_index;
  6118. }
  6119. for (int index = 0; index < AC_QUANTITY; index++)
  6120. {
  6121. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6122. {
  6123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6124. }
  6125. }// End of for AC_QUANTITY
  6126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6127. }
  6128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6133. }
  6134. //============================ Voltage L2 ====================================
  6135. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6136. {
  6137. // AC 3 phse L2 voltage
  6138. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6139. {
  6140. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6141. {
  6142. tempIndex = 2;
  6143. }
  6144. else
  6145. {
  6146. tempIndex = gun_index;
  6147. }
  6148. for (int index = 0; index < AC_QUANTITY; index++)
  6149. {
  6150. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6151. {
  6152. 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
  6153. }
  6154. } // END OF FOR AC_QUANTITY
  6155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6156. }
  6157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6162. }
  6163. //============================ Voltage L3 ====================================
  6164. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6165. {
  6166. // AC 3 phse L3 voltage
  6167. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6168. {
  6169. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6170. {
  6171. tempIndex = 2;
  6172. }
  6173. else
  6174. {
  6175. tempIndex = gun_index;
  6176. }
  6177. for (int index = 0; index < AC_QUANTITY; index++)
  6178. {
  6179. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6180. {
  6181. 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
  6182. }
  6183. } // END OF FOR AC_QUANTITY
  6184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6185. }
  6186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6191. }
  6192. //====================== Start SoC ================================
  6193. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6194. {
  6195. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6196. 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))
  6197. {
  6198. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6199. {
  6200. tempIndex = ((gun_index==2) ? 1: 0);
  6201. }
  6202. else
  6203. {
  6204. tempIndex = gun_index;
  6205. }
  6206. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6207. {
  6208. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6209. {
  6210. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6211. {
  6212. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6213. }
  6214. }
  6215. }
  6216. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6217. {
  6218. for (int index = 0; index < CCS_QUANTITY; index++)
  6219. {
  6220. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6221. {
  6222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6223. }
  6224. }
  6225. }
  6226. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6227. {
  6228. for (int index = 0; index < GB_QUANTITY; index++)
  6229. {
  6230. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6231. {
  6232. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6233. }
  6234. }
  6235. }
  6236. else if(gunType[gun_index] == GUN_TYPE_DO)
  6237. {
  6238. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6239. {
  6240. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6241. {
  6242. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6243. }
  6244. }
  6245. }
  6246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6251. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6252. } // END FOR DC CASE
  6253. }
  6254. //================================================ Message create ====================================================
  6255. json_object *StopTransaction = json_object_new_object();
  6256. json_object *transactionDatas = json_object_new_array();
  6257. json_object *sampledValues = json_object_new_array();
  6258. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6259. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6260. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6261. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6262. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6263. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6264. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6265. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6266. {
  6267. json_object *transactionData = json_object_new_object();
  6268. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6269. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6270. {
  6271. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6272. {
  6273. json_object *sampledValue = json_object_new_object();
  6274. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6275. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6276. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6277. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6278. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6279. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6280. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6281. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6282. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6283. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6284. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6285. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6286. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6287. json_object_array_add(sampledValues, sampledValue);
  6288. }
  6289. }
  6290. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6291. json_object_array_add(transactionDatas, transactionData);
  6292. }
  6293. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6294. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6295. ,MESSAGE_TYPE_CALL
  6296. ,guid
  6297. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6298. json_object_put(StopTransaction);
  6299. #if 1 // for TempStopTransaction
  6300. //Delete TempStopTransaction
  6301. if((access(TempStopTransaction,F_OK))!=-1)
  6302. {
  6303. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6304. }
  6305. #endif
  6306. #if 1
  6307. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6308. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6309. {
  6310. result = PASS;
  6311. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6312. }
  6313. #endif
  6314. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6315. OCPP_insert_transaction_msg(NO, queuedata);
  6316. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6317. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6318. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6319. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6320. {
  6321. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6322. }
  6323. //for test
  6324. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6325. return result;
  6326. }
  6327. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6328. {
  6329. mtrace();
  6330. int result = FAIL;
  6331. char guid[37]={0};
  6332. char tempdata[65]={0};
  6333. int tempIndex = 0;
  6334. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6335. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6336. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6337. //set value
  6338. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6339. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6340. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6341. -1);
  6342. random_uuid(guid);
  6343. //UTC Date time
  6344. struct timeval tmnow;
  6345. struct tm *tm;
  6346. char buf[28];//, usec_buf[6];
  6347. gettimeofday(&tmnow, NULL);
  6348. time_t t;
  6349. t = time(NULL);
  6350. /*UTC time and date*/
  6351. tm = gmtime(&t);
  6352. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6353. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6354. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6355. //********************************(1)Current.Import L1************************************************/
  6356. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6357. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6358. (dataType == ReadingContext_Trigger))
  6359. {
  6360. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6361. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6362. {
  6363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6364. {
  6365. tempIndex = ((gun_index==2) ? 1: 0);
  6366. }
  6367. else
  6368. {
  6369. tempIndex = gun_index;
  6370. }
  6371. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6372. {
  6373. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6374. {
  6375. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6376. }
  6377. }
  6378. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6379. }
  6380. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6381. {
  6382. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6383. {
  6384. tempIndex = ((gun_index==2) ? 1: 0);
  6385. }
  6386. else
  6387. {
  6388. tempIndex = gun_index;
  6389. }
  6390. for (int index = 0; index < CCS_QUANTITY; index++)
  6391. {
  6392. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6393. {
  6394. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6395. }
  6396. }
  6397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6398. }
  6399. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6400. {
  6401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6402. {
  6403. tempIndex = ((gun_index==2) ? 1: 0);
  6404. }
  6405. else
  6406. {
  6407. tempIndex = gun_index;
  6408. }
  6409. for (int index = 0; index < GB_QUANTITY; index++)
  6410. {
  6411. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6412. {
  6413. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6414. }
  6415. }
  6416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6417. }
  6418. else if(gunType[gun_index] == GUN_TYPE_DO)
  6419. {
  6420. tempIndex = gun_index;
  6421. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6422. {
  6423. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6424. {
  6425. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6426. }
  6427. }
  6428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6429. }
  6430. else
  6431. {
  6432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6433. {
  6434. tempIndex = 2;
  6435. }
  6436. else
  6437. {
  6438. tempIndex = gun_index;
  6439. }
  6440. for (int index = 0; index < AC_QUANTITY; index++)
  6441. {
  6442. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6443. {
  6444. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6445. }
  6446. }
  6447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6448. }
  6449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6453. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6454. }
  6455. //********************************(2)Energy.Active.Import.Register ************************************************/
  6456. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6457. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6458. (dataType == ReadingContext_Trigger))
  6459. {
  6460. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6461. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6462. {
  6463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6464. {
  6465. tempIndex = ((gun_index==2) ? 1: 0);
  6466. }
  6467. else
  6468. {
  6469. tempIndex = gun_index;
  6470. }
  6471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6472. {
  6473. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6474. {
  6475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6476. }
  6477. }
  6478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6479. }
  6480. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6481. {
  6482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6483. {
  6484. tempIndex = ((gun_index==2) ? 1: 0);
  6485. }
  6486. else
  6487. {
  6488. tempIndex = gun_index;
  6489. }
  6490. for (int index = 0; index < CCS_QUANTITY; index++)
  6491. {
  6492. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6493. {
  6494. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6495. }
  6496. }
  6497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6498. }
  6499. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6500. {
  6501. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6502. {
  6503. tempIndex = ((gun_index==2) ? 1: 0);
  6504. }
  6505. else
  6506. {
  6507. tempIndex = gun_index;
  6508. }
  6509. for (int index = 0; index < GB_QUANTITY; index++)
  6510. {
  6511. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6512. {
  6513. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6514. }
  6515. }
  6516. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6517. }
  6518. else if(gunType[gun_index] == GUN_TYPE_DO)
  6519. {
  6520. tempIndex = gun_index;
  6521. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6522. {
  6523. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6524. {
  6525. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6526. }
  6527. }
  6528. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6529. }
  6530. else
  6531. {
  6532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6533. {
  6534. tempIndex = 2;
  6535. }
  6536. else
  6537. {
  6538. tempIndex = gun_index;
  6539. }
  6540. for (int index = 0; index < AC_QUANTITY; index++)
  6541. {
  6542. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6543. {
  6544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6545. }
  6546. }
  6547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6548. }
  6549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6553. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6554. }
  6555. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6556. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6557. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6558. (dataType == ReadingContext_Trigger))
  6559. {
  6560. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6561. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6562. {
  6563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6564. {
  6565. tempIndex = ((gun_index==2) ? 1: 0);
  6566. }
  6567. else
  6568. {
  6569. tempIndex = gun_index;
  6570. }
  6571. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6572. {
  6573. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6574. {
  6575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6576. }
  6577. } // END OF FOR CHAdeMO_QUANTITY
  6578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6579. }
  6580. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6581. {
  6582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6583. {
  6584. tempIndex = ((gun_index==2) ? 1: 0);
  6585. }
  6586. else
  6587. {
  6588. tempIndex = gun_index;
  6589. }
  6590. for (int index = 0; index < CCS_QUANTITY; index++)
  6591. {
  6592. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6593. {
  6594. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6595. }
  6596. } // END OF CCS_QUANTITY
  6597. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6598. }
  6599. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6600. {
  6601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6602. {
  6603. tempIndex = ((gun_index==2) ? 1: 0);
  6604. }
  6605. else
  6606. {
  6607. tempIndex = gun_index;
  6608. }
  6609. for (int index = 0; index < GB_QUANTITY; index++)
  6610. {
  6611. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6612. {
  6613. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6614. }
  6615. } // END OF GB_QUANTITY
  6616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6617. }
  6618. else if(gunType[gun_index] == GUN_TYPE_DO)
  6619. {
  6620. tempIndex = gun_index;
  6621. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6622. {
  6623. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6624. {
  6625. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6626. }
  6627. }
  6628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6629. }
  6630. else
  6631. {
  6632. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6633. {
  6634. tempIndex = 2;
  6635. }
  6636. else
  6637. {
  6638. tempIndex = gun_index;
  6639. }
  6640. for (int index = 0; index < AC_QUANTITY; index++)
  6641. {
  6642. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6643. {
  6644. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6645. }
  6646. }
  6647. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6648. }
  6649. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6651. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6654. }
  6655. //********************************(4)Power.Active.Import************************************************/
  6656. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6657. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6658. (dataType == ReadingContext_Trigger))
  6659. {
  6660. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6661. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6662. {
  6663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6664. {
  6665. tempIndex = ((gun_index==2) ? 1: 0);
  6666. }
  6667. else
  6668. {
  6669. tempIndex = gun_index;
  6670. }
  6671. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6672. {
  6673. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6674. {
  6675. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6676. }
  6677. } // END OF FOR
  6678. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6679. }
  6680. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6681. {
  6682. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6683. {
  6684. tempIndex = ((gun_index==2) ? 1: 0);
  6685. }
  6686. else
  6687. {
  6688. tempIndex = gun_index;
  6689. }
  6690. for (int index = 0; index < CCS_QUANTITY; index++)
  6691. {
  6692. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6693. {
  6694. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6695. }
  6696. }
  6697. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6698. }
  6699. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6700. {
  6701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6702. {
  6703. tempIndex = ((gun_index==2) ? 1: 0);
  6704. }
  6705. else
  6706. {
  6707. tempIndex = gun_index;
  6708. }
  6709. for (int index = 0; index < GB_QUANTITY; index++)
  6710. {
  6711. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6712. {
  6713. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6714. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6715. }
  6716. }
  6717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6718. }
  6719. else if(gunType[gun_index] == GUN_TYPE_DO)
  6720. {
  6721. tempIndex = gun_index;
  6722. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6723. {
  6724. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6725. {
  6726. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6727. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6728. }
  6729. }
  6730. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6731. }
  6732. else
  6733. {
  6734. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6735. {
  6736. tempIndex = 2;
  6737. }
  6738. else
  6739. {
  6740. tempIndex = gun_index;
  6741. }
  6742. for (int index = 0; index < AC_QUANTITY; index++)
  6743. {
  6744. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6745. {
  6746. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6747. }
  6748. }
  6749. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6750. }
  6751. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6752. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6753. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6754. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6755. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6756. }
  6757. //***********************************************(5)VOLTAGE L1******************************************************/
  6758. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6759. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6760. (dataType == ReadingContext_Trigger))
  6761. {
  6762. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6763. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  6774. {
  6775. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6776. {
  6777. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6778. }
  6779. }
  6780. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6781. }
  6782. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6783. {
  6784. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6785. {
  6786. tempIndex = ((gun_index==2) ? 1: 0);
  6787. }
  6788. else
  6789. {
  6790. tempIndex = gun_index;
  6791. }
  6792. for (int index = 0; index < CCS_QUANTITY; index++)
  6793. {
  6794. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6795. {
  6796. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6797. }
  6798. }
  6799. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6800. }
  6801. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6802. {
  6803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6804. {
  6805. tempIndex = ((gun_index==2) ? 1: 0);
  6806. }
  6807. else
  6808. {
  6809. tempIndex = gun_index;
  6810. }
  6811. for (int index = 0; index < GB_QUANTITY; index++)
  6812. {
  6813. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6814. {
  6815. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6816. }
  6817. }
  6818. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6819. }
  6820. else if(gunType[gun_index] == GUN_TYPE_DO)
  6821. {
  6822. tempIndex = gun_index;
  6823. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6824. {
  6825. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6826. {
  6827. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6828. }
  6829. }
  6830. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6831. }
  6832. else
  6833. {
  6834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6835. {
  6836. tempIndex = 2;
  6837. }
  6838. else
  6839. {
  6840. tempIndex = gun_index;
  6841. }
  6842. for (int index = 0; index < AC_QUANTITY; index++)
  6843. {
  6844. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6845. {
  6846. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6847. }
  6848. }
  6849. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6850. }
  6851. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6852. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6853. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6854. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6855. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6856. }
  6857. //***********************************************(6)SOC******************************************************/
  6858. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6859. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6860. (dataType == ReadingContext_Trigger))
  6861. {
  6862. 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))
  6863. {
  6864. //idx_sample=5;
  6865. //sampledValue = NULL;
  6866. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6867. {
  6868. tempIndex = ((gun_index==2) ? 1: 0);
  6869. }
  6870. else
  6871. {
  6872. tempIndex = gun_index;
  6873. }
  6874. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6875. {
  6876. //tempIndex = ((gun_index==2) ? 1: 0);
  6877. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6878. {
  6879. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6880. {
  6881. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6882. }
  6883. }
  6884. }
  6885. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6886. {
  6887. //tempIndex = ((gun_index==2) ? 1: 0);
  6888. for (int index = 0; index < CCS_QUANTITY; index++)
  6889. {
  6890. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6891. {
  6892. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6893. }
  6894. }
  6895. }
  6896. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6897. {
  6898. //tempIndex = ((gun_index==2) ? 1: 0);
  6899. for (int index = 0; index < GB_QUANTITY; index++)
  6900. {
  6901. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6902. {
  6903. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6904. }
  6905. }
  6906. }
  6907. else if(gunType[gun_index] == GUN_TYPE_DO)
  6908. {
  6909. //tempIndex = ((gun_index==2) ? 1: 0);
  6910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6911. {
  6912. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6913. {
  6914. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6915. }
  6916. }
  6917. }
  6918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6923. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6924. }
  6925. }
  6926. //********************************(7)Current.Import L2************************************************/
  6927. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6928. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6929. (dataType == ReadingContext_Trigger))
  6930. {
  6931. // Only for AC 3 phase
  6932. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6933. {
  6934. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6935. {
  6936. tempIndex = 2;
  6937. }
  6938. else
  6939. {
  6940. tempIndex = gun_index;
  6941. }
  6942. for (int index = 0; index < AC_QUANTITY; index++)
  6943. {
  6944. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6945. {
  6946. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6947. }
  6948. }
  6949. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6950. }
  6951. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6952. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6953. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6954. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6955. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6956. }
  6957. //********************************(8)Current.Import L3************************************************/
  6958. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6959. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6960. (dataType == ReadingContext_Trigger))
  6961. {
  6962. // Only for AC 3 phase
  6963. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6964. {
  6965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6966. {
  6967. tempIndex = 2;
  6968. }
  6969. else
  6970. {
  6971. tempIndex = gun_index;
  6972. }
  6973. for (int index = 0; index < AC_QUANTITY; index++)
  6974. {
  6975. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6976. {
  6977. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6978. }
  6979. }
  6980. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6981. }
  6982. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6986. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6987. }
  6988. //***********************************************(9)VOLTAGE L2******************************************************/
  6989. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6990. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6991. (dataType == ReadingContext_Trigger))
  6992. {
  6993. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6994. {
  6995. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6996. {
  6997. tempIndex = 2;
  6998. }
  6999. else
  7000. {
  7001. tempIndex = gun_index;
  7002. }
  7003. for (int index = 0; index < AC_QUANTITY; index++)
  7004. {
  7005. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7006. {
  7007. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7008. }
  7009. }
  7010. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7011. }
  7012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7013. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7014. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7015. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7016. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7017. }
  7018. //***********************************************(10)VOLTAGE L3******************************************************/
  7019. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7020. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7021. (dataType == ReadingContext_Trigger))
  7022. {
  7023. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7024. {
  7025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7026. {
  7027. tempIndex = 2;
  7028. }
  7029. else
  7030. {
  7031. tempIndex = gun_index;
  7032. }
  7033. for (int index = 0; index < AC_QUANTITY; index++)
  7034. {
  7035. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7036. {
  7037. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7038. }
  7039. }
  7040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7041. }
  7042. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7044. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7045. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7046. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7047. }
  7048. //***********************************************(11)Current.Offered******************************************************/
  7049. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7050. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7051. (dataType == ReadingContext_Trigger))
  7052. {
  7053. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7054. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7055. {
  7056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7057. {
  7058. tempIndex = ((gun_index==2) ? 1: 0);
  7059. }
  7060. else
  7061. {
  7062. tempIndex = gun_index;
  7063. }
  7064. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7065. {
  7066. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7067. {
  7068. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7069. }
  7070. } // END OF FOR CHAdeMO_QUANTITY
  7071. }
  7072. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7073. {
  7074. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7075. {
  7076. tempIndex = ((gun_index==2) ? 1: 0);
  7077. }
  7078. else
  7079. {
  7080. tempIndex = gun_index;
  7081. }
  7082. for (int index = 0; index < CCS_QUANTITY; index++)
  7083. {
  7084. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7085. {
  7086. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7087. }
  7088. } // END OF CCS_QUANTITY
  7089. }
  7090. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  7101. {
  7102. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7103. {
  7104. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7105. }
  7106. } // END OF GB_QUANTITY
  7107. }
  7108. else if(gunType[gun_index] == GUN_TYPE_DO)
  7109. {
  7110. tempIndex = gun_index;
  7111. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7112. {
  7113. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7114. {
  7115. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7116. }
  7117. }
  7118. }
  7119. else
  7120. {
  7121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7122. {
  7123. tempIndex = 2;
  7124. }
  7125. else
  7126. {
  7127. tempIndex = gun_index;
  7128. }
  7129. for (int index = 0; index < AC_QUANTITY; index++)
  7130. {
  7131. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7132. {
  7133. uint16_t currentOffer;
  7134. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7135. {
  7136. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7137. }
  7138. else
  7139. {
  7140. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7141. }
  7142. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7143. }
  7144. }
  7145. }
  7146. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7147. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7148. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7149. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7150. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7151. }
  7152. //***********************************************(12)Power.Offered******************************************************/
  7153. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7154. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7155. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7156. {
  7157. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7158. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7159. {
  7160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7161. {
  7162. tempIndex = ((gun_index==2) ? 1: 0);
  7163. }
  7164. else
  7165. {
  7166. tempIndex = gun_index;
  7167. }
  7168. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7169. {
  7170. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7171. {
  7172. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7173. }
  7174. } // END OF FOR CHAdeMO_QUANTITY
  7175. }
  7176. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7177. {
  7178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7179. {
  7180. tempIndex = ((gun_index==2) ? 1: 0);
  7181. }
  7182. else
  7183. {
  7184. tempIndex = gun_index;
  7185. }
  7186. for (int index = 0; index < CCS_QUANTITY; index++)
  7187. {
  7188. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7189. {
  7190. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7191. }
  7192. } // END OF CCS_QUANTITY
  7193. }
  7194. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7195. {
  7196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7197. {
  7198. tempIndex = ((gun_index==2) ? 1: 0);
  7199. }
  7200. else
  7201. {
  7202. tempIndex = gun_index;
  7203. }
  7204. for (int index = 0; index < GB_QUANTITY; index++)
  7205. {
  7206. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7207. {
  7208. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7209. }
  7210. } // END OF GB_QUANTITY
  7211. }
  7212. else if(gunType[gun_index] == GUN_TYPE_DO)
  7213. {
  7214. tempIndex = gun_index;
  7215. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7216. {
  7217. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7218. {
  7219. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7220. }
  7221. }
  7222. }
  7223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7226. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7228. }
  7229. // Message create ====================================================================================================
  7230. if(TRUE)
  7231. {
  7232. json_object *MeterValueReq = json_object_new_object();
  7233. json_object *MeterValues = json_object_new_array();
  7234. json_object *sampledValues = json_object_new_array();
  7235. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7236. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7237. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7238. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7239. {
  7240. json_object *MeterValue = json_object_new_object();
  7241. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7242. {
  7243. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7244. {
  7245. json_object *sampledValue = json_object_new_object();
  7246. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7247. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7248. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7249. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7250. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7251. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7252. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7253. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7254. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7255. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7256. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7257. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7258. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7259. json_object_array_add(sampledValues, sampledValue);
  7260. }
  7261. }
  7262. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7263. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7264. json_object_array_add(MeterValues, MeterValue);
  7265. }
  7266. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7267. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7268. ,gun_index + 1
  7269. ,MESSAGE_TYPE_CALL
  7270. ,guid
  7271. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7272. json_object_put(MeterValueReq);
  7273. }
  7274. // Put request guid to hash map
  7275. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7276. 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*/)
  7277. {
  7278. result = PASS;
  7279. //DEBUG_INFO("MeterValues mapitem pass\n");
  7280. }
  7281. if((dataType != ReadingContext_Trigger) &&
  7282. (dataType != ReadingContext_Sample_Clock) &&
  7283. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7284. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7285. else
  7286. {
  7287. if(FirstHeartBeat)
  7288. LWS_Send(queuedata +2);
  7289. }
  7290. return result;
  7291. }
  7292. int sendLogStatusNotificationRequest(char *status)
  7293. {
  7294. mtrace();
  7295. int result = PASS;
  7296. char message[4096]={0};
  7297. char guid[37]={0};
  7298. char tempdata[128]={0};
  7299. json_object *LogStatusNotification = json_object_new_object();
  7300. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7301. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7302. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7303. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7304. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7305. random_uuid(guid);
  7306. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7307. json_object_put(LogStatusNotification);
  7308. LWS_Send(message);
  7309. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7310. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7311. {
  7312. result = PASS;
  7313. }
  7314. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7315. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7316. return result;
  7317. }
  7318. int sendSecurityEventNotificationRequest()
  7319. {
  7320. mtrace();
  7321. int result = PASS;
  7322. char message[4096]={0};
  7323. char guid[37]={0};
  7324. char tempdata[128]={0};
  7325. json_object *SecurityEventNotification = json_object_new_object();
  7326. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7327. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7328. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7329. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7330. random_uuid(guid);
  7331. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7332. json_object_put(SecurityEventNotification);
  7333. LWS_Send(message);
  7334. sprintf(tempdata, "SecurityEventNotification,0");
  7335. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7336. {
  7337. result = PASS;
  7338. }
  7339. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7340. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7341. return result;
  7342. }
  7343. int sendSignCertificateRequest()
  7344. {
  7345. mtrace();
  7346. int result = PASS;
  7347. char message[4096]={0};
  7348. char guid[37]={0};
  7349. char tempdata[128]={0};
  7350. json_object *SignCertificate = json_object_new_object();
  7351. DEBUG_INFO("sendSignCertificateRequest...\n");
  7352. // Read csr file content
  7353. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7354. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7355. char *line = NULL;
  7356. size_t len = 0;
  7357. while(getline(&line, &len, fp) != -1)
  7358. {
  7359. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7360. {
  7361. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7362. }
  7363. }
  7364. fclose(fp);
  7365. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7366. random_uuid(guid);
  7367. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7368. json_object_put(SignCertificate);
  7369. LWS_Send(message);
  7370. sprintf(tempdata, "SignCertificate,0");
  7371. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7372. {
  7373. result = PASS;
  7374. }
  7375. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7376. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7377. return result;
  7378. }
  7379. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7380. {
  7381. mtrace();
  7382. int result = PASS;
  7383. char message[110]={0};
  7384. char guid[37]={0};
  7385. char tempdata[65]={0};
  7386. json_object *FirmwareStatusNotification = json_object_new_object();
  7387. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7388. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7389. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7390. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7391. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7392. random_uuid(guid);
  7393. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7394. json_object_put(FirmwareStatusNotification);
  7395. LWS_Send(message);
  7396. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7397. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7398. {
  7399. result = PASS;
  7400. }
  7401. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7402. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7403. return result;
  7404. }
  7405. //==========================================
  7406. // send confirm routine
  7407. //==========================================
  7408. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7409. {
  7410. mtrace();
  7411. int result = FAIL;
  7412. char message[100]={0};
  7413. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7414. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7415. LWS_Send(message);
  7416. result = TRUE;
  7417. return result;
  7418. }
  7419. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7420. {
  7421. mtrace();
  7422. int result = FAIL;
  7423. char message[100]={0};
  7424. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7425. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7426. LWS_Send(message);
  7427. result = TRUE;
  7428. return result;
  7429. }
  7430. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7431. {
  7432. mtrace();
  7433. int result = FAIL;
  7434. char message[100]={0};
  7435. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7436. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7437. LWS_Send(message);
  7438. result = TRUE;
  7439. return result;
  7440. }
  7441. int sendClearCacheConfirmation(char *uuid,char *payload)
  7442. {
  7443. mtrace();
  7444. int result = FAIL;
  7445. char message[500]={0};
  7446. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7447. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7448. LWS_Send(message);
  7449. return result;
  7450. }
  7451. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7452. {
  7453. mtrace();
  7454. int result = FAIL;
  7455. char message[500]={0};
  7456. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7457. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7458. LWS_Send(message);
  7459. return result;
  7460. }
  7461. int sendDataTransferConfirmation(char *uuid,char *payload)
  7462. {
  7463. mtrace();
  7464. char statusStr[20]={0};
  7465. char dataStr[10]={0};
  7466. char sstr[20]={0};
  7467. int c = 0;
  7468. char *loc;
  7469. int result = FAIL;
  7470. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7471. /**********************status**************************/
  7472. loc = strstr(payload, "status");
  7473. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7474. c = 0;
  7475. while (loc[3+strlen("status")+c] != '\"')
  7476. {
  7477. sstr[c] = loc[3+strlen("status")+c];
  7478. c++;
  7479. }
  7480. sstr[c] = '\0';
  7481. strcpy(statusStr, sstr);
  7482. /**********************data**************************/
  7483. loc = strstr(payload, "data");
  7484. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7485. c = 0;
  7486. while (loc[3+strlen("data")+c] != '\"')
  7487. {
  7488. sstr[c] = loc[3+strlen("data")+c];
  7489. c++;
  7490. }
  7491. sstr[c] = '\0';
  7492. strcpy(dataStr, sstr);
  7493. return result;
  7494. }
  7495. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7496. {
  7497. mtrace();
  7498. int result = FAIL;
  7499. char message[1000]={0};
  7500. int CompositeScheduleIndex = 0;
  7501. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7502. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7503. if(nPeriod == 0)
  7504. {
  7505. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7506. {
  7507. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7508. ,MESSAGE_TYPE_CALLRESULT
  7509. ,uuid
  7510. ,payload
  7511. ,connectorIdInt);
  7512. }
  7513. else
  7514. {
  7515. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7516. ,MESSAGE_TYPE_CALLRESULT
  7517. ,uuid
  7518. ,payload
  7519. ,connectorIdInt
  7520. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7521. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7522. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7523. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7524. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7525. }
  7526. }
  7527. else
  7528. {
  7529. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7530. ,MESSAGE_TYPE_CALLRESULT
  7531. ,uuid
  7532. ,payload
  7533. ,connectorIdInt
  7534. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7535. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7536. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7537. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7538. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7539. {
  7540. if (idx_sample == 0)
  7541. {
  7542. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7543. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7544. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7545. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7546. }
  7547. else
  7548. {
  7549. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7550. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7551. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7552. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7553. }
  7554. }
  7555. sprintf(message + strlen(message), "]}}]");
  7556. }
  7557. LWS_Send(message);
  7558. result = TRUE;
  7559. return result;
  7560. }
  7561. int sendGetConfigurationConfirmation(char *uuid)
  7562. {
  7563. mtrace();
  7564. int result = FAIL;
  7565. int MaxKeySupported = 0;
  7566. int sentConfigurationNumber= 0;
  7567. int sentunConfigurationNumber= 0;
  7568. char message[1024*10]={0};
  7569. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7570. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7571. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7572. ,MESSAGE_TYPE_CALLRESULT
  7573. ,uuid );
  7574. //configuration key
  7575. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7576. {
  7577. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7578. {
  7579. if (sentConfigurationNumber == 0)
  7580. {
  7581. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7582. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7583. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7584. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7585. }
  7586. else
  7587. {
  7588. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7589. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7590. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7591. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7592. }
  7593. sentConfigurationNumber = sentConfigurationNumber + 1;
  7594. }
  7595. }
  7596. sprintf(message + strlen(message), "]");
  7597. if(UnknownKeynum != 0)
  7598. {
  7599. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7600. //unkown key
  7601. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7602. {
  7603. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7604. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7605. if(sentunConfigurationNumber == 0)
  7606. {
  7607. sprintf(message + strlen(message), "\"%s\""
  7608. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7609. }
  7610. else
  7611. {
  7612. sprintf(message + strlen(message), ",\"%s\""
  7613. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7614. }
  7615. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7616. }
  7617. sprintf(message + strlen(message), "]");
  7618. }
  7619. sprintf(message + strlen(message), "}]");
  7620. LWS_Send(message);
  7621. return result;
  7622. }
  7623. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7624. {
  7625. mtrace();
  7626. int result = FAIL;
  7627. char message[400]={0};
  7628. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7629. if(strcmp(payload,"")==0)
  7630. {
  7631. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7632. }
  7633. else
  7634. {
  7635. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7636. }
  7637. LWS_Send(message);
  7638. result = TRUE;
  7639. return result;
  7640. }
  7641. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7642. {
  7643. mtrace();
  7644. int result = FAIL;
  7645. char message[80]={0};
  7646. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7647. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7648. LWS_Send(message);
  7649. result = TRUE;
  7650. return result;
  7651. }
  7652. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7653. {
  7654. mtrace();
  7655. int result = FAIL;
  7656. char message[80]={0};
  7657. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7658. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7659. LWS_Send(message);
  7660. result = TRUE;
  7661. return result;
  7662. }
  7663. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7664. {
  7665. mtrace();
  7666. int result = FAIL;
  7667. char message[80]={0};
  7668. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7669. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7670. LWS_Send(message);
  7671. result = TRUE;
  7672. return result;
  7673. }
  7674. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7675. {
  7676. mtrace();
  7677. int result = FAIL;
  7678. char message[80]={0};
  7679. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7680. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7681. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7682. LWS_Send(message);
  7683. result = TRUE;
  7684. return result;
  7685. }
  7686. int sendResetConfirmation(char *uuid,char *payload)
  7687. {
  7688. mtrace();
  7689. int result = FAIL;
  7690. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7691. char message[80]={0};
  7692. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7693. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7694. LWS_Send(message);
  7695. result = TRUE;
  7696. return result;
  7697. }
  7698. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7699. {
  7700. mtrace();
  7701. int result = FAIL;
  7702. char message[500]={0};
  7703. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7704. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7705. LWS_Send(message);
  7706. result = TRUE;
  7707. return result;
  7708. }
  7709. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7710. {
  7711. mtrace();
  7712. int result = FAIL;
  7713. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7714. char message[80]={0};
  7715. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7716. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7717. LWS_Send(message);
  7718. result = TRUE;
  7719. return result;
  7720. }
  7721. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7722. {
  7723. mtrace();
  7724. int result = FAIL;
  7725. char message[80]={0};
  7726. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7727. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7728. LWS_Send(message);
  7729. result = TRUE;
  7730. return result;
  7731. }
  7732. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7733. {
  7734. mtrace();
  7735. int result = FAIL;
  7736. char message[80]={0};
  7737. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7738. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7739. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7740. LWS_Send(message);
  7741. result = TRUE;
  7742. return result;
  7743. }
  7744. int sendUpdateFirmwareConfirmation(char *uuid)
  7745. {
  7746. mtrace();
  7747. int result = FAIL;
  7748. char message[60]={0};
  7749. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7750. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7751. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7752. LWS_Send(message);
  7753. result = TRUE;
  7754. return result;
  7755. }
  7756. int sendCertificateSignedConfirmation(char *uuid)
  7757. {
  7758. mtrace();
  7759. int result = PASS;
  7760. char message[4096]={0};
  7761. json_object *CertificateSigned = json_object_new_object();
  7762. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7763. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7764. sprintf(message,"[%d,\"%s\",%s]"
  7765. ,MESSAGE_TYPE_CALLRESULT
  7766. ,uuid
  7767. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7768. json_object_put(CertificateSigned);
  7769. LWS_Send(message);
  7770. return result;
  7771. }
  7772. int sendDeleteCertificateConfirmation(char *uuid)
  7773. {
  7774. mtrace();
  7775. int result = PASS;
  7776. char message[4096]={0};
  7777. json_object *DeleteCertificate = json_object_new_object();
  7778. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7779. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7780. sprintf(message,"[%d,\"%s\",%s]"
  7781. ,MESSAGE_TYPE_CALLRESULT
  7782. ,uuid
  7783. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7784. json_object_put(DeleteCertificate);
  7785. LWS_Send(message);
  7786. return result;
  7787. }
  7788. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7789. {
  7790. mtrace();
  7791. int result = PASS;
  7792. char message[4096]={0};
  7793. json_object *ExtendedTriggerMessage = json_object_new_object();
  7794. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7795. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7796. sprintf(message,"[%d,\"%s\",%s]"
  7797. ,MESSAGE_TYPE_CALLRESULT
  7798. ,uuid
  7799. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7800. json_object_put(ExtendedTriggerMessage);
  7801. LWS_Send(message);
  7802. return result;
  7803. }
  7804. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7805. {
  7806. mtrace();
  7807. int result = PASS;
  7808. char message[4096]={0};
  7809. json_object *GetInstalledCertificateIds = json_object_new_object();
  7810. json_object *certificateHashDataDatas = json_object_new_array();
  7811. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7812. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7813. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7814. {
  7815. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7816. {
  7817. json_object *certificateHashData = json_object_new_object();
  7818. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7819. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7820. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7821. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7822. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7823. }
  7824. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7825. }
  7826. else
  7827. {
  7828. json_object_put(certificateHashDataDatas);
  7829. }
  7830. sprintf(message,"[%d,\"%s\",%s]"
  7831. ,MESSAGE_TYPE_CALLRESULT
  7832. ,uuid
  7833. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7834. json_object_put(GetInstalledCertificateIds);
  7835. LWS_Send(message);
  7836. return result;
  7837. }
  7838. int sendGetLogConfirmation(char *uuid)
  7839. {
  7840. mtrace();
  7841. int result = PASS;
  7842. char message[4096]={0};
  7843. json_object *GetLog = json_object_new_object();
  7844. DEBUG_INFO("sendGetLogConfirmation...\n");
  7845. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7846. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7847. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7848. sprintf(message,"[%d,\"%s\",%s]"
  7849. ,MESSAGE_TYPE_CALLRESULT
  7850. ,uuid
  7851. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7852. json_object_put(GetLog);
  7853. LWS_Send(message);
  7854. return result;
  7855. }
  7856. int sendInstallCertificateConfirmation(char *uuid)
  7857. {
  7858. mtrace();
  7859. int result = PASS;
  7860. char message[4096]={0};
  7861. json_object *InstallCertificate = json_object_new_object();
  7862. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7863. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7864. sprintf(message,"[%d,\"%s\",%s]"
  7865. ,MESSAGE_TYPE_CALLRESULT
  7866. ,uuid
  7867. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7868. json_object_put(InstallCertificate);
  7869. LWS_Send(message);
  7870. return result;
  7871. }
  7872. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7873. {
  7874. mtrace();
  7875. int result = PASS;
  7876. char message[4096]={0};
  7877. json_object *SignedUpdateFirmware = json_object_new_object();
  7878. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7879. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7880. sprintf(message,"[%d,\"%s\",%s]"
  7881. ,MESSAGE_TYPE_CALLRESULT
  7882. ,uuid
  7883. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7884. json_object_put(SignedUpdateFirmware);
  7885. LWS_Send(message);
  7886. return result;
  7887. }
  7888. int sendUnknownConfirmation(char *uuid)
  7889. {
  7890. mtrace();
  7891. int result = PASS;
  7892. char message[256]={0};
  7893. DEBUG_INFO("sendUnknownConfirmation...\n");
  7894. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7895. LWS_Send(message);
  7896. return result;
  7897. }
  7898. //==========================================
  7899. // Handle server request routine Start
  7900. //==========================================
  7901. int handleCancelReservationRequest(char *uuid, char *payload)
  7902. {
  7903. mtrace();
  7904. int result = FAIL;
  7905. int gunNO = 0;
  7906. int reservationIdInt = -1;
  7907. char comfirmstr[20];
  7908. DEBUG_INFO("handleCancelReservationRequest...\n");
  7909. json_object *CancelReservation;
  7910. CancelReservation = json_tokener_parse(payload);
  7911. if(!is_error(CancelReservation))
  7912. {
  7913. // Required data
  7914. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7915. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7916. }
  7917. json_object_put(CancelReservation);
  7918. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7919. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7920. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7921. if(reservationIdInt != -1)
  7922. {
  7923. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7924. //check Transaction active
  7925. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7926. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7927. {
  7928. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7929. {
  7930. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7931. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7932. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7933. {
  7934. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7935. }
  7936. else
  7937. {
  7938. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7939. }
  7940. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7941. goto end;
  7942. }
  7943. }
  7944. for (int index = 0; index < CCS_QUANTITY; index++)
  7945. {
  7946. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7947. {
  7948. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7949. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7950. if(gunType[2] == GUN_TYPE_CCS)
  7951. {
  7952. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7953. }
  7954. else
  7955. {
  7956. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7957. }
  7958. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7959. goto end;
  7960. }
  7961. }
  7962. for (int index = 0; index < GB_QUANTITY; index++)
  7963. {
  7964. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7965. {
  7966. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7967. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7968. if(gunType[2] == GUN_TYPE_GBT)
  7969. {
  7970. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7971. }
  7972. else
  7973. {
  7974. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7975. }
  7976. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7977. goto end;
  7978. }
  7979. }
  7980. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7981. {
  7982. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7983. {
  7984. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7985. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7986. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7987. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7988. goto end;
  7989. }
  7990. }
  7991. for (int index = 0; index < AC_QUANTITY; index++)
  7992. {
  7993. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7994. {
  7995. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7996. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7997. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7998. {
  7999. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8000. }
  8001. else
  8002. {
  8003. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8004. }
  8005. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8006. goto end;
  8007. }
  8008. }
  8009. }
  8010. //The reservationId does NOT match the reservationId
  8011. sendCancelReservationConfirmation(uuid, comfirmstr);
  8012. end:
  8013. // Fill in ocpp packet uuid
  8014. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8015. return result;
  8016. }
  8017. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8018. {
  8019. mtrace();
  8020. int result = FAIL;
  8021. int gunIndex = -1;
  8022. char typeStr[16]={0};
  8023. char comfirmstr[20];
  8024. int specificId = FALSE;
  8025. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8026. json_object *ChangeAvailability;
  8027. ChangeAvailability = json_tokener_parse(payload);
  8028. if(!is_error(ChangeAvailability))
  8029. {
  8030. // Required data
  8031. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8032. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8033. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8034. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8035. }
  8036. json_object_put(ChangeAvailability);
  8037. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8038. {
  8039. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8040. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8041. }
  8042. else if(gunIndex == 0)
  8043. {
  8044. for(int i=0; i < gunTotalNumber; i++)
  8045. {
  8046. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8047. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8048. }
  8049. }
  8050. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8051. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8052. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8053. {
  8054. specificId = TRUE;
  8055. }
  8056. if(specificId == FALSE)
  8057. goto end;
  8058. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8059. {
  8060. //----------------------gunIndex is 0 ------------------------------------------------//
  8061. if(gunIndex == 0)
  8062. {
  8063. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8064. {
  8065. for(int i=0; i < gunTotalNumber; i++)
  8066. {
  8067. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8068. {
  8069. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8070. {
  8071. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8072. {
  8073. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8074. goto end;
  8075. }
  8076. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8077. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8078. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8079. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8080. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8081. {
  8082. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8083. goto end;
  8084. }
  8085. }
  8086. }//END FOR CHAdeMO_QUANTITY
  8087. for (int index = 0; index < CCS_QUANTITY; index++)
  8088. {
  8089. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8090. {
  8091. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8092. {
  8093. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8094. goto end;
  8095. }
  8096. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8097. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8098. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8099. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8100. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8101. {
  8102. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8103. goto end;
  8104. }
  8105. }
  8106. }//END FOR CCS_QUANTITY
  8107. for (int index = 0; index < GB_QUANTITY; index++)
  8108. {
  8109. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8110. {
  8111. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8112. {
  8113. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8114. goto end;
  8115. }
  8116. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8117. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8118. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8119. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8120. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8121. {
  8122. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8123. goto end;
  8124. }
  8125. }
  8126. }// END FOR GB_QUANTITY
  8127. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8128. {
  8129. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8130. {
  8131. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8132. {
  8133. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8134. goto end;
  8135. }
  8136. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8137. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8138. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8139. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8140. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8141. {
  8142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8143. goto end;
  8144. }
  8145. }
  8146. }// END FOR GENERAL_GUN_QUANTITY
  8147. for (int index = 0; index < AC_QUANTITY; index++)
  8148. {
  8149. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8150. {
  8151. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8152. {
  8153. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8154. goto end;
  8155. }
  8156. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8157. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8158. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8159. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8160. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8161. {
  8162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8163. goto end;
  8164. }
  8165. }
  8166. }//END FOR AC_QUANTITY
  8167. }// END FOR gunTotalNumber
  8168. }
  8169. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8170. {
  8171. for(int i=0; i < gunTotalNumber; i++)
  8172. {
  8173. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8174. {
  8175. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8176. goto end;
  8177. }
  8178. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8179. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8180. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8181. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8182. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8183. {
  8184. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8185. goto end;
  8186. }
  8187. }
  8188. }
  8189. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8190. goto end;
  8191. }
  8192. //----------------------gunIndex is not 0 ------------------------------------------------//
  8193. //check Transaction active
  8194. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8195. {
  8196. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8197. {
  8198. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8199. {
  8200. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8201. goto end;
  8202. }
  8203. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8204. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8205. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8206. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8207. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8208. {
  8209. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8210. goto end;
  8211. }
  8212. else
  8213. {
  8214. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8215. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8216. goto end;
  8217. }
  8218. }
  8219. }//END FOR CHAdeMO_QUANTITY
  8220. for (int index = 0; index < CCS_QUANTITY; index++)
  8221. {
  8222. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8223. {
  8224. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8225. {
  8226. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8227. goto end;
  8228. }
  8229. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8230. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8231. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8232. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8233. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8234. {
  8235. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8236. goto end;
  8237. }
  8238. else
  8239. {
  8240. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8241. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8242. goto end;
  8243. }
  8244. }
  8245. }//END FOR CCS_QUANTITY
  8246. for (int index = 0; index < GB_QUANTITY; index++)
  8247. {
  8248. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8249. {
  8250. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8251. {
  8252. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8253. goto end;
  8254. }
  8255. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8256. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8257. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8258. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8259. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8260. {
  8261. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8262. goto end;
  8263. }
  8264. else
  8265. {
  8266. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8268. goto end;
  8269. }
  8270. }
  8271. }// END FOR GB_QUANTITY
  8272. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8273. {
  8274. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8275. {
  8276. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8277. {
  8278. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8279. goto end;
  8280. }
  8281. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8282. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8283. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8284. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8285. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8286. {
  8287. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8288. goto end;
  8289. }
  8290. else
  8291. {
  8292. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8294. goto end;
  8295. }
  8296. }
  8297. }// END FOR GENERAL_GUN_QUANTITY
  8298. for (int index = 0; index < AC_QUANTITY; index++)
  8299. {
  8300. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8301. {
  8302. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8303. {
  8304. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8305. goto end;
  8306. }
  8307. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8308. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8309. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8310. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8311. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8312. {
  8313. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8314. goto end;
  8315. }
  8316. else
  8317. {
  8318. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8320. goto end;
  8321. }
  8322. }
  8323. }//END FOR AC_QUANTITY
  8324. }//END FOR AvailabilityTypeStr[Inoperative]
  8325. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8326. {
  8327. //----------------------gunIndex is 0 ------------------------------------------------//
  8328. if(gunIndex == 0)
  8329. {
  8330. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8331. {
  8332. for(int i=0; i < gunTotalNumber; i++)
  8333. {
  8334. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8335. {
  8336. 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
  8337. {
  8338. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8339. goto end;
  8340. }
  8341. }//END FOR CHAdeMO_QUANTITY
  8342. for (int index = 0; index < CCS_QUANTITY; index++)
  8343. {
  8344. 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
  8345. {
  8346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8347. goto end;
  8348. }
  8349. }//END FOR CCS_QUANTITY
  8350. for (int index = 0; index < GB_QUANTITY; index++)
  8351. {
  8352. 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
  8353. {
  8354. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8355. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8356. goto end;
  8357. }
  8358. }// END FOR GB_QUANTITY
  8359. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8360. {
  8361. 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
  8362. {
  8363. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8364. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8365. goto end;
  8366. }
  8367. }// END FOR GENERAL_GUN_QUANTITY
  8368. for (int index = 0; index < AC_QUANTITY; index++)
  8369. {
  8370. 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
  8371. {
  8372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8373. goto end;
  8374. }
  8375. }//END FOR CHAdeMO_QUANTITY
  8376. }// END FOR gunTotalNumber
  8377. }
  8378. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8379. {
  8380. for(int i=0; i < gunTotalNumber; i++)
  8381. {
  8382. for (int index = 0; index < AC_QUANTITY; index++)
  8383. {
  8384. 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
  8385. {
  8386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8387. goto end;
  8388. }
  8389. }//END FOR CHAdeMO_QUANTITY
  8390. } // END FOR gunTotalNumber
  8391. }
  8392. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8393. goto end;
  8394. }
  8395. //----------------------gunIndex is not 0 ------------------------------------------------//
  8396. //check Transaction active
  8397. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8398. {
  8399. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8400. {
  8401. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8402. goto end;
  8403. }
  8404. }//END FOR CHAdeMO_QUANTITY
  8405. for (int index = 0; index < CCS_QUANTITY; index++)
  8406. {
  8407. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8408. {
  8409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8410. goto end;
  8411. }
  8412. }//END FOR CCS_QUANTITY
  8413. for (int index = 0; index < GB_QUANTITY; index++)
  8414. {
  8415. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8416. {
  8417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8418. goto end;
  8419. }
  8420. }// END FOR GB_QUANTITY
  8421. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8422. {
  8423. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8424. {
  8425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8426. goto end;
  8427. }
  8428. }// END FOR GENERAL_GUN_QUANTITY
  8429. for (int index = 0; index < AC_QUANTITY; index++)
  8430. {
  8431. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8432. {
  8433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8434. goto end;
  8435. }
  8436. }//END FOR AC_QUANTITY
  8437. }//END FOR AvailabilityTypeStr[Operative]
  8438. end:
  8439. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8440. {
  8441. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8442. }
  8443. else
  8444. {
  8445. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8446. }
  8447. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8448. {
  8449. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8450. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8451. }
  8452. else if(gunIndex == 0)
  8453. {
  8454. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8455. {
  8456. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8457. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8458. }
  8459. }
  8460. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8461. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8462. return result;
  8463. }
  8464. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8465. {
  8466. mtrace();
  8467. int valueInvalid = NO;
  8468. int result = FAIL;
  8469. char keystr[40]={0};
  8470. char valuestr[501]={0}; //value should be limited in 500 bytes
  8471. char comfirmstr[20]={0};
  8472. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8473. json_object *ChangeConfiguration;
  8474. ChangeConfiguration = json_tokener_parse(payload);
  8475. if(!is_error(ChangeConfiguration))
  8476. {
  8477. // Required data
  8478. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8479. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8480. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8481. {
  8482. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8483. }
  8484. else
  8485. {
  8486. valueInvalid = YES;
  8487. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8488. }
  8489. }
  8490. json_object_put(ChangeConfiguration);
  8491. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8492. {
  8493. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8494. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8495. }
  8496. else
  8497. {
  8498. int status = setKeyValue(keystr, valuestr);
  8499. switch(status)
  8500. {
  8501. case ConfigurationStatus_Accepted:
  8502. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8503. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8504. StoreConfigurationTable();
  8505. break;
  8506. case RebootRequired:
  8507. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8508. StoreConfigurationTable();
  8509. break;
  8510. case NotSupported:
  8511. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8512. break;
  8513. case ConfigurationStatus_Rejected:
  8514. default:
  8515. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8516. break;
  8517. }
  8518. }
  8519. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8520. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8521. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8522. {
  8523. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8524. SetOcppConnStatus(FALSE);
  8525. }
  8526. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8527. {
  8528. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8529. }
  8530. return result;
  8531. }
  8532. int handleClearCacheRequest(char *uuid, char *payload)
  8533. {
  8534. mtrace();
  8535. int result = FAIL;
  8536. char comfirmstr[20];
  8537. char rmFileCmd[100]={0};
  8538. struct stat stats;
  8539. DEBUG_INFO("handleClearCacheRequest...\n");
  8540. stat("/Storage/OCPP", &stats);
  8541. // Check for directory existence
  8542. if (S_ISDIR(stats.st_mode) == 1)
  8543. {}
  8544. else
  8545. {
  8546. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8547. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8548. system(rmFileCmd);
  8549. }
  8550. if(OCPP_cleanLocalCache())
  8551. {
  8552. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8553. }
  8554. else
  8555. {
  8556. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8557. }
  8558. sendClearCacheConfirmation(uuid, comfirmstr);
  8559. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8560. return result;
  8561. }
  8562. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8563. {
  8564. mtrace();
  8565. int result = FAIL;
  8566. int resultRename;
  8567. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8568. char chargingProfilePurposeStr[26]={0};
  8569. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8570. char tempchargingProfilePurposeStr[26]={0};
  8571. char str[100]={0};
  8572. char fname[200]={0};
  8573. char comfirmstr[20]={0};
  8574. char word[1600]={0};
  8575. int clearflag = FALSE;
  8576. int chargingProfileIdIsNULL = FALSE;
  8577. int connectorIsNULL = FALSE;
  8578. int chargingProfilePurposeIsNULL = FALSE;
  8579. int stackLevelIsNULL = FALSE;
  8580. //int GotoEnd = FALSE;
  8581. FILE *fptr1, *fptr2;
  8582. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8583. int n_chargingProfile=0;
  8584. int isEmptyFile = FALSE;
  8585. char sLineWord[1600]={0};
  8586. char chargingProfiles[10][100]={0};
  8587. int ChargeProfileCount = 0;
  8588. int ch;
  8589. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8590. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8591. json_object *ClearChargingProfile;
  8592. ClearChargingProfile = json_tokener_parse(payload);
  8593. if(!is_error(ClearChargingProfile))
  8594. {
  8595. // Optional data
  8596. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8597. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8598. else
  8599. chargingProfileIdIsNULL = TRUE;
  8600. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8601. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8602. else
  8603. connectorIsNULL = TRUE;
  8604. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8605. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8606. else
  8607. chargingProfilePurposeIsNULL = TRUE;
  8608. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8609. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8610. else
  8611. stackLevelIsNULL = TRUE;
  8612. }
  8613. json_object_put(ClearChargingProfile);
  8614. if(connectorIsNULL == FALSE)
  8615. {
  8616. switch(connectorIdInt)
  8617. {
  8618. case 0:
  8619. if(chargingProfilePurposeIsNULL == TRUE)
  8620. {
  8621. int l = 0;
  8622. strcpy(fname, ChargePointMaxProfile_JSON);
  8623. if((access(fname,F_OK))!=-1)
  8624. {
  8625. strcpy(chargingProfiles[l], fname);
  8626. l = l + 1;
  8627. }
  8628. strcpy(fname, TxDefaultProfile_0_JSON);
  8629. if((access(fname,F_OK))!=-1)
  8630. {
  8631. strcpy(chargingProfiles[l], fname);
  8632. l = l + 1;
  8633. }
  8634. ChargeProfileCount = l;
  8635. }
  8636. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8637. {
  8638. strcpy(fname, ChargePointMaxProfile_JSON);
  8639. if((access(fname,F_OK))!=-1)
  8640. {
  8641. strcpy(chargingProfiles[0], fname);
  8642. ChargeProfileCount = 1;
  8643. }
  8644. }
  8645. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8646. {
  8647. strcpy(fname, TxDefaultProfile_0_JSON);
  8648. if((access(fname,F_OK))!=-1)
  8649. {
  8650. strcpy(chargingProfiles[0], fname);
  8651. ChargeProfileCount = 1;
  8652. }
  8653. }
  8654. break;
  8655. default:
  8656. if(chargingProfilePurposeIsNULL == TRUE)
  8657. {
  8658. int m = 0;
  8659. memset(fname, 0, ARRAY_SIZE(fname));
  8660. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8661. if((access(fname,F_OK))!=-1)
  8662. {
  8663. strcpy(chargingProfiles[m], fname);
  8664. m = m + 1;
  8665. }
  8666. memset(fname, 0, ARRAY_SIZE(fname));
  8667. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8668. if((access(fname,F_OK))!=-1)
  8669. {
  8670. strcpy(chargingProfiles[m], fname);
  8671. m = m + 1;
  8672. }
  8673. ChargeProfileCount = m;
  8674. }
  8675. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8676. {
  8677. //strcpy(fname, TxDefaultProfile_1_JSON);
  8678. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8679. if((access(fname,F_OK))!=-1)
  8680. {
  8681. strcpy(chargingProfiles[0], fname);
  8682. ChargeProfileCount = 1;
  8683. }
  8684. }
  8685. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8686. {
  8687. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8688. if((access(fname,F_OK))!=-1)
  8689. {
  8690. strcpy(chargingProfiles[0], fname);
  8691. ChargeProfileCount = 1;
  8692. }
  8693. //strcpy(fname, TxProfile_1_JSON);
  8694. }
  8695. //strcpy(fname, ChargePointMaxProfile_JSON );
  8696. break;
  8697. }
  8698. }
  8699. else // Check all Charging Profiles
  8700. {
  8701. int i = 0;
  8702. char fnametemp[200]={0};
  8703. ChargeProfileCount = 0;
  8704. //Check ChargePointMaxProfile.json exit
  8705. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8706. {
  8707. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8708. i = i + 1;
  8709. }
  8710. //Check TxDefaultProfile_0.json exit
  8711. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8712. {
  8713. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8714. i = i + 1;
  8715. }
  8716. //Check TxDefaultProfile_%d.json
  8717. for(int j=1; j <= gunTotalNumber; j++)
  8718. {
  8719. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8720. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8721. if((access(fnametemp,F_OK))!=-1)
  8722. {
  8723. strcpy(chargingProfiles[i], fnametemp);
  8724. i = i + 1;
  8725. }
  8726. }
  8727. //Check TxProfile_%d.json
  8728. for(int j=1; j <= gunTotalNumber; j++)
  8729. {
  8730. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8731. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8732. if((access(fnametemp,F_OK))!=-1)
  8733. {
  8734. strcpy(chargingProfiles[i], fnametemp);
  8735. i = i + 1;
  8736. }
  8737. }
  8738. ChargeProfileCount = i;
  8739. }// End connectorIsNULL is TRUE
  8740. if(ChargeProfileCount == 0)
  8741. {
  8742. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8743. goto end;
  8744. }
  8745. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8746. {
  8747. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8748. goto end;
  8749. }
  8750. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8751. {
  8752. memset(str, 0, ARRAY_SIZE(str));
  8753. // clear temp file
  8754. sprintf(str,"rm -f %s",temp);
  8755. system(str);
  8756. for(int k=0; k < ChargeProfileCount; k++)
  8757. {
  8758. memset(str, 0, ARRAY_SIZE(str));
  8759. //clear file in C
  8760. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8761. system(str);
  8762. }
  8763. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8764. goto end;
  8765. }
  8766. else if(connectorIsNULL == TRUE)
  8767. {
  8768. for(int k=0; k < ChargeProfileCount; k++)
  8769. {
  8770. fptr1 = fopen(chargingProfiles[k], "r");
  8771. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8772. //Check Charging Profile Count
  8773. while(fscanf(fptr1, "%s", word) != EOF)
  8774. {
  8775. //DEBUG_INFO("word=%s\n",word);
  8776. if(strstr(word, "chargingProfileId")!= NULL)
  8777. {
  8778. //DEBUG_INFO("test chargingProfileId \n");
  8779. n_chargingProfile = n_chargingProfile + 1;
  8780. //DEBUG_INFO("chargingProfileId Found\n");
  8781. }
  8782. }
  8783. rewind(fptr1);
  8784. //search Charging Profile Element
  8785. //int i= 0;
  8786. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8787. {
  8788. json_object *tmpProfilee;
  8789. tmpProfilee = json_tokener_parse(sLineWord);
  8790. if(!is_error(tmpProfilee))
  8791. {
  8792. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8793. {
  8794. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8795. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8796. }
  8797. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8798. {
  8799. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8800. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8801. }
  8802. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8803. {
  8804. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8805. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8806. }
  8807. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8808. {
  8809. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8810. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8811. }
  8812. }
  8813. json_object_put(tmpProfilee);
  8814. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8815. {
  8816. //------- not write to fptr2-------//
  8817. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8818. //clearflag = TRUE;
  8819. }
  8820. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8821. {
  8822. //------- not write to fptr2-------//
  8823. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8824. }
  8825. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8826. {
  8827. //------- not write to fptr2-------//
  8828. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8829. }
  8830. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8831. {
  8832. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8833. }
  8834. else
  8835. {
  8836. fprintf(fptr2, sLineWord);//writing data into file
  8837. }
  8838. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8839. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8840. if(clearflag == TRUE)
  8841. {
  8842. fclose(fptr1);
  8843. fclose(fptr2);
  8844. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8845. system(str);
  8846. // clear temp file
  8847. sprintf(str,"rm -f %s",temp);
  8848. system(str);
  8849. }
  8850. else
  8851. {
  8852. fclose(fptr1);
  8853. fclose(fptr2);
  8854. memset(str, 0, ARRAY_SIZE(str));
  8855. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8856. system(str);
  8857. resultRename = rename(temp, chargingProfiles[k]);
  8858. if(resultRename == 0)
  8859. {
  8860. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8861. }
  8862. else
  8863. {
  8864. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8865. }
  8866. if(comfirmstr[0]== 0)
  8867. {
  8868. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8869. }
  8870. //Check chargingProfile is empty file
  8871. /*------ Read the file ----------------*/
  8872. fptr1=fopen(chargingProfiles[k],"r");
  8873. ch=fgetc(fptr1);
  8874. rewind(fptr1);
  8875. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8876. if(ch!=EOF)
  8877. {
  8878. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8879. {
  8880. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8881. if(sLineWord[0]=='\0')
  8882. {
  8883. isEmptyFile = TRUE;
  8884. break;
  8885. }
  8886. else
  8887. {
  8888. isEmptyFile = FALSE;
  8889. break;
  8890. }
  8891. }
  8892. }
  8893. else
  8894. isEmptyFile = TRUE;
  8895. fclose(fptr1);
  8896. if(isEmptyFile == TRUE)
  8897. {
  8898. memset(str, 0, ARRAY_SIZE(str));
  8899. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8900. system(str);
  8901. }
  8902. }
  8903. }// End of while(int k=0; k < ChargePointCount; k++)
  8904. }
  8905. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8906. {
  8907. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8908. for(int k=0; k < ChargeProfileCount; k++)
  8909. {
  8910. fptr1 = fopen(chargingProfiles[k], "r");
  8911. fptr2 = fopen(temp, "w+");
  8912. //Check Charging Profile Count
  8913. while(fscanf(fptr1, "%s", word) != EOF)
  8914. {
  8915. //DEBUG_INFO("word=%s\n",word);
  8916. if(strstr(word, "chargingProfileId")!= NULL)
  8917. {
  8918. n_chargingProfile = n_chargingProfile + 1;
  8919. }
  8920. }
  8921. rewind(fptr1);
  8922. //search Charging Profile Element
  8923. //int i= 0;
  8924. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8925. {
  8926. json_object *tmpProfilee;
  8927. tmpProfilee = json_tokener_parse(sLineWord);
  8928. if(!is_error(tmpProfilee))
  8929. {
  8930. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8931. {
  8932. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8933. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8934. }
  8935. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8936. {
  8937. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8938. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8939. }
  8940. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8941. {
  8942. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8943. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8944. }
  8945. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8946. {
  8947. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8948. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8949. }
  8950. }
  8951. json_object_put(tmpProfilee);
  8952. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8953. {
  8954. //------- not write to fptr2-------//
  8955. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8956. //clearflag = TRUE;
  8957. }
  8958. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8959. {
  8960. //------- not write to fptr2-------//
  8961. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8962. }
  8963. else if(stackLevelIsNULL == TRUE)
  8964. {
  8965. //Clear Whole File
  8966. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8967. clearflag = TRUE;
  8968. break;
  8969. }
  8970. else
  8971. {
  8972. fprintf(fptr2, sLineWord);//writing data into file
  8973. }
  8974. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8975. }
  8976. if(clearflag == TRUE)
  8977. {
  8978. fclose(fptr1);
  8979. fclose(fptr2);
  8980. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8981. system(str);
  8982. // clear temp file
  8983. sprintf(str,"rm -f %s",temp);
  8984. system(str);
  8985. }
  8986. else
  8987. {
  8988. fclose(fptr1);
  8989. fclose(fptr2);
  8990. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8991. system(str);
  8992. resultRename = rename(temp, chargingProfiles[k]);
  8993. if(resultRename == 0)
  8994. {
  8995. DEBUG_INFO("File ChargingProfile renamed successfully");
  8996. }
  8997. else
  8998. {
  8999. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9000. }
  9001. if(comfirmstr[0]== 0)
  9002. {
  9003. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9004. }
  9005. //Check chargingProfile is empty file
  9006. /*------ Read the file ----------------*/
  9007. fptr1=fopen(chargingProfiles[k],"r");
  9008. ch=fgetc(fptr1);
  9009. rewind(fptr1);
  9010. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9011. if(ch!=EOF)
  9012. {
  9013. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9014. {
  9015. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9016. if(sLineWord[0]=='\0')
  9017. {
  9018. isEmptyFile = TRUE;
  9019. break;
  9020. }
  9021. else
  9022. {
  9023. isEmptyFile = FALSE;
  9024. break;
  9025. }
  9026. }
  9027. }
  9028. else
  9029. isEmptyFile = TRUE;
  9030. fclose(fptr1);
  9031. if(isEmptyFile == TRUE)
  9032. {
  9033. memset(str, 0, ARRAY_SIZE(str));
  9034. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9035. system(str);
  9036. }
  9037. /*------- End of reading ---------------*/
  9038. }
  9039. } // while(int k=0; k < ChargeProfileCount; k++)
  9040. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9041. end:
  9042. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9043. {
  9044. if(connectorIdInt == 0)
  9045. {
  9046. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9047. {
  9048. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9049. }
  9050. }
  9051. else
  9052. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9053. }
  9054. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9055. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9056. return result;
  9057. }
  9058. void createFirmwareVersionByDataTransfer(void)
  9059. {
  9060. json_object *FirmwareDataTransfer = json_object_new_object();
  9061. // AC & DC model
  9062. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9063. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9064. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9065. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9066. // DC model
  9067. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9068. {
  9069. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9070. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9071. (gunType[3] != GUN_TYPE_UNKNOWN))
  9072. {
  9073. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9074. }
  9075. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9076. {
  9077. // DS DM DW
  9078. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9079. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9080. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9081. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9082. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9083. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9084. }
  9085. else
  9086. {
  9087. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9088. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9089. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9090. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9091. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9092. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9093. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9094. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9095. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9096. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9097. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9098. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9099. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9100. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9101. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9102. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9103. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9104. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9105. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9106. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9107. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9108. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9109. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9110. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9111. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9112. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9113. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9114. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9115. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9116. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9117. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9118. }
  9119. }
  9120. // 4G model
  9121. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9122. {
  9123. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9124. }
  9125. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9126. json_object_put(FirmwareDataTransfer);
  9127. }
  9128. int handleDataTransferRequest(char *uuid, char *payload)
  9129. {
  9130. mtrace();
  9131. json_object *response = json_object_new_object();
  9132. int result = FAIL;
  9133. char tempvendorId[255]={0};
  9134. char tempmessageId[50]={0};
  9135. char tempdata[512]={0};
  9136. char message[2048]={0};
  9137. DEBUG_INFO("handleDataTransferRequest...\n");
  9138. if((uuid != NULL) && (payload != NULL))
  9139. {
  9140. json_object *DataTransfer;
  9141. DataTransfer = json_tokener_parse(payload);
  9142. if(!is_error(DataTransfer))
  9143. {
  9144. // Required data
  9145. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9146. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9147. // Optional data
  9148. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9149. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9150. if(json_object_object_get(DataTransfer, "data") != NULL)
  9151. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9152. result = PASS;
  9153. }
  9154. json_object_put(DataTransfer);
  9155. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9156. {
  9157. // Send all moudle firmware version on EVSE
  9158. createFirmwareVersionByDataTransfer();
  9159. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9160. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9161. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9162. json_object_put(response);
  9163. }
  9164. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9165. {
  9166. system("/usr/bin/run_tmate_restart.sh &");
  9167. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9168. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9169. json_object_put(response);
  9170. }
  9171. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9172. {
  9173. json_object *data;
  9174. data = json_tokener_parse(tempdata);
  9175. if(!is_error(data))
  9176. {
  9177. 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))
  9178. {
  9179. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9180. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9181. if(json_object_object_get(data, "SOC") != NULL)
  9182. {
  9183. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9184. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9185. }
  9186. if(json_object_object_get(data, "Energy") != NULL)
  9187. {
  9188. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9189. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9190. }
  9191. if(json_object_object_get(data, "Duration") != NULL)
  9192. {
  9193. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9194. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9195. }
  9196. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9197. }
  9198. else
  9199. {
  9200. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9201. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9202. }
  9203. }
  9204. else
  9205. {
  9206. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9207. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9208. }
  9209. json_object_put(data);
  9210. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9211. json_object_put(response);
  9212. }
  9213. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9214. {
  9215. json_object *data;
  9216. data = json_tokener_parse(tempdata);
  9217. if(!is_error(data))
  9218. {
  9219. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9220. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9221. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9222. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9223. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9224. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9225. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9226. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9227. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9228. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9229. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9230. }
  9231. else
  9232. {
  9233. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9234. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9235. }
  9236. json_object_put(data);
  9237. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9238. json_object_put(response);
  9239. }
  9240. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9241. {
  9242. json_object *data;
  9243. data = json_tokener_parse(tempdata);
  9244. if(!is_error(data))
  9245. {
  9246. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9247. if(json_object_object_get(data, "idToken") != NULL)
  9248. {
  9249. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9250. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9251. }
  9252. if(json_object_object_get(data, "price") != NULL)
  9253. {
  9254. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9255. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9256. }
  9257. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9258. }
  9259. else
  9260. {
  9261. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9262. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9263. }
  9264. json_object_put(data);
  9265. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9266. json_object_put(response);
  9267. }
  9268. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9269. {
  9270. json_object *data;
  9271. data = json_tokener_parse(tempdata);
  9272. if(!is_error(data))
  9273. {
  9274. if(json_object_object_get(data, "txId") != NULL)
  9275. {
  9276. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9277. for(int idx = 0;idx<gunTotalNumber;idx++)
  9278. {
  9279. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9280. {
  9281. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9282. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9283. if(json_object_object_get(data, "description") != NULL)
  9284. {
  9285. // California pricing V1.0
  9286. DEBUG_INFO("California pricing V1.0\n");
  9287. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9288. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9289. }
  9290. else
  9291. {
  9292. // California pricing V1.1
  9293. DEBUG_INFO("California pricing V1.1\n");
  9294. if(json_object_object_get(data, "timestamp") != NULL)
  9295. {
  9296. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9297. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9298. }
  9299. if(json_object_object_get(data, "meterValue") != NULL)
  9300. {
  9301. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9302. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9303. }
  9304. if(json_object_object_get(data, "cost") != NULL)
  9305. {
  9306. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9307. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9308. }
  9309. if(json_object_object_get(data, "state") != NULL)
  9310. {
  9311. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9312. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9313. }
  9314. if(json_object_object_get(data, "chargingPrice") != NULL)
  9315. {
  9316. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9317. {
  9318. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9319. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9320. }
  9321. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9322. {
  9323. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9324. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9325. }
  9326. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9327. {
  9328. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9329. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9330. }
  9331. }
  9332. if(json_object_object_get(data, "idlePrice") != NULL)
  9333. {
  9334. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9335. {
  9336. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9337. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9338. }
  9339. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9340. {
  9341. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9342. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9343. }
  9344. }
  9345. if(json_object_object_get(data, "nextPeriod") != NULL)
  9346. {
  9347. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9348. {
  9349. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9350. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9351. }
  9352. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9353. {
  9354. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9355. {
  9356. 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")));
  9357. 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"));
  9358. }
  9359. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9360. {
  9361. 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")));
  9362. 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"));
  9363. }
  9364. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9365. {
  9366. 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")));
  9367. 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"));
  9368. }
  9369. }
  9370. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9371. {
  9372. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9373. {
  9374. 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")));
  9375. 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"));
  9376. }
  9377. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9378. {
  9379. 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")));
  9380. 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"));
  9381. }
  9382. }
  9383. }
  9384. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9385. {
  9386. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9387. {
  9388. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9389. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9390. }
  9391. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9392. {
  9393. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9394. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9395. }
  9396. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9397. {
  9398. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9399. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9400. }
  9401. }
  9402. }
  9403. }
  9404. }
  9405. }
  9406. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9407. }
  9408. else
  9409. {
  9410. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9411. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9412. }
  9413. json_object_put(data);
  9414. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9415. json_object_put(response);
  9416. }
  9417. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9418. {
  9419. json_object *data;
  9420. data = json_tokener_parse(tempdata);
  9421. if(!is_error(data))
  9422. {
  9423. if(json_object_object_get(data, "txId") != NULL)
  9424. {
  9425. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9426. for(int idx = 0;idx<gunTotalNumber;idx++)
  9427. {
  9428. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9429. {
  9430. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9431. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9432. if(json_object_object_get(data, "description") != NULL)
  9433. {
  9434. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9435. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9436. }
  9437. }
  9438. }
  9439. }
  9440. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9441. }
  9442. else
  9443. {
  9444. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9445. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9446. }
  9447. json_object_put(data);
  9448. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9449. json_object_put(response);
  9450. }
  9451. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9452. {
  9453. json_object *data;
  9454. data = json_tokener_parse(tempdata);
  9455. if(!is_error(data))
  9456. {
  9457. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9458. if(json_object_object_get(data, "Content_Type") != NULL)
  9459. {
  9460. 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))
  9461. {
  9462. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9463. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9464. {
  9465. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9466. }
  9467. }
  9468. else
  9469. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9470. }
  9471. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9472. }
  9473. else
  9474. {
  9475. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9476. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9477. }
  9478. json_object_put(data);
  9479. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9480. json_object_put(response);
  9481. }
  9482. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9483. {
  9484. json_object *data;
  9485. data = json_tokener_parse(tempdata);
  9486. if(!is_error(data))
  9487. {
  9488. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9489. if(json_object_object_get(data, "ConnectorId") != NULL)
  9490. {
  9491. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9492. }
  9493. if(json_object_object_get(data, "SerialNo") != NULL)
  9494. {
  9495. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9496. }
  9497. if(json_object_object_get(data, "Page_Index") != NULL)
  9498. {
  9499. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9500. }
  9501. if(json_object_object_get(data, "Duration") != NULL)
  9502. {
  9503. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9504. }
  9505. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9506. }
  9507. else
  9508. {
  9509. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9510. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9511. }
  9512. json_object_put(data);
  9513. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9514. json_object_put(response);
  9515. }
  9516. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9517. {
  9518. json_object *data;
  9519. data = json_tokener_parse(tempdata);
  9520. if(!is_error(data))
  9521. {
  9522. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9523. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9524. {
  9525. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9526. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9527. else
  9528. {
  9529. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9530. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9531. }
  9532. }
  9533. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9534. {
  9535. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9536. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9537. else
  9538. {
  9539. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9540. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9541. }
  9542. }
  9543. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9544. {
  9545. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9546. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9547. else
  9548. {
  9549. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9550. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9551. }
  9552. }
  9553. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9554. {
  9555. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9556. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9557. else
  9558. {
  9559. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9560. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9561. }
  9562. }
  9563. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9564. {
  9565. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9566. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9567. else
  9568. {
  9569. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9570. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9571. }
  9572. }
  9573. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9574. {
  9575. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9576. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9577. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9578. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9579. else
  9580. {
  9581. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9582. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9583. }
  9584. }
  9585. if(json_object_object_get(data, "isAuthentication") != NULL)
  9586. {
  9587. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9588. {
  9589. case 0:
  9590. case 1:
  9591. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9592. break;
  9593. default:
  9594. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9595. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9596. break;
  9597. }
  9598. }
  9599. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9600. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9601. }
  9602. else
  9603. {
  9604. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9605. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9606. }
  9607. json_object_put(data);
  9608. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9609. json_object_put(response);
  9610. }
  9611. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9612. {
  9613. json_object *data;
  9614. data = json_tokener_parse(tempdata);
  9615. if(!is_error(data))
  9616. {
  9617. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9618. {
  9619. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9620. {
  9621. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9622. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9623. }
  9624. else
  9625. {
  9626. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9627. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9628. }
  9629. }
  9630. else
  9631. {
  9632. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9633. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9634. }
  9635. }
  9636. else
  9637. {
  9638. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9639. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9640. }
  9641. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9642. json_object_put(response);
  9643. }
  9644. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9645. {
  9646. json_object *data;
  9647. data = json_tokener_parse(tempdata);
  9648. if(!is_error(data))
  9649. {
  9650. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9651. if(json_object_object_get(data, "stationName") != NULL)
  9652. {
  9653. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9654. }
  9655. else
  9656. {
  9657. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9658. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9659. }
  9660. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9661. {
  9662. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9663. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9664. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9665. }
  9666. }
  9667. else
  9668. {
  9669. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9670. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9671. }
  9672. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9673. json_object_put(response);
  9674. }
  9675. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9676. {
  9677. json_object *data;
  9678. data = json_tokener_parse(tempdata);
  9679. if(!is_error(data))
  9680. {
  9681. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9682. if(json_object_object_get(data, "weatherId") != NULL)
  9683. {
  9684. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9685. }
  9686. else
  9687. {
  9688. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9689. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9690. }
  9691. if(json_object_object_get(data, "Temperature") != NULL)
  9692. {
  9693. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9694. }
  9695. else
  9696. {
  9697. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9698. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9699. }
  9700. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9701. {
  9702. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9703. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9704. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9705. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9706. );
  9707. }
  9708. }
  9709. else
  9710. {
  9711. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9712. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9713. }
  9714. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9715. json_object_put(response);
  9716. }
  9717. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9718. {
  9719. json_object *data;
  9720. data = json_tokener_parse(tempdata);
  9721. if(!is_error(data))
  9722. {
  9723. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9724. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9725. {
  9726. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9727. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9728. }
  9729. else
  9730. {
  9731. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9732. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9733. }
  9734. }
  9735. else
  9736. {
  9737. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9738. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9739. }
  9740. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9741. json_object_put(response);
  9742. }
  9743. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9744. {
  9745. json_object *data;
  9746. data = json_tokener_parse(tempdata);
  9747. if(!is_error(data))
  9748. {
  9749. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9750. {
  9751. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9752. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9753. if(gun_index < gunTotalNumber)
  9754. {
  9755. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9756. {
  9757. json_object *responsedata = json_object_new_object();
  9758. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  9759. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9760. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  9761. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  9762. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9763. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9764. }
  9765. else
  9766. {
  9767. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9768. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9769. }
  9770. }
  9771. else
  9772. {
  9773. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9774. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9775. }
  9776. }
  9777. else
  9778. {
  9779. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9780. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9781. }
  9782. }
  9783. else
  9784. {
  9785. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9786. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9787. }
  9788. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9789. json_object_put(response);
  9790. }
  9791. else
  9792. {
  9793. // Can not find valid message id
  9794. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9795. }
  9796. }
  9797. else
  9798. {
  9799. // Payload is null
  9800. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9801. }
  9802. LWS_Send(message);
  9803. return result;
  9804. }
  9805. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9806. {
  9807. mtrace();
  9808. int result = FAIL;
  9809. int connectorIdInt, durationInt;
  9810. char chargingRateUnitStr[4]={0};
  9811. char comfirmstr[20];
  9812. int confirmPeriods = 0;
  9813. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9814. json_object *GetCompositeSchedule;
  9815. GetCompositeSchedule = json_tokener_parse(payload);
  9816. if(!is_error(GetCompositeSchedule))
  9817. {
  9818. // Required data
  9819. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9820. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9821. else
  9822. connectorIdInt = -1;
  9823. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9824. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9825. else
  9826. durationInt = 86400;
  9827. // Optional data
  9828. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9829. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9830. }
  9831. json_object_put(GetCompositeSchedule);
  9832. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9833. if((connectorIdInt == 0) ||
  9834. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9835. {
  9836. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9837. struct StructChargingProfile tmpProfile[1];
  9838. if(strstr(chargingRateUnitStr, "W") != NULL)
  9839. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9840. else
  9841. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9842. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9843. {
  9844. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9845. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9846. }
  9847. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9848. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9849. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9850. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9851. {
  9852. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9853. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9854. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9855. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9856. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9857. {
  9858. confirmPeriods = idx;
  9859. break;
  9860. }
  9861. }
  9862. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9863. {
  9864. confirmPeriods += 1;
  9865. }
  9866. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9867. }
  9868. else
  9869. {
  9870. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9871. }
  9872. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9873. return result;
  9874. }
  9875. int handleGetConfigurationRequest(char *uuid, char *payload)
  9876. {
  9877. mtrace();
  9878. int result = FAIL;
  9879. int MaxKeySupported = 0;
  9880. int n_keys = 0;
  9881. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9882. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9883. json_object *GetConfiguration;
  9884. GetConfiguration = json_tokener_parse(payload);
  9885. if(!is_error(GetConfiguration))
  9886. {
  9887. // Optional data
  9888. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9889. {
  9890. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9891. {
  9892. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9893. n_keys = idx + 1;
  9894. }
  9895. }
  9896. }
  9897. json_object_put(GetConfiguration);
  9898. UnknownKeynum = 0;
  9899. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9900. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9901. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9902. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9903. if(n_keys != 0)
  9904. {
  9905. for(int i=0;i<n_keys;i++)
  9906. {
  9907. getKeyValue(requestKey[i]);
  9908. }
  9909. }
  9910. else
  9911. {
  9912. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9913. getKeyValue("");
  9914. }
  9915. processUnkownKey();
  9916. sendGetConfigurationConfirmation(uuid);
  9917. return result;
  9918. }
  9919. static char fnamePlusPath[100]={0};
  9920. static char fnamePWithNoPath[60]={0};
  9921. void checkUploadLog(void)
  9922. {
  9923. FILE *fp;
  9924. /* Open the command for reading. */
  9925. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9926. if (fp == NULL) {
  9927. DEBUG_WARN("Failed to run command\n" );
  9928. exit(1);
  9929. }
  9930. int ftppathlen = 0;
  9931. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9932. int i = 0;
  9933. /* Read the output a line at a time - output it. */
  9934. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9935. if(i==0)
  9936. {
  9937. ftppathlen = strlen(fnamePlusPath);
  9938. DEBUG_INFO("%s\n", fnamePlusPath);
  9939. fnamePlusPath[ftppathlen]='\0';
  9940. break;
  9941. }
  9942. i= i+1;
  9943. }
  9944. /* close */
  9945. pclose(fp);
  9946. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9947. {
  9948. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9949. {
  9950. fnamePlusPath[k]='\0';
  9951. }
  9952. }
  9953. i=1;
  9954. //char fname[60]={0};
  9955. while(i < ftppathlen)
  9956. {
  9957. int len=ftppathlen-i;
  9958. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9959. {
  9960. DEBUG_INFO("compare '/' all right\n");
  9961. break;
  9962. }
  9963. i=i+1;
  9964. }
  9965. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9966. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9967. fnamePWithNoPath[i+1] = '\0';
  9968. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9969. {
  9970. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9971. {
  9972. fnamePWithNoPath[j]='\0';
  9973. }
  9974. }
  9975. FILE* fp1 = fopen(fnamePlusPath, "r");
  9976. if (fp1)
  9977. {
  9978. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9979. // file exists
  9980. fclose(fp1);
  9981. }
  9982. else
  9983. {
  9984. // file doesn't exist
  9985. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9986. }
  9987. }
  9988. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9989. {
  9990. mtrace();
  9991. int result = FAIL;
  9992. time_t CurrentTime;
  9993. struct tm *tm;
  9994. pthread_t th_Status;
  9995. CurrentTime = time(NULL);
  9996. tm = localtime(&CurrentTime);
  9997. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9998. 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);
  9999. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10000. if(!interLock.isGetDiagnosticGoing)
  10001. {
  10002. interLock.isGetDiagnosticGoing = 1;
  10003. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10004. sleep(1);
  10005. }
  10006. else
  10007. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10008. return result;
  10009. }
  10010. void* GetDiagnosticsProcess(void* data)
  10011. {
  10012. pthread_detach(pthread_self());
  10013. mtrace();
  10014. int retriesInt=0, retryIntervalInt=0;
  10015. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10016. 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};
  10017. int port=0;
  10018. int isSuccess = FALSE;
  10019. char cmdBuf[2048];
  10020. struct tm *tmNow;
  10021. time_t CurrentTime;
  10022. struct tm tmStart;
  10023. struct tm tmStop;
  10024. CurrentTime = time(NULL);
  10025. tmNow=localtime(&CurrentTime);
  10026. uint16_t targetYear, targetMonth;
  10027. json_object *GetDiagnostics;
  10028. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10029. GetDiagnostics = json_tokener_parse(data);
  10030. if(!is_error(GetDiagnostics))
  10031. {
  10032. // Required data
  10033. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10034. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10035. // Optional data
  10036. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10037. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10038. else
  10039. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10040. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10041. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10042. else
  10043. retryIntervalInt = 30;
  10044. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10045. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10046. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10047. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10048. }
  10049. json_object_put(GetDiagnostics);
  10050. // Pack log to compress file
  10051. 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) &&
  10052. (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))
  10053. {
  10054. // Pack system log
  10055. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10056. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10057. targetYear = tmStart.tm_year;
  10058. targetMonth = tmStart.tm_mon;
  10059. do
  10060. {
  10061. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10062. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10063. if(targetMonth+1>=13)
  10064. {
  10065. targetYear += 1;
  10066. targetMonth = 1;
  10067. }
  10068. else
  10069. {
  10070. targetMonth += 1;
  10071. }
  10072. }while((targetYear < (tmNow->tm_year+1900)) ||
  10073. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10074. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10075. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10076. system(cmdBuf);
  10077. // Pack charging & event log
  10078. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10079. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10080. targetYear = tmStart.tm_year;
  10081. targetMonth = tmStart.tm_mon;
  10082. do
  10083. {
  10084. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10085. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10086. if(targetMonth+1>=13)
  10087. {
  10088. targetYear += 1;
  10089. targetMonth = 1;
  10090. }
  10091. else
  10092. {
  10093. targetMonth += 1;
  10094. }
  10095. }while((targetYear < (tmNow->tm_year+1900)) ||
  10096. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10097. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10098. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10099. system(cmdBuf);
  10100. // Combine log file
  10101. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10102. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10103. }
  10104. else
  10105. {
  10106. system("exec /root/logPackTools 'log' 6");
  10107. }
  10108. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10109. system(cmdBuf);
  10110. checkUploadLog();
  10111. //****************location*******************/
  10112. if(strcmp(locationstr,"")==0)
  10113. {
  10114. DEBUG_INFO("location is <Empty>!\n");
  10115. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10116. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10117. goto end;
  10118. }
  10119. memset(protocol, 0, ARRAY_SIZE(protocol));
  10120. memset(user, 0, ARRAY_SIZE(user) );
  10121. memset(password, 0, ARRAY_SIZE(password));
  10122. memset(host, 0, ARRAY_SIZE(host));
  10123. memset(path, 0, ARRAY_SIZE(path));
  10124. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10125. memset(host1, 0, ARRAY_SIZE(host1));
  10126. memset(path1, 0, ARRAY_SIZE(path1));
  10127. /*location: ftp://user:password@host:port/path*/
  10128. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10129. if((access(fnamePlusPath,F_OK))!=-1)
  10130. {
  10131. DEBUG_INFO("fnamePlusPath exist.\n");
  10132. }
  10133. else
  10134. {
  10135. DEBUG_INFO("fnamePlusPath not exist!\n");
  10136. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10137. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10138. goto end;
  10139. }
  10140. if(strchr(locationstr,'@')==NULL)
  10141. {
  10142. sscanf(locationstr,
  10143. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10144. protocol, host, &port, path);
  10145. strcpy(user,"anonymous");
  10146. strcpy(password,"");
  10147. }
  10148. else
  10149. {
  10150. //DEBUG_INFO("pch=%s\n", pch);
  10151. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10152. protocol, user, password, host, &port, path);
  10153. }
  10154. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10155. {
  10156. DEBUG_INFO("protocol is not ftp/http ! \n");
  10157. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10158. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10159. goto end;
  10160. }
  10161. if(strncmp(locationstr,"http", 4) == 0)
  10162. {
  10163. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10164. sprintf(ftppath,"/%s", path);
  10165. do
  10166. {
  10167. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10168. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10169. sleep(3);
  10170. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10171. if(!isSuccess)
  10172. {
  10173. DEBUG_INFO("Diagnostics fail.\n");
  10174. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10175. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10176. sleep(retryIntervalInt);
  10177. }
  10178. else
  10179. {
  10180. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10181. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10182. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10183. }
  10184. retriesInt--;
  10185. }while((isSuccess == 0)&&(retriesInt >= 0));
  10186. }
  10187. else
  10188. {
  10189. sscanf(host,"%[^/]%s",host1, path1);
  10190. if(strlen(path) > 0)
  10191. sprintf(ftppath,"/%s", path);
  10192. else
  10193. sprintf(ftppath,"/%s", path1);
  10194. int ftppathlen=strlen(ftppath);
  10195. int i=1;
  10196. char filenametemp[50];
  10197. while(i < ftppathlen)
  10198. {
  10199. int len=ftppathlen-i;
  10200. if(ftppath[len]== 47) // '/' ascll code: 47
  10201. {
  10202. DEBUG_INFO("find '/' all right\n");
  10203. break;
  10204. }
  10205. i=i+1;
  10206. }
  10207. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10208. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10209. filenametemp[i+1] = 0;
  10210. if(port == 0)
  10211. port = 21;
  10212. do
  10213. {
  10214. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10215. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10216. sleep(3);
  10217. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10218. if(!isSuccess)
  10219. {
  10220. DEBUG_INFO("Diagnostics fail.\n");
  10221. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10222. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10223. sleep(retryIntervalInt);
  10224. }
  10225. else
  10226. {
  10227. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10228. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10229. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10230. }
  10231. retriesInt--;
  10232. }while((!isSuccess)&&(retriesInt >= 0));
  10233. }
  10234. end:
  10235. system("rm -f /mnt/*");
  10236. sleep(5);
  10237. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10238. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10239. interLock.isGetDiagnosticGoing = 0;
  10240. pthread_exit(NULL);
  10241. }
  10242. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10243. {
  10244. mtrace();
  10245. int result = FAIL;
  10246. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10247. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10248. {
  10249. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10250. locallistVersion = -1;
  10251. }
  10252. else
  10253. {
  10254. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10255. OCPP_getListVerion();
  10256. }
  10257. //from db.OCPP_getListVerion
  10258. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10259. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10260. sendGetLocalListVersionConfirmation(uuid,"");
  10261. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10262. return result;
  10263. }
  10264. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10265. {
  10266. mtrace();
  10267. int result = FAIL;
  10268. int connectorIdInt=-1;
  10269. int tempIndex = 0;
  10270. int connectorIdIsNULL, chargingProfileIsNULL;
  10271. char comfirmstr[20]={0};
  10272. char cmdBuf[512];
  10273. json_object *RemoteStartTransaction;
  10274. FILE *fp;
  10275. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10276. if(server_pending == TRUE)
  10277. {
  10278. return 0;
  10279. }
  10280. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10281. RemoteStartTransaction = json_tokener_parse(payload);
  10282. if(!is_error(RemoteStartTransaction))
  10283. {
  10284. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10285. {
  10286. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10287. }
  10288. else
  10289. {
  10290. connectorIdIsNULL = TRUE;
  10291. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10292. {
  10293. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10294. {
  10295. connectorIdIsNULL = FALSE;
  10296. connectorIdInt = (gun_index+1);
  10297. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10298. break;
  10299. }
  10300. }
  10301. }
  10302. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10303. {
  10304. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10305. // Required data
  10306. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10307. // Optional data
  10308. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10309. {
  10310. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10311. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10312. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10313. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10314. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10315. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10316. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10317. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10318. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10319. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10320. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10321. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10322. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10323. {
  10324. 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")));
  10325. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10326. 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"));
  10327. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10328. 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"));
  10329. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10330. 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")));
  10331. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10332. {
  10333. 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++)
  10334. {
  10335. 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"));
  10336. 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"));
  10337. 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)
  10338. 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"));
  10339. }
  10340. }
  10341. }
  10342. }
  10343. else
  10344. {
  10345. chargingProfileIsNULL = TRUE;
  10346. }
  10347. }
  10348. }
  10349. else
  10350. {
  10351. connectorIdIsNULL = TRUE;
  10352. }
  10353. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10354. {
  10355. DEBUG_WARN("Connector id is NULL\n.");
  10356. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10357. goto end;
  10358. }
  10359. /*
  10360. enum _SYSTEM_STATUS
  10361. {
  10362. S_BOOTING = 0,
  10363. S_IDLE, = 1
  10364. S_AUTHORIZING, = 2
  10365. S_REASSIGN_CHECK, = 3
  10366. S_REASSIGN, = 4
  10367. S_PRECHARGE, = 5
  10368. S_PREPARING_FOR_EV, = 6
  10369. S_PREPARING_FOR_EVSE, = 7
  10370. S_CHARGING, = 8
  10371. S_TERMINATING, = 9
  10372. S_COMPLETE, = 10
  10373. S_ALARM, = 11
  10374. S_FAULT = 12
  10375. }
  10376. */
  10377. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10378. {
  10379. //check Transaction active
  10380. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10381. {
  10382. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10383. {
  10384. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10385. }
  10386. else
  10387. {
  10388. tempIndex = connectorIdInt -1;
  10389. }
  10390. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10391. {
  10392. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10393. {
  10394. 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))
  10395. {
  10396. //Reserved
  10397. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10398. }
  10399. 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))
  10400. {
  10401. //Reserved
  10402. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10403. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10404. goto end;
  10405. }
  10406. else
  10407. {
  10408. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10409. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10410. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10411. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10412. {
  10413. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10414. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10415. goto end;
  10416. }
  10417. }//END FOR ELSE
  10418. }
  10419. }// END FOR CHAdeMO_QUANTITY
  10420. }
  10421. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10422. {
  10423. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10424. {
  10425. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10426. }
  10427. else
  10428. {
  10429. tempIndex = connectorIdInt -1;
  10430. }
  10431. for (int index = 0; index < CCS_QUANTITY; index++)
  10432. {
  10433. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10434. {
  10435. 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))
  10436. {
  10437. //Reserved
  10438. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10439. }
  10440. 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))
  10441. {
  10442. //Reserved
  10443. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10444. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10445. goto end;
  10446. }
  10447. else
  10448. {
  10449. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10450. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10451. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10452. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10453. {
  10454. DEBUG_WARN("CCS connector not allow start\n.");
  10455. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10456. goto end;
  10457. }
  10458. }// END FOR ELSE
  10459. }
  10460. }// END FOR CCS_QUANTITY
  10461. }
  10462. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10463. {
  10464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10465. {
  10466. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10467. }
  10468. else
  10469. {
  10470. tempIndex = connectorIdInt -1;
  10471. }
  10472. for (int index = 0; index < GB_QUANTITY; index++)
  10473. {
  10474. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10475. {
  10476. 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))
  10477. {
  10478. //Reserved
  10479. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10480. }
  10481. 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))
  10482. {
  10483. //Reserved
  10484. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10485. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10486. goto end;
  10487. }
  10488. else
  10489. {
  10490. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10491. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10492. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10493. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10494. {
  10495. DEBUG_WARN("GB connector not allow start\n.");
  10496. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10497. goto end;
  10498. }
  10499. }// END FOR ELSE
  10500. }
  10501. } // END FOR GB_QUANTITY
  10502. }
  10503. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10504. {
  10505. tempIndex = connectorIdInt -1;
  10506. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10507. {
  10508. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10509. {
  10510. 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))
  10511. {
  10512. //Reserved
  10513. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10514. }
  10515. 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))
  10516. {
  10517. //Reserved
  10518. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10519. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10520. goto end;
  10521. }
  10522. else
  10523. {
  10524. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10525. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10526. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10527. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10528. {
  10529. DEBUG_WARN("GB connector not allow start\n.");
  10530. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10531. goto end;
  10532. }
  10533. }// END FOR ELSE
  10534. }
  10535. } // END FOR GB_QUANTITY
  10536. }
  10537. else
  10538. {
  10539. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10540. {
  10541. tempIndex = 2;
  10542. }
  10543. else
  10544. {
  10545. tempIndex = connectorIdInt -1;
  10546. }
  10547. for (int index = 0; index < AC_QUANTITY; index++)
  10548. {
  10549. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10550. {
  10551. 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))
  10552. {
  10553. //Reserved
  10554. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10555. }
  10556. 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))
  10557. {
  10558. //Reserved
  10559. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10560. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10561. goto end;
  10562. }
  10563. else
  10564. {
  10565. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10566. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10567. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10568. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10569. {
  10570. DEBUG_WARN("AC connector not allow start\n.");
  10571. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10572. goto end;
  10573. }
  10574. }//END FOR ELSE
  10575. }
  10576. }// END FOR AC_QUANTITY
  10577. }
  10578. if(chargingProfileIsNULL == FALSE)
  10579. {
  10580. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10581. {
  10582. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10583. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10584. //memset idTag
  10585. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10586. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10587. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10588. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10589. // Save profile to file
  10590. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10591. system(cmdBuf);
  10592. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10593. fp = fopen(cmdBuf, "w");
  10594. 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));
  10595. fclose(fp);
  10596. }
  10597. else
  10598. {
  10599. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10600. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10601. }
  10602. }
  10603. else
  10604. {
  10605. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10606. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10607. //memset idTag
  10608. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10609. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10610. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10611. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10612. }
  10613. }
  10614. else
  10615. {
  10616. DEBUG_WARN("Connector id over\n.");
  10617. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10618. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10619. }
  10620. end:
  10621. json_object_put(RemoteStartTransaction);
  10622. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10623. {
  10624. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10625. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10626. }
  10627. //OCPP send RemoteStartConfirmation by first.
  10628. sendRemoteStartConfirmation(uuid, comfirmstr);
  10629. return result;
  10630. }
  10631. int handleRemoteStartRequest(char *uuid, char *payload)
  10632. {
  10633. mtrace();
  10634. int result = PASS;
  10635. int connectorIdInt=-1;
  10636. int tempIndex = 0;
  10637. char comfirmstr[20]={0};
  10638. char cmdBuf[512];
  10639. json_object *RemoteStartTransaction;
  10640. FILE *fp;
  10641. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10642. if(server_pending == TRUE)
  10643. {
  10644. result = FAIL;
  10645. }
  10646. RemoteStartTransaction = json_tokener_parse(payload);
  10647. if(!is_error(RemoteStartTransaction))
  10648. {
  10649. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10650. {
  10651. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10652. }
  10653. else
  10654. {
  10655. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10656. {
  10657. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10658. {
  10659. connectorIdInt = (gun_index+1);
  10660. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10661. break;
  10662. }
  10663. }
  10664. }
  10665. if(connectorIdInt == 0)
  10666. {
  10667. DEBUG_WARN("Connector id shall not equal 0.\n");
  10668. result = FAIL;
  10669. }
  10670. else if(connectorIdInt == -1)
  10671. {
  10672. DEBUG_INFO("Connector id does not specific.\n");
  10673. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10674. {
  10675. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10676. // Required data
  10677. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10678. // Optional data
  10679. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10680. {
  10681. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10682. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10683. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10684. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10685. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10686. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10687. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10688. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10689. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10690. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10691. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10692. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10693. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10694. {
  10695. 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")));
  10696. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10697. 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"));
  10698. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10699. 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"));
  10700. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10701. 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")));
  10702. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10703. {
  10704. 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++)
  10705. {
  10706. 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"));
  10707. 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"));
  10708. 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)
  10709. 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"));
  10710. }
  10711. }
  10712. }
  10713. }
  10714. else
  10715. {
  10716. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10717. }
  10718. }
  10719. }
  10720. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10721. {
  10722. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10723. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10724. // Required data
  10725. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10726. // Optional data
  10727. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10728. {
  10729. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10730. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10731. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10732. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10733. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10734. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10735. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10736. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10737. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10738. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10739. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10740. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10741. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10742. {
  10743. 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")));
  10744. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10745. 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"));
  10746. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10747. 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"));
  10748. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10749. 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")));
  10750. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10751. {
  10752. 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++)
  10753. {
  10754. 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"));
  10755. 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"));
  10756. 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)
  10757. 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"));
  10758. }
  10759. }
  10760. }
  10761. }
  10762. else
  10763. {
  10764. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10765. }
  10766. }
  10767. else
  10768. {
  10769. DEBUG_WARN("Connector id is over maximun value.\n");
  10770. result = FAIL;
  10771. }
  10772. }
  10773. if(result == PASS)
  10774. {
  10775. if(connectorIdInt > 0)
  10776. {
  10777. //check Transaction active
  10778. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10779. {
  10780. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10781. {
  10782. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10783. }
  10784. else
  10785. {
  10786. tempIndex = connectorIdInt -1;
  10787. }
  10788. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10789. {
  10790. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10791. {
  10792. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10793. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10794. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10795. {
  10796. //Reserved
  10797. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10798. }
  10799. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10800. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10801. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10802. {
  10803. //Reserved
  10804. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10805. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10806. goto end;
  10807. }
  10808. else
  10809. {
  10810. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10811. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10812. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10813. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10814. {
  10815. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10816. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10817. goto end;
  10818. }
  10819. }//END FOR ELSE
  10820. }
  10821. }// END FOR CHAdeMO_QUANTITY
  10822. }
  10823. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10824. {
  10825. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10826. {
  10827. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10828. }
  10829. else
  10830. {
  10831. tempIndex = connectorIdInt -1;
  10832. }
  10833. for (int index = 0; index < CCS_QUANTITY; index++)
  10834. {
  10835. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10836. {
  10837. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10838. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10839. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10840. {
  10841. //Reserved
  10842. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10843. }
  10844. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10845. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10846. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10847. {
  10848. //Reserved
  10849. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10850. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10851. goto end;
  10852. }
  10853. else
  10854. {
  10855. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10856. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10857. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10858. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10859. {
  10860. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10861. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10862. goto end;
  10863. }
  10864. }// END FOR ELSE
  10865. }
  10866. }// END FOR CCS_QUANTITY
  10867. }
  10868. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10869. {
  10870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10871. {
  10872. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10873. }
  10874. else
  10875. {
  10876. tempIndex = connectorIdInt -1;
  10877. }
  10878. for (int index = 0; index < GB_QUANTITY; index++)
  10879. {
  10880. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10881. {
  10882. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10883. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10884. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10885. {
  10886. //Reserved
  10887. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10888. }
  10889. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10890. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10891. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10892. {
  10893. //Reserved
  10894. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10895. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10896. goto end;
  10897. }
  10898. else
  10899. {
  10900. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10901. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10902. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10903. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10904. {
  10905. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10906. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10907. goto end;
  10908. }
  10909. }// END FOR ELSE
  10910. }
  10911. } // END FOR GB_QUANTITY
  10912. }
  10913. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10914. {
  10915. tempIndex = connectorIdInt -1;
  10916. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10917. {
  10918. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10919. {
  10920. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10921. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10922. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10923. {
  10924. //Reserved
  10925. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10926. }
  10927. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10928. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10929. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10930. {
  10931. //Reserved
  10932. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10933. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10934. goto end;
  10935. }
  10936. else
  10937. {
  10938. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10939. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10940. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10941. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10942. {
  10943. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10944. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10945. goto end;
  10946. }
  10947. }// END FOR ELSE
  10948. }
  10949. } // END FOR GB_QUANTITY
  10950. }
  10951. else
  10952. {
  10953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10954. {
  10955. tempIndex = 2;
  10956. }
  10957. else
  10958. {
  10959. tempIndex = connectorIdInt -1;
  10960. }
  10961. for (int index = 0; index < AC_QUANTITY; index++)
  10962. {
  10963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10964. {
  10965. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10966. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10967. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10968. {
  10969. //Reserved
  10970. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10971. }
  10972. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10973. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10974. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10975. {
  10976. //Reserved
  10977. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10978. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10979. goto end;
  10980. }
  10981. else
  10982. {
  10983. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10984. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10985. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10986. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10987. {
  10988. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10989. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10990. goto end;
  10991. }
  10992. }//END FOR ELSE
  10993. }
  10994. }// END FOR AC_QUANTITY
  10995. }
  10996. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10997. {
  10998. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10999. {
  11000. // Save profile to file
  11001. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11002. system(cmdBuf);
  11003. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11004. fp = fopen(cmdBuf, "w");
  11005. 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));
  11006. fclose(fp);
  11007. }
  11008. else
  11009. {
  11010. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11011. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11012. goto end;
  11013. }
  11014. }
  11015. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11016. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11017. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11018. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11019. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11020. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11021. }
  11022. else
  11023. {
  11024. uint8_t isHasIdleConnector = FALSE;
  11025. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11026. {
  11027. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11028. {
  11029. isHasIdleConnector = TRUE;
  11030. break;
  11031. }
  11032. }
  11033. if(isHasIdleConnector == TRUE)
  11034. {
  11035. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11036. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11037. {
  11038. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11039. {
  11040. // Save profile to file
  11041. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11042. system(cmdBuf);
  11043. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11044. fp = fopen(cmdBuf, "w");
  11045. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11046. fclose(fp);
  11047. refreshStartTimer(&clientTime.RemoteStartWait);
  11048. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11049. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11050. }
  11051. else
  11052. {
  11053. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11054. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11055. }
  11056. }
  11057. else
  11058. {
  11059. refreshStartTimer(&clientTime.RemoteStartWait);
  11060. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11061. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11062. }
  11063. }
  11064. else
  11065. {
  11066. DEBUG_INFO("There is not any connector is idle.\n");
  11067. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11068. }
  11069. }
  11070. }
  11071. else
  11072. {
  11073. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11074. }
  11075. end:
  11076. json_object_put(RemoteStartTransaction);
  11077. sendRemoteStartConfirmation(uuid, comfirmstr);
  11078. return result;
  11079. }
  11080. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11081. {
  11082. mtrace();
  11083. int result = FAIL;
  11084. int match = FALSE;
  11085. int GunNO = 0;
  11086. int tempIndex = 0;
  11087. int transactionIdInt=0;
  11088. int transactionIdIsNULL= TRUE;
  11089. char comfirmstr[20];
  11090. json_object *RemoteStopTransaction;
  11091. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11092. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11093. if(server_pending == TRUE)
  11094. {
  11095. return 0;
  11096. }
  11097. RemoteStopTransaction = json_tokener_parse(payload);
  11098. if(!is_error(RemoteStopTransaction))
  11099. {
  11100. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11101. {
  11102. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11103. transactionIdIsNULL = FALSE;
  11104. }
  11105. }
  11106. json_object_put(RemoteStopTransaction);
  11107. if(transactionIdIsNULL == FALSE)
  11108. {
  11109. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11110. {
  11111. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11112. {
  11113. //check Transaction active
  11114. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11115. {
  11116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11117. {
  11118. tempIndex = ((gun_index==2) ? 1: 0);
  11119. }
  11120. else
  11121. {
  11122. tempIndex = gun_index;
  11123. }
  11124. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11125. {
  11126. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11127. {
  11128. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11129. {
  11130. match = TRUE;
  11131. GunNO = gun_index;
  11132. }
  11133. }
  11134. }// END FOR CHAdeMO_QUANTITY
  11135. }
  11136. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11137. {
  11138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11139. {
  11140. tempIndex = ((gun_index==2) ? 1: 0);
  11141. }
  11142. else
  11143. {
  11144. tempIndex = gun_index;
  11145. }
  11146. for (int index = 0; index < CCS_QUANTITY; index++)
  11147. {
  11148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11149. {
  11150. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11151. {
  11152. match = TRUE;
  11153. GunNO = gun_index;
  11154. }
  11155. }
  11156. }// END FOR CCS_QUANTITY
  11157. }
  11158. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11159. {
  11160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11161. {
  11162. tempIndex = ((gun_index==2) ? 1: 0);
  11163. }
  11164. else
  11165. {
  11166. tempIndex = gun_index;
  11167. }
  11168. for (int index = 0; index < GB_QUANTITY; index++)
  11169. {
  11170. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11171. {
  11172. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11173. {
  11174. match = TRUE;
  11175. GunNO = gun_index;
  11176. }
  11177. }
  11178. }// END FOR GB_QUANTITY
  11179. }
  11180. else if(gunType[gun_index] == GUN_TYPE_DO)
  11181. {
  11182. tempIndex = gun_index;
  11183. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11184. {
  11185. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11186. {
  11187. 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
  11188. {
  11189. match = TRUE;
  11190. GunNO = gun_index;
  11191. }
  11192. }
  11193. }// END FOR GB_QUANTITY
  11194. }
  11195. else
  11196. {
  11197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11198. {
  11199. tempIndex = 2;
  11200. }
  11201. else
  11202. {
  11203. tempIndex = gun_index;
  11204. }
  11205. for (int index = 0; index < AC_QUANTITY; index++)
  11206. {
  11207. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11208. {
  11209. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11210. {
  11211. match = TRUE;
  11212. GunNO = gun_index;
  11213. }
  11214. }
  11215. }// END FOR CHAdeMO_QUANTITY
  11216. } // END FOR AC ELSE
  11217. }// CHECK IF ResponseTransactionId == transactionIdInt
  11218. }//END FOR
  11219. if( match == TRUE)
  11220. {
  11221. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11222. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11223. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11224. }
  11225. else
  11226. {
  11227. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11228. }
  11229. }
  11230. else
  11231. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11232. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11233. return result;
  11234. }
  11235. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11236. {
  11237. mtrace();
  11238. int result = FAIL;
  11239. int connectorIdInt=0, reservationIdInt=0;
  11240. int tempIndex = 0;
  11241. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11242. char comfirmstr[20]={0};
  11243. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11244. int c = 0;
  11245. char *loc;
  11246. //char *ptr;
  11247. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11248. strcpy(sstrtemp, stringtrimspace(payload));
  11249. //***(1)connectorId ****/
  11250. c=0;
  11251. loc = strstr(sstrtemp, "connectorId");
  11252. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11253. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11254. {
  11255. sstr[c] = loc[strlen("connectorId")+2+c];
  11256. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11257. c++;
  11258. }
  11259. sstr[c] = '\0';
  11260. connectorIdInt = atoi(sstr);
  11261. //***(2)expiryDate ****/
  11262. loc = strstr(sstrtemp, "expiryDate");
  11263. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11264. c = 0;
  11265. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11266. {
  11267. sstr[c] = loc[3+strlen("expiryDate")+c];
  11268. c++;
  11269. }
  11270. sstr[c] = '\0';
  11271. strcpy(expiryDatestr, sstr);
  11272. //***(3)idTag ****/
  11273. loc = strstr(sstrtemp, "idTag");
  11274. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11275. c = 0;
  11276. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11277. {
  11278. sstr[c] = loc[3+strlen("idTag")+c];
  11279. c++;
  11280. }
  11281. sstr[c] = '\0';
  11282. strcpy(idTagstr, sstr);
  11283. //***(4)parentIdTag ****/
  11284. loc = strstr(sstrtemp, "parentIdTag");
  11285. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11286. c = 0;
  11287. if(loc == NULL)
  11288. {
  11289. strcpy(parentIdTagstr, "");
  11290. }
  11291. else
  11292. {
  11293. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11294. {
  11295. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11296. c++;
  11297. }
  11298. sstr[c] = '\0';
  11299. strcpy(parentIdTagstr, sstr);
  11300. }
  11301. //***(5)reservationId ****/
  11302. c=0;
  11303. loc = strstr(sstrtemp, "reservationId");
  11304. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11305. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11306. {
  11307. sstr[c] = loc[strlen("reservationId")+2+c];
  11308. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11309. c++;
  11310. }
  11311. sstr[c] = '\0';
  11312. reservationIdInt = atoi(sstr);
  11313. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11314. /*
  11315. enum SYSTEM_STATUS
  11316. {
  11317. SYS_MODE_BOOTING = 0,
  11318. SYS_MODE_IDLE = 1,
  11319. SYS_MODE_AUTHORIZING = 2,
  11320. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11321. SYS_MODE_REASSIGN = 4,
  11322. SYS_MODE_PREPARING = 5,
  11323. SYS_MODE_PREPARE_FOR_EV = 6,
  11324. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11325. SYS_MODE_CHARGING = 8,
  11326. SYS_MODE_TERMINATING = 9,
  11327. SYS_MODE_COMPLETE = 10,
  11328. SYS_MODE_ALARM = 11,
  11329. SYS_MODE_FAULT = 12,
  11330. SYS_MODE_RESERVATION = 13,
  11331. SYS_MODE_BOOKING = 14,
  11332. SYS_MODE_MAINTAIN = 15,
  11333. SYS_MODE_DEBUG = 16,
  11334. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11335. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11336. SYS_MODE_UPDATE = 19
  11337. };
  11338. */
  11339. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11340. {
  11341. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11342. goto end;
  11343. }
  11344. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11345. {
  11346. //check Transaction active
  11347. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11348. {
  11349. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11350. {
  11351. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11352. }
  11353. else
  11354. {
  11355. tempIndex = connectorIdInt -1;
  11356. }
  11357. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11358. {
  11359. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11360. {
  11361. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11362. {
  11363. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11364. {
  11365. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11366. {
  11367. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11368. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11369. }
  11370. 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'))
  11371. {
  11372. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11373. }
  11374. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11375. {
  11376. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11377. }
  11378. else
  11379. {
  11380. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11381. }
  11382. }
  11383. 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
  11384. {
  11385. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11386. }
  11387. }
  11388. else
  11389. {
  11390. //replace reservation
  11391. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11392. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11393. }
  11394. }
  11395. } // END FOR CHAdeMO_QUANTITY
  11396. }
  11397. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11398. {
  11399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11400. {
  11401. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11402. }
  11403. else
  11404. {
  11405. tempIndex = connectorIdInt -1;
  11406. }
  11407. for (int index = 0; index < CCS_QUANTITY; index++)
  11408. {
  11409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11410. {
  11411. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11412. {
  11413. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11414. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11415. {
  11416. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11417. {
  11418. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11419. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11420. }
  11421. 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'))
  11422. {
  11423. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11424. }
  11425. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11426. {
  11427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11428. }
  11429. else
  11430. {
  11431. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11432. }
  11433. }
  11434. 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
  11435. {
  11436. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11437. }
  11438. }
  11439. else
  11440. {
  11441. //replace reservation
  11442. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11443. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11444. }
  11445. }
  11446. } // END FOR CCS_QUANTITY
  11447. }
  11448. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11449. {
  11450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11451. {
  11452. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11453. }
  11454. else
  11455. {
  11456. tempIndex = connectorIdInt -1;
  11457. }
  11458. for (int index = 0; index < GB_QUANTITY; index++)
  11459. {
  11460. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11461. {
  11462. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11463. {
  11464. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11465. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11466. {
  11467. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11468. {
  11469. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11470. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11471. }
  11472. 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'))
  11473. {
  11474. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11475. }
  11476. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11477. {
  11478. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11479. }
  11480. else
  11481. {
  11482. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11483. }
  11484. }
  11485. 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
  11486. {
  11487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11488. }
  11489. }
  11490. else
  11491. {
  11492. //replace reservation
  11493. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11495. }
  11496. }
  11497. }// END FOR GB_QUANTITY
  11498. }
  11499. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11500. {
  11501. tempIndex = connectorIdInt -1;
  11502. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11503. {
  11504. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11505. {
  11506. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11507. {
  11508. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11509. 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
  11510. {
  11511. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11512. {
  11513. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11514. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11515. }
  11516. 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'))
  11517. {
  11518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11519. }
  11520. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11521. {
  11522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11523. }
  11524. else
  11525. {
  11526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11527. }
  11528. }
  11529. 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
  11530. {
  11531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11532. }
  11533. }
  11534. else
  11535. {
  11536. //replace reservation
  11537. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11539. }
  11540. }
  11541. }// END FOR GB_QUANTITY
  11542. }
  11543. else
  11544. {
  11545. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11546. {
  11547. tempIndex = 2;
  11548. }
  11549. else
  11550. {
  11551. tempIndex = (connectorIdInt -1);
  11552. }
  11553. for (int index = 0; index < AC_QUANTITY; index++)
  11554. {
  11555. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11556. {
  11557. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11558. {
  11559. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11560. {
  11561. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11562. {
  11563. 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))
  11564. {
  11565. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11566. }
  11567. else
  11568. {
  11569. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11571. }
  11572. }
  11573. 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'))
  11574. {
  11575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11576. }
  11577. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11578. {
  11579. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11580. }
  11581. else
  11582. {
  11583. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11584. }
  11585. }
  11586. 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
  11587. {
  11588. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11589. }
  11590. }
  11591. else
  11592. {
  11593. //replace reservation
  11594. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11596. }
  11597. }
  11598. } // END FOR AC_QUANTITY
  11599. }
  11600. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11601. }
  11602. else if(connectorIdInt == 0)
  11603. {
  11604. //check Transaction active
  11605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11606. {
  11607. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11608. {
  11609. 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'))
  11610. {
  11611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11612. goto end;
  11613. }
  11614. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11615. {
  11616. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11617. goto end;
  11618. }
  11619. 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
  11620. {
  11621. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11622. goto end;
  11623. }
  11624. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11625. {
  11626. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11627. goto end;
  11628. }
  11629. }
  11630. }// END FOR CHAdeMO_QUANTITY
  11631. for (int index = 0; index < CCS_QUANTITY; index++)
  11632. {
  11633. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11634. {
  11635. 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'))
  11636. {
  11637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11638. goto end;
  11639. }
  11640. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11641. {
  11642. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11643. goto end;
  11644. }
  11645. 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
  11646. {
  11647. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11648. goto end;
  11649. }
  11650. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11651. {
  11652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11653. goto end;
  11654. }
  11655. }
  11656. } // END FOR CCS_QUANTITY
  11657. for (int index = 0; index < GB_QUANTITY; index++)
  11658. {
  11659. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11660. {
  11661. 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'))
  11662. {
  11663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11664. goto end;
  11665. }
  11666. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11667. {
  11668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11669. goto end;
  11670. }
  11671. 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
  11672. {
  11673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11674. goto end;
  11675. }
  11676. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11677. {
  11678. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11679. goto end;
  11680. }
  11681. }
  11682. } // END FOR GB_QUANTITY
  11683. for (int index = 0; index < AC_QUANTITY; index++)
  11684. {
  11685. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11686. {
  11687. 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'))
  11688. {
  11689. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11690. goto end;
  11691. }
  11692. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11693. {
  11694. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11695. goto end;
  11696. }
  11697. 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
  11698. {
  11699. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11700. goto end;
  11701. }
  11702. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11703. {
  11704. 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))
  11705. {
  11706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11707. goto end;
  11708. }
  11709. }
  11710. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11711. {
  11712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11713. goto end;
  11714. }
  11715. }
  11716. }// END FOR AC_QUANTITY
  11717. //The connectorId is 0
  11718. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11720. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11721. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11722. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11723. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11724. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11725. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11726. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11727. result = TRUE;
  11728. return result;
  11729. }
  11730. else
  11731. {
  11732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11733. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11734. }
  11735. if(strcmp(comfirmstr,"Accepted") == 0)
  11736. {
  11737. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11738. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11739. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11740. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11741. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11742. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11743. result = TRUE;
  11744. return result;
  11745. }
  11746. end:
  11747. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11748. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11749. return result;
  11750. }
  11751. int handleResetRequest(char *uuid, char *payload)
  11752. {
  11753. mtrace();
  11754. int result = FAIL;
  11755. char sstr[10]={0},sstrtemp[30]={ 0 };
  11756. char typestr[10]={0};
  11757. char comfirmstr[20]={0};
  11758. int c = 0;
  11759. char *loc;
  11760. DEBUG_INFO("handleResetRequest...\n");
  11761. strcpy(sstrtemp, stringtrimspace(payload));
  11762. loc = strstr(sstrtemp, "type");
  11763. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11764. c = 0;
  11765. while (loc[3+strlen("type")+c] != '\"')
  11766. {
  11767. sstr[c] = loc[3+strlen("type")+c];
  11768. c++;
  11769. }
  11770. sstr[c] = '\0';
  11771. strcpy(typestr,sstr);
  11772. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11773. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11774. {
  11775. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11776. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11777. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11778. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11779. }
  11780. else
  11781. {
  11782. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11783. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11784. result = PASS;
  11785. }
  11786. sendResetConfirmation(uuid, comfirmstr);
  11787. return result;
  11788. }
  11789. int handleSendLocalListRequest(char *uuid, char *payload)
  11790. {
  11791. mtrace();
  11792. int result = FAIL;
  11793. char comfirmstr[20];
  11794. int checkState_Faulted = FALSE;
  11795. json_object *SendLocalList;
  11796. DEBUG_INFO("handleSendLocalListRequest...\n");
  11797. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11798. {
  11799. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11800. goto end;
  11801. }
  11802. //check Charge Point state
  11803. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11804. {
  11805. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11806. {
  11807. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11808. }
  11809. }
  11810. for (int index = 0; index < CCS_QUANTITY; index++)
  11811. {
  11812. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11813. {
  11814. checkState_Faulted = TRUE; //OCPP Status
  11815. }
  11816. }
  11817. for (int index = 0; index < GB_QUANTITY; index++)
  11818. {
  11819. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11820. {
  11821. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11822. }
  11823. }
  11824. //check Charge Point state
  11825. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11826. {
  11827. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11828. {
  11829. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11830. }
  11831. }
  11832. //check Charge Point state
  11833. for (int index = 0; index < AC_QUANTITY; index++)
  11834. {
  11835. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11836. {
  11837. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11838. }
  11839. }
  11840. if(checkState_Faulted == TRUE)
  11841. {
  11842. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11843. goto end;
  11844. }
  11845. // Parsing payload
  11846. SendLocalList = json_tokener_parse(payload);
  11847. if(!is_error(SendLocalList))
  11848. {
  11849. // Required data
  11850. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11851. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11852. // Optional data
  11853. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11854. {
  11855. //Check UpdateType
  11856. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11857. {
  11858. //Local list full update
  11859. DEBUG_INFO("Local list full update.\n");
  11860. OCPP_getListVerion();
  11861. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11862. {
  11863. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11864. goto end;
  11865. }
  11866. OCPP_cleanLocalList();
  11867. }
  11868. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11869. {
  11870. //Local list different update
  11871. DEBUG_INFO("Local list different update.\n");
  11872. OCPP_getListVerion();
  11873. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11874. {
  11875. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11876. goto end;
  11877. }
  11878. }
  11879. else
  11880. {
  11881. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11882. goto end;
  11883. }
  11884. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11885. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11886. {
  11887. 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")));
  11888. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11889. {
  11890. 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")));
  11891. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11892. 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")));
  11893. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11894. 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")));
  11895. }
  11896. // Add to db
  11897. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11898. {
  11899. //Local list full update
  11900. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11901. idx,
  11902. ShmOCPP16Data->SendLocalList.ListVersion,
  11903. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11904. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11905. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11906. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11907. // update list
  11908. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11909. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11910. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11911. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11912. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11913. }
  11914. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11915. {
  11916. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11917. idx,
  11918. ShmOCPP16Data->SendLocalList.ListVersion,
  11919. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11920. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11921. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11922. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11923. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11924. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11925. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11926. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11927. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11928. }
  11929. }
  11930. }
  11931. else
  11932. {
  11933. //Check UpdateType
  11934. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11935. {
  11936. //Local list full update
  11937. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11938. OCPP_cleanLocalList();
  11939. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11940. goto end;
  11941. }
  11942. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11943. {
  11944. //Local list different update
  11945. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11946. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11947. goto end;
  11948. }
  11949. }
  11950. result = PASS;
  11951. }
  11952. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11953. end:
  11954. json_object_put(SendLocalList);
  11955. sendSendLocalListConfirmation(uuid, comfirmstr);
  11956. return result;
  11957. }
  11958. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11959. {
  11960. mtrace();
  11961. int result = FAIL;
  11962. struct StructSetChargingProfile SetProfileReq = {0};
  11963. int tempchargingProfileIdInt;
  11964. int tempstackLevelInt;
  11965. int chargingSchedulePeriodCount = 0;
  11966. char comfirmstr[20]={0};
  11967. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11968. char rmFileCmd[128]={0};
  11969. int profileQuantity = 0;
  11970. int isReplaceable = FALSE;
  11971. json_object *SetChargingProfile;
  11972. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11973. SetChargingProfile = json_tokener_parse(payload);
  11974. if(!is_error(SetChargingProfile))
  11975. {
  11976. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11977. {
  11978. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11979. }
  11980. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11981. {
  11982. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11983. {
  11984. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11985. }
  11986. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11987. {
  11988. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11989. }
  11990. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11991. {
  11992. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11993. }
  11994. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11995. {
  11996. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11997. }
  11998. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11999. {
  12000. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12001. }
  12002. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12003. {
  12004. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12005. }
  12006. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12007. {
  12008. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12009. }
  12010. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12011. {
  12012. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12013. }
  12014. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12015. {
  12016. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12017. {
  12018. 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")));
  12019. }
  12020. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12021. {
  12022. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12023. }
  12024. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12025. {
  12026. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12027. }
  12028. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12029. {
  12030. 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")));
  12031. }
  12032. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12033. {
  12034. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12035. if(chargingSchedulePeriodCount <= 10)
  12036. {
  12037. 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++)
  12038. {
  12039. 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)
  12040. {
  12041. 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"));
  12042. }
  12043. 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)
  12044. {
  12045. 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"));
  12046. }
  12047. 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)
  12048. {
  12049. 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"));
  12050. }
  12051. }
  12052. }
  12053. }
  12054. }
  12055. }
  12056. }
  12057. // Profile periods quantity check
  12058. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12059. {
  12060. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12061. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12062. goto end;
  12063. }
  12064. // Check invalid limit
  12065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12066. {
  12067. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12068. {
  12069. 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)))) ||
  12070. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12071. {
  12072. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12073. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12074. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12075. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12076. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12077. goto end;
  12078. }
  12079. }
  12080. }
  12081. else
  12082. {
  12083. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12084. {
  12085. 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))
  12086. {
  12087. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12088. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12089. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12090. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12091. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12092. goto end;
  12093. }
  12094. }
  12095. }
  12096. // Profile purpose info check
  12097. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12098. {
  12099. FILE *fp;
  12100. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12101. if(SetProfileReq.ConnectorId != 0)
  12102. {
  12103. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12104. DEBUG_WARN("Profile connector id is not 0.\n");
  12105. goto end;
  12106. }
  12107. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12108. if (!fp)
  12109. {
  12110. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12111. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12112. }
  12113. else
  12114. {
  12115. char *line = NULL;
  12116. size_t len = 0;
  12117. while(getline(&line, &len, fp) != -1)
  12118. {
  12119. json_object *obj = NULL;
  12120. obj = json_tokener_parse(line);
  12121. if(is_error(obj))
  12122. {
  12123. DEBUG_ERROR("Parse txProfile from file error.\n");
  12124. }
  12125. else
  12126. {
  12127. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12128. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12129. {
  12130. profileQuantity += 1;
  12131. }
  12132. else
  12133. isReplaceable = TRUE;
  12134. }
  12135. }
  12136. }
  12137. fclose(fp);
  12138. }
  12139. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12140. {
  12141. FILE *fp;
  12142. char filename[128]={0};
  12143. int tmpProfileQuantity;
  12144. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12145. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12146. {
  12147. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12148. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12149. goto end;
  12150. }
  12151. if(SetProfileReq.ConnectorId == 0)
  12152. {
  12153. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12154. {
  12155. tmpProfileQuantity = 0;
  12156. memset(filename, 0, ARRAY_SIZE(filename));
  12157. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12158. fp = fopen(filename, "r");
  12159. if (!fp)
  12160. {
  12161. DEBUG_INFO("%s does not create.\n", filename);
  12162. fp = fopen(filename, "w+");
  12163. }
  12164. else
  12165. {
  12166. char *line = NULL;
  12167. size_t len = 0;
  12168. while(getline(&line, &len, fp) != -1)
  12169. {
  12170. json_object *obj = NULL;
  12171. obj = json_tokener_parse(line);
  12172. if(is_error(obj))
  12173. {
  12174. DEBUG_ERROR("Parse txProfile from file error.\n");
  12175. }
  12176. else
  12177. {
  12178. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12179. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12180. {
  12181. tmpProfileQuantity += 1;
  12182. }
  12183. else
  12184. isReplaceable = TRUE;
  12185. }
  12186. }
  12187. }
  12188. fclose(fp);
  12189. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12190. }
  12191. }
  12192. else
  12193. {
  12194. memset(filename, 0, ARRAY_SIZE(filename));
  12195. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12196. fp = fopen(filename, "r");
  12197. if (!fp)
  12198. {
  12199. DEBUG_INFO("%s does not create.\n", filename);
  12200. fp = fopen(filename, "w+");
  12201. }
  12202. else
  12203. {
  12204. char *line = NULL;
  12205. size_t len = 0;
  12206. while(getline(&line, &len, fp) != -1)
  12207. {
  12208. json_object *obj = NULL;
  12209. obj = json_tokener_parse(line);
  12210. if(is_error(obj))
  12211. {
  12212. DEBUG_ERROR("Parse txProfile from file error.\n");
  12213. }
  12214. else
  12215. {
  12216. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12217. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12218. {
  12219. profileQuantity += 1;
  12220. }
  12221. else
  12222. isReplaceable = TRUE;
  12223. }
  12224. }
  12225. }
  12226. fclose(fp);
  12227. }
  12228. }
  12229. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12230. {
  12231. int isMatchTransactiodId= FALSE;
  12232. FILE *fp;
  12233. char filename[128]={0};
  12234. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12235. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12236. if(SetProfileReq.ConnectorId == 0)
  12237. {
  12238. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12239. DEBUG_WARN("Profile connector id is 0.\n");
  12240. goto end;
  12241. }
  12242. int tempIndex = 0;
  12243. //check Transaction active
  12244. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12245. {
  12246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12247. {
  12248. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12249. }
  12250. else
  12251. {
  12252. tempIndex = SetProfileReq.ConnectorId -1;
  12253. }
  12254. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12255. {
  12256. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12257. {
  12258. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12259. {
  12260. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12261. {
  12262. isMatchTransactiodId = TRUE;
  12263. break;
  12264. }
  12265. }
  12266. }
  12267. }
  12268. }
  12269. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12270. {
  12271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12272. {
  12273. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12274. }
  12275. else
  12276. {
  12277. tempIndex = SetProfileReq.ConnectorId -1;
  12278. }
  12279. for (int index = 0; index < CCS_QUANTITY; index++)
  12280. {
  12281. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12282. {
  12283. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12284. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12285. {
  12286. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12287. {
  12288. isMatchTransactiodId = TRUE;
  12289. break;
  12290. }
  12291. }
  12292. }
  12293. }
  12294. }
  12295. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12296. {
  12297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12298. {
  12299. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12300. }
  12301. else
  12302. {
  12303. tempIndex = SetProfileReq.ConnectorId -1;
  12304. }
  12305. for (int index = 0; index < GB_QUANTITY; index++)
  12306. {
  12307. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12308. {
  12309. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12310. {
  12311. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12312. {
  12313. isMatchTransactiodId = TRUE;
  12314. break;
  12315. }
  12316. }
  12317. }
  12318. }
  12319. }
  12320. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12321. {
  12322. tempIndex = SetProfileReq.ConnectorId -1;
  12323. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12324. {
  12325. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12326. {
  12327. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12328. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12329. {
  12330. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12331. {
  12332. isMatchTransactiodId = TRUE;
  12333. break;
  12334. }
  12335. }
  12336. }
  12337. }
  12338. }
  12339. else
  12340. {
  12341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12342. {
  12343. tempIndex = 2;
  12344. }
  12345. else
  12346. {
  12347. tempIndex = (SetProfileReq.ConnectorId -1);
  12348. }
  12349. for (int index = 0; index < AC_QUANTITY; index++)
  12350. {
  12351. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12352. {
  12353. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12354. {
  12355. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12356. {
  12357. isMatchTransactiodId = TRUE;
  12358. break;
  12359. }
  12360. }
  12361. }
  12362. }
  12363. }
  12364. //check Transaction active
  12365. if(isMatchTransactiodId == FALSE)
  12366. {
  12367. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12368. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12369. goto end;
  12370. }
  12371. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12372. {
  12373. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12374. DEBUG_WARN("Connector id is over max gun number.\n");
  12375. goto end;
  12376. }
  12377. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12378. fp = fopen(filename, "r");
  12379. if (!fp)
  12380. {
  12381. DEBUG_INFO("%s does not create.\n", filename);
  12382. fp = fopen(filename, "w+");
  12383. }
  12384. else
  12385. {
  12386. char *line = NULL;
  12387. size_t len = 0;
  12388. while(getline(&line, &len, fp) != -1)
  12389. {
  12390. json_object *obj = NULL;
  12391. obj = json_tokener_parse(line);
  12392. if(is_error(obj))
  12393. {
  12394. DEBUG_ERROR("Parse txProfile from file error.\n");
  12395. }
  12396. else
  12397. {
  12398. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12399. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12400. {
  12401. profileQuantity += 1;
  12402. }
  12403. else
  12404. isReplaceable = TRUE;
  12405. }
  12406. }
  12407. }
  12408. fclose(fp);
  12409. }
  12410. // Check ChargeProfileMaxStackLevel
  12411. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12412. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12413. {
  12414. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12415. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12416. goto end;
  12417. }
  12418. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12419. {
  12420. FILE *fp;
  12421. char dataLine[4096]={0};
  12422. char fnametemp[128]={0};
  12423. int tmpProfileQuantity;
  12424. //Check ChargePointMaxProfile.json exit
  12425. profileQuantity = 0;
  12426. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12427. {
  12428. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12429. //Check Charging Profile Count
  12430. tmpProfileQuantity = 0;
  12431. while(fscanf(fp, "%s", dataLine) != EOF)
  12432. {
  12433. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12434. {
  12435. profileQuantity += 1;
  12436. tmpProfileQuantity += 1;
  12437. }
  12438. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12439. }
  12440. fclose(fp);
  12441. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12442. }
  12443. //Check TxDefaultProfile_%d.json
  12444. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12445. {
  12446. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12447. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12448. if((access(fnametemp,F_OK))!=-1)
  12449. {
  12450. fp = fopen(fnametemp, "r");
  12451. //Check Charging Profile Count
  12452. tmpProfileQuantity = 0;
  12453. while(fscanf(fp, "%s", dataLine) != EOF)
  12454. {
  12455. //DEBUG_INFO("word=%s\n",word);
  12456. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12457. {
  12458. profileQuantity += 1;
  12459. tmpProfileQuantity += 1;
  12460. }
  12461. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12462. }
  12463. fclose(fp);
  12464. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12465. }
  12466. }
  12467. //Check TxProfile_%d.json
  12468. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12469. {
  12470. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12471. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12472. if((access(fnametemp,F_OK))!=-1)
  12473. {
  12474. fp = fopen(fnametemp, "r");
  12475. //Check Charging Profile Count
  12476. tmpProfileQuantity = 0;
  12477. while(fscanf(fp, "%s", dataLine) != EOF)
  12478. {
  12479. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12480. {
  12481. profileQuantity += 1;
  12482. tmpProfileQuantity += 1;
  12483. }
  12484. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12485. }
  12486. fclose(fp);
  12487. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12488. }
  12489. }
  12490. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12491. if((profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData)) && (isReplaceable != TRUE))
  12492. {
  12493. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12494. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12495. goto end;
  12496. }
  12497. }
  12498. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12499. //**********************************Write to File********************************************************/
  12500. {
  12501. FILE *infile;
  12502. FILE *outfile;
  12503. char dataLine[4096]={0};
  12504. char filename[128]={0};
  12505. int chkChar=0;
  12506. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12507. {
  12508. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12509. {
  12510. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12511. }
  12512. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12513. {
  12514. if(SetProfileReq.ConnectorId==0)
  12515. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12516. else
  12517. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12518. }
  12519. else
  12520. {
  12521. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12522. }
  12523. infile = fopen (filename, "r");
  12524. outfile = fopen (tempfile, "w");
  12525. chkChar = fgetc(infile);
  12526. rewind(infile);
  12527. if(chkChar == EOF)
  12528. {
  12529. // Profile is empty
  12530. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12531. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12532. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12533. fclose(infile);
  12534. fclose(outfile);
  12535. sprintf(rmFileCmd,"rm -f %s",filename);
  12536. system(rmFileCmd);
  12537. rename(tempfile, filename);
  12538. }
  12539. else
  12540. {
  12541. // Profile is not empty
  12542. int ChargingProfileAdded = FALSE;
  12543. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12544. {
  12545. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12546. json_object *tmpChargingProfile;
  12547. tmpChargingProfile = json_tokener_parse(dataLine);
  12548. if(!is_error(SetChargingProfile))
  12549. {
  12550. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12551. {
  12552. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12553. {
  12554. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12555. }
  12556. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12557. {
  12558. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12559. }
  12560. }
  12561. }
  12562. json_object_put(tmpChargingProfile);
  12563. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12564. {
  12565. if(ChargingProfileAdded == FALSE)
  12566. {
  12567. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12568. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12569. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12570. ChargingProfileAdded = TRUE;
  12571. }
  12572. }
  12573. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12574. {
  12575. if(ChargingProfileAdded == FALSE)
  12576. {
  12577. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12578. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12579. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12580. ChargingProfileAdded = TRUE;
  12581. }
  12582. }
  12583. else
  12584. {
  12585. fprintf(outfile,"%s\n",dataLine);
  12586. if(ChargingProfileAdded == FALSE)
  12587. {
  12588. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12589. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12590. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12591. ChargingProfileAdded = TRUE;
  12592. }
  12593. }
  12594. } // end of while loop
  12595. fclose(infile);
  12596. fclose(outfile);
  12597. sprintf(rmFileCmd,"rm -f %s",filename);
  12598. system(rmFileCmd);
  12599. rename(tempfile, filename);
  12600. }
  12601. }
  12602. sleep(1);
  12603. result = TRUE;
  12604. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12605. }
  12606. end:
  12607. json_object_put(SetChargingProfile);
  12608. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12609. {
  12610. if(SetProfileReq.ConnectorId == 0)
  12611. {
  12612. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12613. {
  12614. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12615. }
  12616. }
  12617. else
  12618. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12619. }
  12620. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12621. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12622. return result;
  12623. }
  12624. int handleTriggerMessageRequest(char *uuid, char *payload)
  12625. {
  12626. mtrace();
  12627. int result = FAIL;
  12628. int connectorIdIsNULL = FALSE;
  12629. int connectorIdInt =0;
  12630. char sstr[40]={0},sstrtemp[100]={ 0 };
  12631. char requestedMessagestr[40]={0};
  12632. char comfirmstr[20]={0};
  12633. int c = 0;
  12634. char *loc;
  12635. DEBUG_INFO("handleTriggerMessageRequest\n");
  12636. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12637. strcpy(sstrtemp, stringtrimspace(payload));
  12638. c = 0;
  12639. loc = strstr(sstrtemp, "requestedMessage");
  12640. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12641. {
  12642. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12643. c++;
  12644. }
  12645. sstr[c] = '\0';
  12646. strcpy(requestedMessagestr, sstr);
  12647. c = 0;
  12648. loc = strstr(sstrtemp, "connectorId");
  12649. if(loc == NULL)
  12650. {
  12651. connectorIdIsNULL = TRUE;
  12652. }
  12653. else
  12654. {
  12655. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12656. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12657. {
  12658. sstr[c] = loc[strlen("connectorId")+2+c];
  12659. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12660. c++;
  12661. }
  12662. sstr[c] = '\0';
  12663. connectorIdInt = atoi(sstr);
  12664. }
  12665. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12666. {
  12667. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12668. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12669. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12670. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12671. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12672. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12673. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12674. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12675. {
  12676. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12677. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12678. return TRUE;
  12679. }
  12680. else
  12681. {
  12682. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12683. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12684. }
  12685. }
  12686. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12687. {
  12688. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12689. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12690. return TRUE;
  12691. }
  12692. //==========================
  12693. // Trigger message
  12694. //==========================
  12695. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12696. {
  12697. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12698. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12699. {
  12700. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12701. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12702. }
  12703. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12704. }
  12705. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12706. {
  12707. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12708. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12709. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12710. }
  12711. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12712. {
  12713. //sendBootNotificationRequest();
  12714. server_sign = FALSE;
  12715. }
  12716. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12717. {
  12718. refreshStartTimer(&clientTime.Heartbeat);
  12719. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12720. }
  12721. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12722. {
  12723. if(connectorIdIsNULL == FALSE)
  12724. {
  12725. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12726. {
  12727. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12728. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12729. }
  12730. }
  12731. else
  12732. {
  12733. for(int idx=0;idx< gunTotalNumber;idx++)
  12734. {
  12735. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12736. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12737. }
  12738. }
  12739. }
  12740. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12741. {
  12742. if(connectorIdIsNULL == FALSE)
  12743. {
  12744. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12745. {
  12746. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12747. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12748. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12749. }
  12750. }
  12751. else
  12752. {
  12753. for(int idx=0;idx< gunTotalNumber;idx++)
  12754. {
  12755. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12756. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12757. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12758. }
  12759. }
  12760. }
  12761. return result;
  12762. }
  12763. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12764. {
  12765. mtrace();
  12766. int result = FAIL;
  12767. int connectorIdInt =0;
  12768. char comfirmstr[20]={0};
  12769. int tempIndex = 0;
  12770. json_object *UnlockConnector;
  12771. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12772. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12773. UnlockConnector = json_tokener_parse(payload);
  12774. if(!is_error(UnlockConnector))
  12775. {
  12776. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12777. {
  12778. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12779. }
  12780. }
  12781. json_object_put(UnlockConnector);
  12782. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12783. if(gunTotalNumber == 0)
  12784. {
  12785. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12786. goto end;
  12787. }
  12788. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12789. {
  12790. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12791. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12792. goto end;
  12793. }
  12794. else
  12795. {
  12796. //check Transaction active
  12797. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12798. {
  12799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12800. {
  12801. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12802. }
  12803. else
  12804. {
  12805. tempIndex = connectorIdInt -1;
  12806. }
  12807. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12808. {
  12809. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12810. {
  12811. //stop Transaction
  12812. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12813. }
  12814. }
  12815. }
  12816. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12817. {
  12818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12819. {
  12820. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12821. }
  12822. else
  12823. {
  12824. tempIndex = connectorIdInt -1;
  12825. }
  12826. for (int index = 0; index < CCS_QUANTITY; index++)
  12827. {
  12828. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12829. {
  12830. //stop Transaction
  12831. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12832. }
  12833. }
  12834. }
  12835. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12836. {
  12837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12838. {
  12839. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12840. }
  12841. else
  12842. {
  12843. tempIndex = connectorIdInt -1;
  12844. }
  12845. for (int index = 0; index < GB_QUANTITY; index++)
  12846. {
  12847. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12848. {
  12849. //stop Transaction
  12850. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12851. }
  12852. }
  12853. }
  12854. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12855. {
  12856. tempIndex = connectorIdInt -1;
  12857. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12858. {
  12859. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12860. {
  12861. //stop Transaction
  12862. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12863. }
  12864. }
  12865. }
  12866. else
  12867. {
  12868. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12869. {
  12870. tempIndex = 2;
  12871. }
  12872. else
  12873. {
  12874. tempIndex = connectorIdInt-1;
  12875. }
  12876. for (int index = 0; index < AC_QUANTITY; index++)
  12877. {
  12878. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12879. {
  12880. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12881. }
  12882. }
  12883. }
  12884. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12885. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12886. result = TRUE;
  12887. return result;
  12888. }
  12889. end:
  12890. //json_object_put(obj); --- remove temporally
  12891. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12892. return result;
  12893. }
  12894. static char UpdateFirmwarepayloadData[300]={0};
  12895. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12896. {
  12897. mtrace();
  12898. int result = FAIL;
  12899. pthread_t t;
  12900. sendUpdateFirmwareConfirmation(uuid);
  12901. memset(UpdateFirmwarepayloadData, 0, 300);
  12902. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12903. if(!interLock.isUpdateFirmwareGoing)
  12904. {
  12905. interLock.isUpdateFirmwareGoing = 1;
  12906. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12907. sleep(1);
  12908. }
  12909. else
  12910. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12911. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12912. return result;
  12913. }
  12914. void *UpdateFirmwareProcess(void *data)
  12915. {
  12916. pthread_detach(pthread_self());
  12917. mtrace();
  12918. int retriesInt =0, retryIntervalInt=0;
  12919. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12920. int port=0;
  12921. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12922. int isSuccess = 0;
  12923. char ftpbuf[1024];
  12924. char temp[1024];
  12925. char * pch;
  12926. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12927. json_object *UpdateFirmware;
  12928. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12929. if(!is_error(UpdateFirmware))
  12930. {
  12931. // Required data
  12932. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12933. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12934. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12935. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12936. // Optional data
  12937. if(json_object_object_get(UpdateFirmware, "retries"))
  12938. {
  12939. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12940. }
  12941. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12942. {
  12943. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12944. }
  12945. }
  12946. json_object_put(UpdateFirmware);
  12947. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12948. memset(path, 0, ARRAY_SIZE(path));
  12949. // Wait retrieveData
  12950. if(strlen(retrieveDatestr) > 10)
  12951. {
  12952. do
  12953. {
  12954. sleep(1);
  12955. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12956. }
  12957. // Ready to download
  12958. system("rm -f /mnt/*");
  12959. if(strncmp(locationstr,"http", 4) == 0)
  12960. {
  12961. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12962. sprintf(ftppath,"/%s", path);
  12963. DEBUG_INFO("locationstr: %s\n", locationstr);
  12964. DEBUG_INFO("protocol: %s\n",protocol);
  12965. DEBUG_INFO("host: %s\n",host);
  12966. DEBUG_INFO("path: %s\n",path);
  12967. DEBUG_INFO("ftppath: %s\n",ftppath);
  12968. int ftppathlen=strlen(ftppath);
  12969. int i=1;
  12970. char filenametemp[50];
  12971. while(i < ftppathlen)
  12972. {
  12973. int len=ftppathlen-i;
  12974. if(ftppath[len]== 47) // '/' ascll code: 47
  12975. {
  12976. DEBUG_INFO("compare '/' all right\n");
  12977. break;
  12978. }
  12979. i=i+1;
  12980. }
  12981. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12982. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12983. filenametemp[i+1] = 0;
  12984. do
  12985. {
  12986. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12987. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12988. sleep(1);
  12989. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12990. if(!isSuccess)
  12991. {
  12992. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12993. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12994. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12995. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12996. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12997. }
  12998. else
  12999. {
  13000. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13001. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13002. }
  13003. retriesInt--;
  13004. }while((isSuccess == 0)&&(retriesInt >= 0));
  13005. }
  13006. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13007. {
  13008. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13009. memset(temp, 0, ARRAY_SIZE(temp));
  13010. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13011. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13012. int ftppathlen=strlen(ftpbuf);
  13013. int i=1;
  13014. char filenametemp[50];
  13015. while(i < ftppathlen)
  13016. {
  13017. int len=ftppathlen-i;
  13018. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13019. {
  13020. DEBUG_INFO(" compare '/' all right\n");
  13021. break;
  13022. }
  13023. i=i+1;
  13024. }
  13025. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13026. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13027. filenametemp[i+1] = 0;
  13028. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13029. pch=strchr(temp,'@');
  13030. if(pch==NULL)
  13031. {
  13032. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13033. protocol, host, &port, path);
  13034. strcpy(user,"anonymous");
  13035. strcpy(password,"");
  13036. }
  13037. else
  13038. {
  13039. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13040. protocol, user, password, host, &port, path);
  13041. }
  13042. sscanf(host,"%[^/]%s",host1, path1);
  13043. sprintf(ftppath,"%s", path1);
  13044. //DEBUG_INFO("protocol =%s\n",protocol);
  13045. //DEBUG_INFO("user =%s\n",user);
  13046. //DEBUG_INFO("password =%s\n",password);
  13047. //DEBUG_INFO("host1 =%s\n",host1);
  13048. //DEBUG_INFO("port =%d\n",port);
  13049. //DEBUG_INFO("path1 =%s\n",path1);
  13050. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13051. //ftpFile(host, user, password, port, ftppath, fname);
  13052. //download firmware pthred
  13053. if(port == 0)
  13054. {
  13055. port = 21;
  13056. }
  13057. do
  13058. {
  13059. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13060. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13061. sleep(1);
  13062. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13063. if(!isSuccess)
  13064. {
  13065. //BulldogUtil.sleepMs(interval*1000);
  13066. DEBUG_INFO("Update firmware request and download file fail.\n");
  13067. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13068. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13069. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13070. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13071. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13072. }
  13073. else
  13074. {
  13075. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13076. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13077. }
  13078. retriesInt--;
  13079. }while((!isSuccess)&&(retriesInt >= 0));
  13080. }
  13081. else
  13082. {
  13083. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13084. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13085. sleep(1);
  13086. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13087. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13088. }
  13089. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13090. interLock.isUpdateFirmwareGoing = 0;
  13091. pthread_exit(NULL);
  13092. }
  13093. int handleCertificateSignedRequest(char *uuid, char *payload)
  13094. {
  13095. mtrace();
  13096. int result = PASS;
  13097. json_object *CertificateSigned;
  13098. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13099. CertificateSigned = json_tokener_parse(payload);
  13100. if(!is_error(CertificateSigned))
  13101. {
  13102. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13103. }
  13104. json_object_put(CertificateSigned);
  13105. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13106. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13107. fclose(fp);
  13108. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13109. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13110. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13111. sendCertificateSignedConfirmation(uuid);
  13112. return result;
  13113. }
  13114. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13115. {
  13116. mtrace();
  13117. int result = PASS;
  13118. json_object *DeleteCertificate;
  13119. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13120. DeleteCertificate = json_tokener_parse(payload);
  13121. if(!is_error(DeleteCertificate))
  13122. {
  13123. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13124. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13125. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13126. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13127. }
  13128. json_object_put(DeleteCertificate);
  13129. /*
  13130. * TODO: Delete certificateSigned process
  13131. */
  13132. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13133. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13134. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13135. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13136. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13137. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13138. sendDeleteCertificateConfirmation(uuid);
  13139. return result;
  13140. }
  13141. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13142. {
  13143. mtrace();
  13144. int result = PASS;
  13145. json_object *ExtendedTriggerMessage;
  13146. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13147. ExtendedTriggerMessage = json_tokener_parse(payload);
  13148. if(!is_error(ExtendedTriggerMessage))
  13149. {
  13150. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13151. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13152. {
  13153. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13154. }
  13155. else
  13156. {
  13157. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13158. }
  13159. }
  13160. json_object_put(ExtendedTriggerMessage);
  13161. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13162. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13163. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13164. {
  13165. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13166. }
  13167. else
  13168. {
  13169. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13170. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13171. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13172. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13173. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13174. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13175. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13176. {
  13177. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13178. }
  13179. else
  13180. {
  13181. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13182. }
  13183. }
  13184. sendExtendedTriggerMessageConfirmation(uuid);
  13185. //==========================
  13186. // Trigger message
  13187. //==========================
  13188. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13189. {
  13190. //sendBootNotificationRequest();
  13191. server_sign = FALSE;
  13192. }
  13193. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13194. {
  13195. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13196. }
  13197. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13198. {
  13199. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13200. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13201. {
  13202. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13203. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13204. }
  13205. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13206. }
  13207. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13208. {
  13209. refreshStartTimer(&clientTime.Heartbeat);
  13210. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13211. }
  13212. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13213. {
  13214. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13215. {
  13216. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13217. }
  13218. else
  13219. {
  13220. for(int idx=0;idx< gunTotalNumber;idx++)
  13221. {
  13222. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13223. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13224. }
  13225. }
  13226. }
  13227. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13228. {
  13229. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13230. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13231. {
  13232. 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\" &");
  13233. }
  13234. }
  13235. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13236. {
  13237. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13238. {
  13239. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13240. }
  13241. else
  13242. {
  13243. for(int idx=0;idx< gunTotalNumber;idx++)
  13244. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13245. }
  13246. }
  13247. return result;
  13248. }
  13249. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13250. {
  13251. mtrace();
  13252. int result = PASS;
  13253. json_object *GetInstalledCertificateIds;
  13254. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13255. GetInstalledCertificateIds = json_tokener_parse(payload);
  13256. if(!is_error(GetInstalledCertificateIds))
  13257. {
  13258. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13259. }
  13260. json_object_put(GetInstalledCertificateIds);
  13261. /*
  13262. * TODO: Return installed certificate process
  13263. */
  13264. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13265. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13266. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13267. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13268. sendGetInstalledCertificateIdsConfirmation(uuid);
  13269. return result;
  13270. }
  13271. int handleGetLogRequest(char *uuid, char *payload)
  13272. {
  13273. mtrace();
  13274. int result = PASS;
  13275. json_object *GetLog;
  13276. DEBUG_INFO("handleGetLogRequest...\n");
  13277. GetLog = json_tokener_parse(payload);
  13278. if(!is_error(GetLog))
  13279. {
  13280. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13281. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13282. if(json_object_object_get(GetLog, "retries") != NULL)
  13283. {
  13284. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13285. }
  13286. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13287. {
  13288. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13289. }
  13290. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13291. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13292. {
  13293. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13294. }
  13295. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13296. {
  13297. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13298. }
  13299. }
  13300. json_object_put(GetLog);
  13301. /*
  13302. * TODO: Upload log process
  13303. */
  13304. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13305. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13306. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13307. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13308. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13309. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13310. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13311. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13312. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13313. sendGetLogConfirmation(uuid);
  13314. return result;
  13315. }
  13316. int handleInstallCertificateRequest(char *uuid, char *payload)
  13317. {
  13318. mtrace();
  13319. int result = PASS;
  13320. json_object *InstallCertificate;
  13321. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13322. InstallCertificate = json_tokener_parse(payload);
  13323. if(!is_error(InstallCertificate))
  13324. {
  13325. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13326. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13327. /*
  13328. * TODO: Install certificate process
  13329. */
  13330. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13331. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13332. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13333. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13334. sendInstallCertificateConfirmation(uuid);
  13335. }
  13336. json_object_put(InstallCertificate);
  13337. return result;
  13338. }
  13339. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13340. {
  13341. mtrace();
  13342. int result = PASS;
  13343. json_object *SignedUpdateFirmware;
  13344. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13345. SignedUpdateFirmware = json_tokener_parse(payload);
  13346. if(!is_error(SignedUpdateFirmware))
  13347. {
  13348. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13349. {
  13350. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13351. }
  13352. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13353. {
  13354. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13355. }
  13356. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13357. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13358. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13359. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13360. {
  13361. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13362. }
  13363. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13364. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13365. }
  13366. json_object_put(SignedUpdateFirmware);
  13367. /*
  13368. * TODO: Upgrade firmware process
  13369. */
  13370. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13371. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13372. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13373. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13374. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13375. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13376. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13377. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13378. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13379. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13380. sendInstallCertificateConfirmation(uuid);
  13381. return result;
  13382. }
  13383. int handleUnknownRequest(char *uuid, char *payload)
  13384. {
  13385. mtrace();
  13386. int result = PASS;
  13387. DEBUG_INFO("handleUnknownRequest...\n");
  13388. sendUnknownConfirmation(uuid);
  13389. result = PASS;
  13390. return result;
  13391. }
  13392. //==========================================
  13393. // Handle server response routine
  13394. //==========================================
  13395. void handleAuthorizeResponse(char *payload, int gun_index)
  13396. {
  13397. mtrace();
  13398. char expiryDatestr[30]={0};
  13399. char parentIdTagstr[20]={0};
  13400. char statusstr[20]={0};
  13401. int expiryDateISNULL=FALSE;
  13402. int parentIdTagISNULL=FALSE;
  13403. DEBUG_INFO("handleAuthorizeResponse...\n");
  13404. json_object *Authorize;
  13405. Authorize = json_tokener_parse(payload);
  13406. if(!is_error(Authorize))
  13407. {
  13408. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13409. {
  13410. // Required data
  13411. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13412. // Optional data
  13413. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13414. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13415. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13416. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13417. }
  13418. }
  13419. json_object_put(Authorize);
  13420. if(expiryDateISNULL == FALSE)
  13421. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13422. if(parentIdTagISNULL == FALSE)
  13423. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13424. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13425. //Update idTag information to authorization cache if supproted
  13426. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13427. {
  13428. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13429. }
  13430. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13431. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13432. authorizeRetryTimes = 0;
  13433. }
  13434. void handleBootNotificationResponse(char *payload, int gun_index)
  13435. {
  13436. mtrace();
  13437. char statusStr[12]={0};
  13438. char currentTimeStr[30]={0};
  13439. int intervalInt = 0;
  13440. DEBUG_INFO("handleBootNotificationResponse...\n");
  13441. json_object *BootNotification;
  13442. BootNotification = json_tokener_parse(payload);
  13443. if(!is_error(BootNotification))
  13444. {
  13445. // Required data
  13446. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13447. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13448. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13449. }
  13450. json_object_put(BootNotification);
  13451. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13452. BootNotificationInterval = intervalInt;
  13453. //write back to ShmOCPP16Data->BootNotification
  13454. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13455. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13456. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13457. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13458. {
  13459. if((intervalInt == 0) || (intervalInt >= 10))
  13460. {
  13461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13462. HeartBeatWaitTime = intervalInt;
  13463. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13464. }
  13465. server_sign = TRUE;
  13466. server_pending =FALSE;
  13467. }
  13468. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13469. {
  13470. server_pending = TRUE;
  13471. }
  13472. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13473. srand(time(NULL));
  13474. refreshStartTimer(&clientTime.Heartbeat);
  13475. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13476. SetOcppConnStatus(TRUE);
  13477. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13478. }
  13479. void handleDataTransferResponse(char *payload, int gun_index)
  13480. {
  13481. json_object *DataTransfer = json_tokener_parse(payload);
  13482. if(!is_error(DataTransfer))
  13483. {
  13484. // Required data
  13485. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13486. // Optional data
  13487. if(json_object_object_get(DataTransfer, "data") != NULL)
  13488. {
  13489. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13490. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13491. if(!is_error(Data))
  13492. {
  13493. if(json_object_object_get(Data, "msgId") != NULL)
  13494. {
  13495. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13496. {
  13497. 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")));
  13498. }
  13499. }
  13500. }
  13501. json_object_put(Data);
  13502. }
  13503. }
  13504. json_object_put(DataTransfer);
  13505. }
  13506. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13507. {
  13508. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13509. //struct json_object *obj;
  13510. // obj = json_tokener_parse(payload);
  13511. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13512. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13513. //No fields are defined.
  13514. }
  13515. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13516. {
  13517. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13518. //struct json_object *obj;
  13519. // obj = json_tokener_parse(payload);
  13520. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13521. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13522. //No fields are defined.
  13523. }
  13524. void handleHeartbeatResponse(char *payload, int gun_index)
  13525. {
  13526. mtrace();
  13527. DEBUG_INFO("handleHeartbeatResponse...\n");
  13528. json_object *Heartbeat;
  13529. Heartbeat = json_tokener_parse(payload);
  13530. if(!is_error(Heartbeat))
  13531. {
  13532. // Required data
  13533. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13534. }
  13535. json_object_put(Heartbeat);
  13536. if(FirstHeartBeat == 0)
  13537. {
  13538. FirstHeartBeat = 1;
  13539. DEBUG_INFO("FirstHeartBeat \n");
  13540. }
  13541. HeartBeatWithNOResponse = 0;
  13542. refreshStartTimer(&clientTime.Heartbeat);
  13543. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13544. }
  13545. void handleMeterValuesResponse(char *payload, int gun_index)
  13546. {
  13547. mtrace();
  13548. DEBUG_INFO("handleMeterValuesResponse...\n");
  13549. isQueueSendable = 1;
  13550. }
  13551. void handleStartTransactionResponse(char *payload, int gun_index)
  13552. {
  13553. mtrace();
  13554. //int transactionIdInt = 0;
  13555. FILE *outfile;
  13556. char data[100]={0};
  13557. DEBUG_INFO("handleStartTransactionResponse...\n");
  13558. json_object *StartTransaction;
  13559. StartTransaction = json_tokener_parse(payload);
  13560. if(!is_error(StartTransaction))
  13561. {
  13562. // Required data
  13563. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13564. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13565. // Optional data
  13566. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13567. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13568. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13569. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13570. }
  13571. json_object_put(StartTransaction);
  13572. isQueueSendable = 1;
  13573. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13574. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13575. //-----------Start : write to the Queue TransactionId file -----------------//
  13576. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13577. {}
  13578. else
  13579. {
  13580. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13581. if(log == NULL)
  13582. {
  13583. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13584. return ;
  13585. }
  13586. else
  13587. {
  13588. fclose(log);
  13589. }
  13590. }
  13591. // open file for writing
  13592. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13593. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13594. {
  13595. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13596. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13597. fputs(data, outfile);
  13598. fclose (outfile);
  13599. }
  13600. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13601. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13602. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13603. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13604. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13605. }
  13606. void handleStatusNotificationResponse(char *payload, int gun_index)
  13607. {
  13608. mtrace();
  13609. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13610. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13611. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13612. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13613. }
  13614. void handleStopTransactionnResponse(char *payload, int gun_index)
  13615. {
  13616. mtrace();
  13617. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13618. json_object *StopTransaction;
  13619. StopTransaction = json_tokener_parse(payload);
  13620. if(!is_error(StopTransaction))
  13621. {
  13622. // Optional data
  13623. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13624. {
  13625. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13626. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13627. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13628. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13629. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13630. }
  13631. }
  13632. json_object_put(StopTransaction);
  13633. isQueueSendable = 1;
  13634. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13635. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13636. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13637. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13638. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13639. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13640. }
  13641. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13642. {
  13643. mtrace();
  13644. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13645. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13646. }
  13647. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13648. {
  13649. mtrace();
  13650. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13651. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13652. }
  13653. void handleSignCertificateResponse(char *payload, int gun_index)
  13654. {
  13655. mtrace();
  13656. DEBUG_INFO("handleSignCertificateResponse...\n");
  13657. json_object *SignCertificate;
  13658. SignCertificate = json_tokener_parse(payload);
  13659. if(!is_error(SignCertificate))
  13660. {
  13661. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13662. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13663. }
  13664. json_object_put(SignCertificate);
  13665. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13666. }
  13667. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13668. {
  13669. mtrace();
  13670. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13671. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13672. }
  13673. //==========================================
  13674. // Handle Error routine
  13675. //==========================================
  13676. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13677. {
  13678. mtrace();
  13679. #ifdef SystemLogMessage
  13680. DEBUG_INFO("errorCode: %s\n", errorCode);
  13681. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13682. DEBUG_INFO("errorDetails: %s\n", payload);
  13683. #endif
  13684. }
  13685. //===============================================
  13686. // Common routine
  13687. //===============================================
  13688. int initialConfigurationTable(void)
  13689. {
  13690. //clock_t start_t, end_t, total_t;
  13691. FILE *fp;
  13692. FILE *outfile;
  13693. char str[512]={0};
  13694. char sstr[256]={0};
  13695. int c = 0;
  13696. char *loc;
  13697. int confVersion = 13;
  13698. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13699. //start_t = clock();
  13700. //printf("Starting of the program, start_t = %ld\n", start_t);
  13701. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13702. // Check configuration file size is correct
  13703. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13704. {
  13705. struct stat st;
  13706. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13707. if(st.st_size < 3100)
  13708. {
  13709. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13710. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13711. }
  13712. }
  13713. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13714. {
  13715. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13716. if(outfile == NULL)
  13717. {
  13718. DEBUG_INFO("Error opening file\n");
  13719. return FALSE;
  13720. }
  13721. /*Core Profile*/
  13722. //AllowOfflineTxForUnknownId
  13723. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13727. //AuthorizationCacheEnabled
  13728. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13732. //AuthorizeRemoteTxRequests
  13733. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13737. //BlinkRepeat
  13738. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13742. //ClockAlignedDataInterval
  13743. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13747. //ConnectionTimeOut
  13748. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13752. //GetConfigurationMaxKeys
  13753. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13757. // HeartbeatInterval
  13758. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13762. // LightIntensity
  13763. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13767. // LocalAuthorizeOffline
  13768. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13772. // LocalPreAuthorize
  13773. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13777. // MaxEnergyOnInvalidId
  13778. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13782. // MeterValuesAlignedData
  13783. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13785. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13786. 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" );
  13787. else
  13788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13790. // MeterValuesAlignedDataMaxLength
  13791. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13793. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13795. else
  13796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13798. // MeterValuesSampledData
  13799. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13802. 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" );
  13803. else
  13804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13806. // MeterValuesSampledDataMaxLength
  13807. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13809. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13811. else
  13812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13814. // MeterValueSampleInterval
  13815. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13819. // MinimumStatusDuration
  13820. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13823. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13825. // NumberOfConnectors
  13826. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13828. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13829. {
  13830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13831. }
  13832. else
  13833. {
  13834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13835. }
  13836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13837. // ResetRetries
  13838. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13842. // ConnectorPhaseRotation
  13843. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13847. // ConnectorPhaseRotationMaxLength
  13848. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13852. // StopTransactionOnEVSideDisconnect
  13853. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13857. // StopTransactionOnInvalidId
  13858. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13862. // StopTxnAlignedData
  13863. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13867. // StopTxnAlignedDataMaxLength
  13868. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13872. // StopTxnSampledData
  13873. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13875. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13877. else
  13878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13880. // StopTxnSampledDataMaxLength
  13881. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13884. {
  13885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13886. }
  13887. else
  13888. {
  13889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13890. }
  13891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13892. // SupportedFeatureProfiles
  13893. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13897. // SupportedFeatureProfilesMaxLength
  13898. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13902. // TransactionMessageAttempts
  13903. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13906. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13908. // TransactionMessageRetryInterval
  13909. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13912. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13914. // UnlockConnectorOnEVSideDisconnect
  13915. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13919. // WebSocketPingInterval
  13920. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13924. // QueueOffLineMeterValues
  13925. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13929. // AuthorizationKey
  13930. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13934. // SecurityProfile
  13935. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13939. // DefaultPrice
  13940. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13944. // CustomDisplayCostAndPrice
  13945. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13949. // CustomIdleFeeAfterStop
  13950. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13954. // TimeOffset
  13955. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13959. // NextTimeOffsetTransitionDateTime
  13960. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13964. // TimeOffsetNextTransition
  13965. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13969. // SystemUptimeSec
  13970. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13974. // FreeVend
  13975. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13979. // FreeVendIdtag
  13980. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13984. // OcppServer
  13985. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13987. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13989. // MaintainServer
  13990. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13992. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13994. // StatusNotificationPeriodically
  13995. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13999. // StatusNotificationInterval
  14000. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14004. // Configuration Version
  14005. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14009. //* Local Auth List Management Profile*/
  14010. #if 0
  14011. //For OCTT Test Case
  14012. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14015. #endif
  14016. #if 1
  14017. //LocalAuthListEnabled
  14018. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14022. #endif
  14023. //LocalAuthListMaxLength
  14024. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14028. //SendLocalListMaxLength
  14029. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14033. //ReserveConnectorZeroSupported
  14034. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14038. //* Smart Charging Profile */
  14039. //ChargeProfileMaxStackLevel
  14040. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14044. // ChargingScheduleAllowedChargingRateUnit
  14045. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14049. // ChargingScheduleMaxPeriods
  14050. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14054. // ConnectorSwitch3to1PhaseSupported
  14055. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14059. // MaxChargingProfilesInstalled
  14060. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14064. fclose(outfile);
  14065. }
  14066. else
  14067. {
  14068. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14069. char keystr[60]={0};
  14070. char readonlystr[10]={0};
  14071. char valuestr[256]={0};
  14072. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14073. if(fp == NULL) {
  14074. DEBUG_INFO("Error opening file");
  14075. return FALSE;
  14076. }
  14077. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14078. {
  14079. //DEBUG_INFO("Get Configuration \n");
  14080. if(strlen(str) > 0)
  14081. {
  14082. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14083. //*************************key*********************************/
  14084. if(strstr(str, "key") != NULL)
  14085. {
  14086. loc = strstr(str, "key");
  14087. c = 0;
  14088. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14089. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14090. {
  14091. sstr[c] = loc[strlen("key")+3+c];
  14092. c++;
  14093. }
  14094. sstr[c] = '\0';
  14095. strcpy(keystr,sstr);
  14096. }
  14097. //*************************readonly*********************************/
  14098. if(strstr(str, "readonly") != NULL)
  14099. {
  14100. loc = strstr(str, "readonly");
  14101. c = 0;
  14102. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14103. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14104. {
  14105. sstr[c] = loc[strlen("readonly")+2+c];
  14106. c++;
  14107. }
  14108. sstr[c] = '\0';
  14109. strcpy(readonlystr,sstr);
  14110. }
  14111. //*************************value*********************************/
  14112. if(strstr(str, "value") != NULL)
  14113. {
  14114. loc = strstr(str, "value");
  14115. c = 0;
  14116. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14117. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14118. {
  14119. sstr[c] = loc[strlen("value")+3+c];
  14120. c++;
  14121. }
  14122. sstr[c] = '\0';
  14123. strcpy(valuestr,sstr);
  14124. }
  14125. // DEBUG_INFO("keystr=%s\n",keystr);
  14126. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14127. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14128. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14129. {
  14130. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14131. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14133. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14134. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14135. }
  14136. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14137. {
  14138. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14139. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14141. }
  14142. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14143. {
  14144. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14146. }
  14147. if(strcmp(keystr, "BlinkRepeat") == 0)
  14148. {
  14149. //Charger.BlinkRepeat = Integer.parseInt(value);
  14150. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14152. }
  14153. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14154. {
  14155. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14157. }
  14158. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14159. {
  14160. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14162. }
  14163. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14164. {
  14165. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14167. }
  14168. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14169. {
  14170. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14172. HeartBeatWaitTime = atoi(valuestr);
  14173. }
  14174. if(strcmp(keystr, "LightIntensity") == 0)
  14175. {
  14176. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14178. }
  14179. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14180. {
  14181. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14183. }
  14184. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14185. {
  14186. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14188. }
  14189. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14190. {
  14191. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14193. }
  14194. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14195. {
  14196. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14198. }
  14199. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14200. {
  14201. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14203. }
  14204. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14205. {
  14206. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14208. }
  14209. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14210. {
  14211. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14213. }
  14214. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14215. {
  14216. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14218. }
  14219. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14220. {
  14221. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14223. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14224. }
  14225. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14226. {
  14227. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14229. }
  14230. if(strcmp(keystr, "ResetRetries") == 0)
  14231. {
  14232. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14234. }
  14235. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14236. {
  14237. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14239. }
  14240. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14241. {
  14242. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14244. }
  14245. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14246. {
  14247. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14249. }
  14250. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14251. {
  14252. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14254. }
  14255. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14256. {
  14257. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14259. }
  14260. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14261. {
  14262. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14264. }
  14265. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14266. {
  14267. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14269. }
  14270. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14271. {
  14272. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14274. }
  14275. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14276. {
  14277. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14279. }
  14280. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14281. {
  14282. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14284. }
  14285. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14286. {
  14287. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14288. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14289. TransactionMessageAttemptsValue = atoi(valuestr);
  14290. }
  14291. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14292. {
  14293. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14295. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14296. }
  14297. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14298. {
  14299. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14300. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14301. }
  14302. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14303. {
  14304. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14306. }
  14307. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14308. {
  14309. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14310. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14311. }
  14312. if(strcmp(keystr, "AuthorizationKey") == 0)
  14313. {
  14314. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14315. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14317. }
  14318. if(strcmp(keystr, "SecurityProfile") == 0)
  14319. {
  14320. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14322. }
  14323. if(strcmp(keystr, "DefaultPrice") == 0)
  14324. {
  14325. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14327. }
  14328. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14329. {
  14330. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14332. }
  14333. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14334. {
  14335. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14337. }
  14338. if(strcmp(keystr, "TimeOffset") == 0)
  14339. {
  14340. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14342. }
  14343. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14344. {
  14345. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14347. }
  14348. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14349. {
  14350. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14352. }
  14353. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14354. {
  14355. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14357. }
  14358. if(strcmp(keystr, "FreeVend") == 0)
  14359. {
  14360. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14362. }
  14363. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14364. {
  14365. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14367. }
  14368. if(strcmp(keystr, "OcppServer") == 0)
  14369. {
  14370. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14371. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14372. }
  14373. if(strcmp(keystr, "MaintainServer") == 0)
  14374. {
  14375. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14376. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14377. }
  14378. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14379. {
  14380. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14382. }
  14383. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14384. {
  14385. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14387. }
  14388. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14389. {
  14390. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14391. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14392. }
  14393. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14394. {
  14395. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14397. }
  14398. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14399. {
  14400. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14402. }
  14403. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14404. {
  14405. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14407. }
  14408. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14409. {
  14410. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14412. }
  14413. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14414. {
  14415. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14417. }
  14418. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14419. {
  14420. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14422. }
  14423. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14424. {
  14425. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14427. }
  14428. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14429. {
  14430. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14432. }
  14433. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14434. {
  14435. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14437. }
  14438. }
  14439. }
  14440. fclose(fp);
  14441. }
  14442. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14443. {
  14444. return PASS;
  14445. }
  14446. else
  14447. {
  14448. return FAIL;
  14449. }
  14450. }
  14451. void StoreConfigurationTable(void)
  14452. {
  14453. FILE *outfile;
  14454. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14455. if(outfile == NULL)
  14456. {
  14457. DEBUG_INFO("Error opening file");
  14458. return ;
  14459. }
  14460. /*Core Profile*/
  14461. //AllowOfflineTxForUnknownId
  14462. /*
  14463. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14464. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14467. */
  14468. //DEBUG_INFO("data=%s\n",data);
  14469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14470. //AuthorizationCacheEnabled
  14471. /*
  14472. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14475. */
  14476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14477. //AuthorizeRemoteTxRequests
  14478. /*
  14479. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14482. */
  14483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14484. //BlinkRepeat
  14485. /*
  14486. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14489. */
  14490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14491. //ClockAlignedDataInterval
  14492. /*
  14493. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14496. */
  14497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14498. //ConnectionTimeOut
  14499. /*
  14500. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14503. */
  14504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14505. //GetConfigurationMaxKeys
  14506. /*
  14507. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14510. */
  14511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14512. // HeartbeatInterval
  14513. /*
  14514. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14517. */
  14518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14519. // LightIntensity
  14520. /*
  14521. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14524. */
  14525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14526. // LocalAuthorizeOffline
  14527. /*
  14528. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14531. */
  14532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14533. // LocalPreAuthorize
  14534. /*
  14535. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14538. */
  14539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14540. // MaxEnergyOnInvalidId
  14541. /*
  14542. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14545. */
  14546. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14547. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14548. // MeterValuesAlignedData
  14549. /*
  14550. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14553. */
  14554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14555. // MeterValuesAlignedDataMaxLength
  14556. /*
  14557. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14560. */
  14561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14562. // MeterValuesSampledData
  14563. /*
  14564. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14567. */
  14568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14569. // MeterValuesSampledDataMaxLength
  14570. /*
  14571. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14574. */
  14575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14576. // MeterValueSampleInterval
  14577. /*
  14578. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14581. */
  14582. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14583. // MinimumStatusDuration
  14584. /*
  14585. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14588. */
  14589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14590. // NumberOfConnectors
  14591. /*
  14592. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14594. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14595. {
  14596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14597. }
  14598. else
  14599. {
  14600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14601. }
  14602. */
  14603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14604. // ResetRetries
  14605. /*
  14606. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14609. */
  14610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14611. // ConnectorPhaseRotation
  14612. /*
  14613. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14616. */
  14617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14618. // ConnectorPhaseRotationMaxLength
  14619. /*
  14620. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14623. */
  14624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14625. // StopTransactionOnEVSideDisconnect
  14626. /*
  14627. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14630. */
  14631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14632. // StopTransactionOnInvalidId
  14633. /*
  14634. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14637. */
  14638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14639. // StopTxnAlignedData
  14640. /*
  14641. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14644. */
  14645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14646. // StopTxnAlignedDataMaxLength
  14647. /*
  14648. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14651. */
  14652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14653. // StopTxnSampledData
  14654. /*
  14655. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14658. */
  14659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14660. // StopTxnSampledDataMaxLength
  14661. /*
  14662. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14665. */
  14666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14667. // SupportedFeatureProfiles
  14668. /*
  14669. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14672. */
  14673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14674. // SupportedFeatureProfilesMaxLength
  14675. /*
  14676. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14679. */
  14680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14681. // TransactionMessageAttempts
  14682. /*
  14683. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14686. */
  14687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14688. // TransactionMessageRetryInterval
  14689. /*
  14690. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14693. */
  14694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14695. // UnlockConnectorOnEVSideDisconnect
  14696. /*
  14697. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14700. */
  14701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14702. // WebSocketPingInterval
  14703. /*
  14704. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14707. */
  14708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14709. // QueueOffLineMeterValues
  14710. /*
  14711. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14714. */
  14715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14716. // AuthorizationKey
  14717. /*
  14718. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14721. */
  14722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14723. // SecurityProfile
  14724. /*
  14725. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14728. */
  14729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14730. // DefaultPrice
  14731. /*
  14732. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14735. */
  14736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14737. // CustomDisplayCostAndPrice
  14738. /*
  14739. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14742. */
  14743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14744. // CustomIdleFeeAfterStop
  14745. /*
  14746. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14749. */
  14750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14751. // TimeOffset
  14752. /*
  14753. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14756. */
  14757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14758. // NextTimeOffsetTransitionDateTime
  14759. /*
  14760. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14763. */
  14764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14765. // TimeOffsetNextTransition
  14766. /*
  14767. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14770. */
  14771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14772. // SystemUptimeSec
  14773. /*
  14774. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14777. */
  14778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14779. // FreeVend
  14780. /*
  14781. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14784. */
  14785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14786. // FreeVendIdtag
  14787. /*
  14788. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14791. */
  14792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14793. // OcppServer
  14794. /*
  14795. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14798. */
  14799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14800. // MaintainServer
  14801. /*
  14802. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14805. */
  14806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14807. // StatusNotificationPeriodically
  14808. /*
  14809. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14812. */
  14813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14814. // StatusNotificationInterval
  14815. /*
  14816. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14819. */
  14820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14821. // ConfigurationVersion
  14822. /*
  14823. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14826. */
  14827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14828. //* Local Auth List Management Profile*/
  14829. //LocalAuthListEnabled
  14830. /*
  14831. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14834. */
  14835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14836. //LocalAuthListMaxLength
  14837. /*
  14838. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14841. */
  14842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14843. //SendLocalListMaxLength
  14844. /*
  14845. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14848. */
  14849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14850. //ReserveConnectorZeroSupported
  14851. /*
  14852. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14855. */
  14856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14857. //* Smart Charging Profile */
  14858. //ChargeProfileMaxStackLevel
  14859. /*
  14860. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14863. */
  14864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14865. // ChargingScheduleAllowedChargingRateUnit
  14866. /*
  14867. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14870. */
  14871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14872. // ChargingScheduleMaxPeriods
  14873. /*
  14874. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14877. */
  14878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14879. // ConnectorSwitch3to1PhaseSupported
  14880. /*
  14881. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14884. */
  14885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14886. // MaxChargingProfilesInstalled
  14887. /*
  14888. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14891. */
  14892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14893. fclose(outfile);
  14894. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14895. }
  14896. void getKeyValue(char *keyReq)
  14897. {
  14898. int isEmpty = FALSE;
  14899. int isKnowKey = FALSE;
  14900. DEBUG_INFO("keyReq = %s\n", keyReq);
  14901. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14902. isEmpty = TRUE;
  14903. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14904. {
  14905. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14908. {
  14909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14910. }
  14911. else
  14912. {
  14913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14914. }
  14915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14916. isKnowKey = TRUE;
  14917. }
  14918. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14919. {
  14920. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14922. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14923. {
  14924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14925. }
  14926. else
  14927. {
  14928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14929. }
  14930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14931. isKnowKey = TRUE;
  14932. }
  14933. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14934. {
  14935. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14938. {
  14939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14940. }
  14941. else
  14942. {
  14943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14944. }
  14945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14946. isKnowKey = TRUE;
  14947. }
  14948. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14949. {
  14950. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14953. {
  14954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14955. }
  14956. else
  14957. {
  14958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14959. }
  14960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14961. isKnowKey = TRUE;
  14962. }
  14963. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14964. {
  14965. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14968. {
  14969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14970. }
  14971. else
  14972. {
  14973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14974. }
  14975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14976. isKnowKey = TRUE;
  14977. }
  14978. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14979. {
  14980. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14983. {
  14984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14985. }
  14986. else
  14987. {
  14988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14989. }
  14990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14991. isKnowKey = TRUE;
  14992. }
  14993. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14994. {
  14995. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14998. {
  14999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15000. }
  15001. else
  15002. {
  15003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15004. }
  15005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15006. isKnowKey = TRUE;
  15007. }
  15008. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15009. {
  15010. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15013. {
  15014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15015. }
  15016. else
  15017. {
  15018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15019. }
  15020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15021. isKnowKey = TRUE;
  15022. }
  15023. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15024. {
  15025. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15027. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15028. {
  15029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15030. }
  15031. else
  15032. {
  15033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15034. }
  15035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15036. isKnowKey = TRUE;
  15037. }
  15038. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15039. {
  15040. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15042. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15043. {
  15044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15045. }
  15046. else
  15047. {
  15048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15049. }
  15050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15051. isKnowKey = TRUE;
  15052. }
  15053. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15054. {
  15055. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15057. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15058. {
  15059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15060. }
  15061. else
  15062. {
  15063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15064. }
  15065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15066. isKnowKey = TRUE;
  15067. }
  15068. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15069. {
  15070. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15073. {
  15074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15075. }
  15076. else
  15077. {
  15078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15079. }
  15080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15081. isKnowKey = TRUE;
  15082. }
  15083. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15084. {
  15085. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15088. {
  15089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15090. }
  15091. else
  15092. {
  15093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15094. }
  15095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15096. isKnowKey = TRUE;
  15097. }
  15098. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15099. {
  15100. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15103. {
  15104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15105. }
  15106. else
  15107. {
  15108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15109. }
  15110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15111. isKnowKey = TRUE;
  15112. }
  15113. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15114. {
  15115. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15118. {
  15119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15120. }
  15121. else
  15122. {
  15123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15124. }
  15125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15126. isKnowKey = TRUE;
  15127. }
  15128. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15129. {
  15130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15133. {
  15134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15135. }
  15136. else
  15137. {
  15138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15139. }
  15140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15141. isKnowKey = TRUE;
  15142. }
  15143. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15144. {
  15145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15148. {
  15149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15150. }
  15151. else
  15152. {
  15153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15154. }
  15155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15156. isKnowKey = TRUE;
  15157. }
  15158. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15159. {
  15160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15163. {
  15164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15165. }
  15166. else
  15167. {
  15168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15169. }
  15170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15171. isKnowKey = TRUE;
  15172. }
  15173. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15174. {
  15175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15178. {
  15179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15180. }
  15181. else
  15182. {
  15183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15184. }
  15185. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15187. isKnowKey = TRUE;
  15188. }
  15189. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15190. {
  15191. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15194. {
  15195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15196. }
  15197. else
  15198. {
  15199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15200. }
  15201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15202. isKnowKey = TRUE;
  15203. }
  15204. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15205. {
  15206. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15208. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15209. {
  15210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15211. }
  15212. else
  15213. {
  15214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15215. }
  15216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15217. isKnowKey = TRUE;
  15218. }
  15219. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15220. {
  15221. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15223. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15224. {
  15225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15226. }
  15227. else
  15228. {
  15229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15230. }
  15231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15232. isKnowKey = TRUE;
  15233. }
  15234. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15235. {
  15236. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15239. {
  15240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15241. }
  15242. else
  15243. {
  15244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15245. }
  15246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15247. isKnowKey = TRUE;
  15248. }
  15249. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15250. {
  15251. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15254. {
  15255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15256. }
  15257. else
  15258. {
  15259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15260. }
  15261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15262. isKnowKey = TRUE;
  15263. }
  15264. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15265. {
  15266. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15268. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15269. {
  15270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15271. }
  15272. else
  15273. {
  15274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15275. }
  15276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15277. isKnowKey = TRUE;
  15278. }
  15279. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15280. {
  15281. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15283. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15284. {
  15285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15286. }
  15287. else
  15288. {
  15289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15290. }
  15291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15292. isKnowKey = TRUE;
  15293. }
  15294. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15295. {
  15296. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15298. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15299. {
  15300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15301. }
  15302. else
  15303. {
  15304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15305. }
  15306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15307. isKnowKey = TRUE;
  15308. }
  15309. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15310. {
  15311. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15314. {
  15315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15316. }
  15317. else
  15318. {
  15319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15320. }
  15321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15322. isKnowKey = TRUE;
  15323. }
  15324. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15325. {
  15326. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15329. {
  15330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15331. }
  15332. else
  15333. {
  15334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15335. }
  15336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15337. isKnowKey = TRUE;
  15338. }
  15339. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15340. {
  15341. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15344. {
  15345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15346. }
  15347. else
  15348. {
  15349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15350. }
  15351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15352. isKnowKey = TRUE;
  15353. }
  15354. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15355. {
  15356. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15359. {
  15360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15361. }
  15362. else
  15363. {
  15364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15365. }
  15366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15367. isKnowKey = TRUE;
  15368. }
  15369. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15370. {
  15371. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15374. {
  15375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15376. }
  15377. else
  15378. {
  15379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15380. }
  15381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15382. isKnowKey = TRUE;
  15383. }
  15384. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15385. {
  15386. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15388. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15389. {
  15390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15391. }
  15392. else
  15393. {
  15394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15395. }
  15396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15397. isKnowKey = TRUE;
  15398. }
  15399. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15400. {
  15401. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15404. {
  15405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15406. }
  15407. else
  15408. {
  15409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15410. }
  15411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15412. isKnowKey = TRUE;
  15413. }
  15414. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15415. {
  15416. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15418. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15419. {
  15420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15421. }
  15422. else
  15423. {
  15424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15425. }
  15426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15427. isKnowKey = TRUE;
  15428. }
  15429. /*
  15430. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15431. {
  15432. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15435. {
  15436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15437. }
  15438. else
  15439. {
  15440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15441. }
  15442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15443. isKnowKey = TRUE;
  15444. }*/
  15445. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15446. {
  15447. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15450. {
  15451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15452. }
  15453. else
  15454. {
  15455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15456. }
  15457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15458. isKnowKey = TRUE;
  15459. }
  15460. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15461. {
  15462. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15465. {
  15466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15467. }
  15468. else
  15469. {
  15470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15471. }
  15472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15473. isKnowKey = TRUE;
  15474. }
  15475. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15476. {
  15477. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15480. {
  15481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15482. }
  15483. else
  15484. {
  15485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15486. }
  15487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15488. isKnowKey = TRUE;
  15489. }
  15490. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15491. {
  15492. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15495. {
  15496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15497. }
  15498. else
  15499. {
  15500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15501. }
  15502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15503. isKnowKey = TRUE;
  15504. }
  15505. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15506. {
  15507. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15510. {
  15511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15512. }
  15513. else
  15514. {
  15515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15516. }
  15517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15518. isKnowKey = TRUE;
  15519. }
  15520. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15521. {
  15522. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15525. {
  15526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15527. }
  15528. else
  15529. {
  15530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15531. }
  15532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15533. isKnowKey = TRUE;
  15534. }
  15535. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15536. {
  15537. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15539. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15540. {
  15541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15542. }
  15543. else
  15544. {
  15545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15546. }
  15547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15548. isKnowKey = TRUE;
  15549. }
  15550. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15551. {
  15552. struct sysinfo s_info;
  15553. int error = sysinfo(&s_info);
  15554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15557. {
  15558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15559. }
  15560. else
  15561. {
  15562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15563. }
  15564. if(error != 0)
  15565. {
  15566. DEBUG_WARN("System uptime get error: %d\n", error);
  15567. }
  15568. else
  15569. {
  15570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15571. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15572. }
  15573. isKnowKey = TRUE;
  15574. }
  15575. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15576. {
  15577. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15579. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15580. {
  15581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15582. }
  15583. else
  15584. {
  15585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15586. }
  15587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15588. isKnowKey = TRUE;
  15589. }
  15590. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15591. {
  15592. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15594. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15595. {
  15596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15597. }
  15598. else
  15599. {
  15600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15601. }
  15602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15603. isKnowKey = TRUE;
  15604. }
  15605. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15606. {
  15607. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15609. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15610. {
  15611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15612. }
  15613. else
  15614. {
  15615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15616. }
  15617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15618. isKnowKey = TRUE;
  15619. }
  15620. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15621. {
  15622. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15624. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15625. {
  15626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15627. }
  15628. else
  15629. {
  15630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15631. }
  15632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15633. isKnowKey = TRUE;
  15634. }
  15635. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15636. {
  15637. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15639. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15640. {
  15641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15642. }
  15643. else
  15644. {
  15645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15646. }
  15647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15648. isKnowKey = TRUE;
  15649. }
  15650. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15651. {
  15652. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15655. {
  15656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15657. }
  15658. else
  15659. {
  15660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15661. }
  15662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15663. isKnowKey = TRUE;
  15664. }
  15665. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15666. {
  15667. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15669. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15670. {
  15671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15672. }
  15673. else
  15674. {
  15675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15676. }
  15677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15678. isKnowKey = TRUE;
  15679. }
  15680. #if 1
  15681. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15682. {
  15683. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15685. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15686. {
  15687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15688. }
  15689. else
  15690. {
  15691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15692. }
  15693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15694. isKnowKey = TRUE;
  15695. }
  15696. #endif
  15697. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15698. {
  15699. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15701. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15702. {
  15703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15704. }
  15705. else
  15706. {
  15707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15708. }
  15709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15710. isKnowKey = TRUE;
  15711. }
  15712. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15713. {
  15714. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15716. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15717. {
  15718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15719. }
  15720. else
  15721. {
  15722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15723. }
  15724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15725. isKnowKey = TRUE;
  15726. }
  15727. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15728. {
  15729. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15731. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15732. {
  15733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15734. }
  15735. else
  15736. {
  15737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15738. }
  15739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15740. isKnowKey = TRUE;
  15741. }
  15742. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15743. {
  15744. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15746. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15747. {
  15748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15749. }
  15750. else
  15751. {
  15752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15753. }
  15754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15755. isKnowKey = TRUE;
  15756. }
  15757. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15758. {
  15759. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15761. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15762. {
  15763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15764. }
  15765. else
  15766. {
  15767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15768. }
  15769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15770. isKnowKey = TRUE;
  15771. }
  15772. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15773. {
  15774. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15776. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15777. {
  15778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15779. }
  15780. else
  15781. {
  15782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15783. }
  15784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15785. isKnowKey = TRUE;
  15786. }
  15787. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15788. {
  15789. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15791. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15792. {
  15793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15794. }
  15795. else
  15796. {
  15797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15798. }
  15799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15800. isKnowKey = TRUE;
  15801. }
  15802. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15803. {
  15804. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15806. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15807. {
  15808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15809. }
  15810. else
  15811. {
  15812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15813. }
  15814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15815. isKnowKey = TRUE;
  15816. }
  15817. //=========================================================
  15818. if(!isEmpty && !isKnowKey)
  15819. {
  15820. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15821. strcpy(unknownkey[UnknownKeynum], keyReq);
  15822. UnknownKeynum = UnknownKeynum + 1;
  15823. }
  15824. }
  15825. void processUnkownKey(void)
  15826. {
  15827. DEBUG_INFO("processUnkownKey...\n");
  15828. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15829. for(int index=0; index < UnknownKeynum; index++)
  15830. {
  15831. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15832. {
  15833. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15834. }
  15835. }
  15836. }
  15837. int setKeyValue(char *key, char *value)
  15838. {
  15839. int isSuccess = NotSupported;
  15840. int check_ascii=0;
  15841. char str[501]={0};
  15842. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15843. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15844. {
  15845. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15846. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15847. {
  15848. strcpy(str, (const char*)value);
  15849. for(int i = 0; str[i]; i++){
  15850. str[i] = tolower(str[i]);
  15851. }
  15852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15853. isSuccess = ConfigurationStatus_Accepted;
  15854. }
  15855. else
  15856. {
  15857. isSuccess = ConfigurationStatus_Rejected;
  15858. }
  15859. }
  15860. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15861. {
  15862. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15863. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15864. {
  15865. strcpy(str, (const char*)value);
  15866. for(int i = 0; str[i]; i++){
  15867. str[i] = tolower(str[i]);
  15868. }
  15869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15870. isSuccess = ConfigurationStatus_Accepted;
  15871. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15872. }
  15873. else
  15874. {
  15875. isSuccess = ConfigurationStatus_Rejected;
  15876. }
  15877. }
  15878. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15879. {
  15880. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15881. {
  15882. strcpy(str, (const char*)value);
  15883. for(int i = 0; str[i]; i++)
  15884. {
  15885. str[i] = tolower(str[i]);
  15886. }
  15887. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15889. isSuccess = ConfigurationStatus_Accepted;
  15890. }
  15891. else
  15892. {
  15893. isSuccess = ConfigurationStatus_Rejected;
  15894. }
  15895. }
  15896. if(strcmp(key, "BlinkRepeat") == 0)
  15897. {
  15898. //Charger.BlinkRepeat = Integer.parseInt(value);
  15899. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15900. {
  15901. check_ascii = value[0];
  15902. if( (check_ascii < 48) || (check_ascii > 57) )
  15903. {
  15904. isSuccess = ConfigurationStatus_Rejected;
  15905. }
  15906. else
  15907. {
  15908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15909. isSuccess = ConfigurationStatus_Accepted;
  15910. }
  15911. }
  15912. else
  15913. {
  15914. isSuccess = ConfigurationStatus_Rejected;
  15915. }
  15916. }
  15917. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15918. {
  15919. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15920. {
  15921. check_ascii = value[0];
  15922. if( (check_ascii < 48) || (check_ascii > 57) )
  15923. {
  15924. isSuccess = ConfigurationStatus_Rejected;
  15925. }
  15926. else
  15927. {
  15928. if((atoi(value) == 0) || (atoi(value) >= 5))
  15929. {
  15930. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15932. isSuccess = ConfigurationStatus_Accepted;
  15933. }
  15934. else
  15935. isSuccess = ConfigurationStatus_Rejected;
  15936. }
  15937. }
  15938. else
  15939. {
  15940. isSuccess = ConfigurationStatus_Rejected;
  15941. }
  15942. }
  15943. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15944. {
  15945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15946. {
  15947. check_ascii = value[0];
  15948. if( (check_ascii < 48) || (check_ascii > 57) )
  15949. {
  15950. isSuccess = ConfigurationStatus_Rejected;
  15951. }
  15952. else
  15953. {
  15954. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15956. isSuccess = ConfigurationStatus_Accepted;
  15957. }
  15958. }
  15959. else
  15960. {
  15961. isSuccess = ConfigurationStatus_Rejected;
  15962. }
  15963. }
  15964. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15965. {
  15966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15967. {
  15968. check_ascii = value[0];
  15969. if( (check_ascii < 48) || (check_ascii > 57) )
  15970. {
  15971. isSuccess = ConfigurationStatus_Rejected;
  15972. }
  15973. else
  15974. {
  15975. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15977. isSuccess = ConfigurationStatus_Accepted;
  15978. }
  15979. }
  15980. else
  15981. {
  15982. isSuccess = ConfigurationStatus_Rejected;
  15983. }
  15984. }
  15985. if(strcmp(key, "HeartbeatInterval") == 0)
  15986. {
  15987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15988. {
  15989. check_ascii = value[0];
  15990. if( (check_ascii < 48) || (check_ascii > 57) )
  15991. {
  15992. isSuccess = ConfigurationStatus_Rejected;
  15993. }
  15994. else
  15995. {
  15996. if((atoi(value) == 0) || (atoi(value) >= 10))
  15997. {
  15998. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16000. HeartBeatWaitTime = atoi(value);
  16001. isSuccess = ConfigurationStatus_Accepted;
  16002. }
  16003. else
  16004. {
  16005. isSuccess = ConfigurationStatus_Rejected;
  16006. }
  16007. }
  16008. }
  16009. else
  16010. {
  16011. isSuccess = ConfigurationStatus_Rejected;
  16012. }
  16013. }
  16014. if(strcmp(key, "LightIntensity") == 0)
  16015. {
  16016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16017. {
  16018. check_ascii = value[0];
  16019. if( (check_ascii < 48) || (check_ascii > 57) )
  16020. {
  16021. isSuccess = ConfigurationStatus_Rejected;
  16022. }
  16023. else
  16024. {
  16025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16026. isSuccess = ConfigurationStatus_Accepted;
  16027. }
  16028. }
  16029. else
  16030. {
  16031. isSuccess = ConfigurationStatus_Rejected;
  16032. }
  16033. }
  16034. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16035. {
  16036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16037. {
  16038. strcpy(str, (const char*)value);
  16039. for(int i = 0; str[i]; i++)
  16040. {
  16041. str[i] = tolower(str[i]);
  16042. }
  16043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16044. isSuccess = ConfigurationStatus_Accepted;
  16045. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16046. }
  16047. else
  16048. {
  16049. isSuccess = ConfigurationStatus_Rejected;
  16050. }
  16051. }
  16052. if(strcmp(key, "LocalPreAuthorize") == 0)
  16053. {
  16054. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16055. {
  16056. strcpy(str, (const char*)value);
  16057. for(int i = 0; str[i]; i++)
  16058. {
  16059. str[i] = tolower(str[i]);
  16060. }
  16061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16062. isSuccess = ConfigurationStatus_Accepted;
  16063. }
  16064. else
  16065. {
  16066. isSuccess = ConfigurationStatus_Rejected;
  16067. }
  16068. }
  16069. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16070. {
  16071. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16072. {
  16073. check_ascii = value[0];
  16074. if( (check_ascii < 48) || (check_ascii > 57) )
  16075. {
  16076. isSuccess = ConfigurationStatus_Rejected;
  16077. }
  16078. else
  16079. {
  16080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16081. isSuccess = ConfigurationStatus_Accepted;
  16082. }
  16083. }
  16084. else
  16085. {
  16086. isSuccess = ConfigurationStatus_Rejected;
  16087. }
  16088. }
  16089. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16090. {
  16091. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16092. {
  16093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16094. isSuccess = ConfigurationStatus_Accepted;
  16095. }
  16096. else
  16097. {
  16098. isSuccess = ConfigurationStatus_Rejected;
  16099. }
  16100. }
  16101. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16102. {
  16103. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16104. {
  16105. check_ascii = value[0];
  16106. if( (check_ascii < 48) || (check_ascii > 57) )
  16107. {
  16108. isSuccess = ConfigurationStatus_Rejected;
  16109. }
  16110. else
  16111. {
  16112. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16114. isSuccess = ConfigurationStatus_Accepted;
  16115. }
  16116. }
  16117. else
  16118. {
  16119. isSuccess = ConfigurationStatus_Rejected;
  16120. }
  16121. }
  16122. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16123. {
  16124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16125. {
  16126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16127. isSuccess = ConfigurationStatus_Accepted;
  16128. }
  16129. else
  16130. {
  16131. isSuccess = ConfigurationStatus_Rejected;
  16132. }
  16133. }
  16134. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16135. {
  16136. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16137. {
  16138. check_ascii = value[0];
  16139. if( (check_ascii < 48) || (check_ascii > 57) )
  16140. {
  16141. isSuccess = ConfigurationStatus_Rejected;
  16142. }
  16143. else
  16144. {
  16145. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16147. isSuccess = ConfigurationStatus_Accepted;
  16148. }
  16149. }
  16150. else
  16151. {
  16152. isSuccess = ConfigurationStatus_Rejected;
  16153. }
  16154. }
  16155. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16156. {
  16157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16158. {
  16159. check_ascii = value[0];
  16160. if( (check_ascii < 48) || (check_ascii > 57) )
  16161. {
  16162. isSuccess = ConfigurationStatus_Rejected;
  16163. }
  16164. else
  16165. {
  16166. if((atoi(value) == 0) || (atoi(value) >= 3))
  16167. {
  16168. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16170. isSuccess = ConfigurationStatus_Accepted;
  16171. }
  16172. else
  16173. {
  16174. isSuccess = ConfigurationStatus_Rejected;
  16175. }
  16176. }
  16177. }
  16178. else
  16179. {
  16180. isSuccess = ConfigurationStatus_Rejected;
  16181. }
  16182. }
  16183. if(strcmp(key, "MinimumStatusDuration") == 0)
  16184. {
  16185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16186. {
  16187. check_ascii = value[0];
  16188. if( (check_ascii < 48) || (check_ascii > 57) )
  16189. {
  16190. isSuccess = ConfigurationStatus_Rejected;
  16191. }
  16192. else
  16193. {
  16194. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16195. {
  16196. isSuccess = ConfigurationStatus_Rejected;
  16197. }
  16198. else
  16199. {
  16200. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16202. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16203. isSuccess = ConfigurationStatus_Accepted;
  16204. }
  16205. }
  16206. }
  16207. else
  16208. {
  16209. isSuccess = ConfigurationStatus_Rejected;
  16210. }
  16211. }
  16212. if(strcmp(key, "NumberOfConnectors") == 0)
  16213. {
  16214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16215. {
  16216. check_ascii = value[0];
  16217. if( (check_ascii < 48) || (check_ascii > 57) )
  16218. {
  16219. isSuccess = ConfigurationStatus_Rejected;
  16220. }
  16221. else
  16222. {
  16223. //Charger.ResetRetries = Integer.parseInt(value);
  16224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16225. isSuccess = ConfigurationStatus_Accepted;
  16226. }
  16227. }
  16228. else
  16229. {
  16230. isSuccess = ConfigurationStatus_Rejected;
  16231. }
  16232. }
  16233. if(strcmp(key, "ResetRetries") == 0)
  16234. {
  16235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16236. {
  16237. check_ascii = value[0];
  16238. if( (check_ascii < 48) || (check_ascii > 57) )
  16239. {
  16240. isSuccess = ConfigurationStatus_Rejected;
  16241. }
  16242. else
  16243. {
  16244. //Charger.ResetRetries = Integer.parseInt(value);
  16245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16246. isSuccess = ConfigurationStatus_Accepted;
  16247. }
  16248. }
  16249. else
  16250. {
  16251. isSuccess = ConfigurationStatus_Rejected;
  16252. }
  16253. }
  16254. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16255. {
  16256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16257. {
  16258. strcpy(str, (const char*)value);
  16259. for(int i = 0; str[i]; i++)
  16260. {
  16261. str[i] = tolower(str[i]);
  16262. }
  16263. if(strcmp(str, "notapplicable")== 0)
  16264. {
  16265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16266. isSuccess = ConfigurationStatus_Accepted;
  16267. }
  16268. else if(strcmp(str, "unknown")== 0)
  16269. {
  16270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16271. isSuccess = ConfigurationStatus_Accepted;
  16272. }
  16273. else if(strcmp(str, "rst")== 0)
  16274. {
  16275. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16276. isSuccess = ConfigurationStatus_Accepted;
  16277. }
  16278. else if(strcmp(str, "rts")== 0)
  16279. {
  16280. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16281. isSuccess = ConfigurationStatus_Accepted;
  16282. }
  16283. else if(strcmp(str, "srt")== 0)
  16284. {
  16285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16286. isSuccess = ConfigurationStatus_Accepted;
  16287. }
  16288. else if(strcmp(str, "str")== 0)
  16289. {
  16290. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16291. isSuccess = ConfigurationStatus_Accepted;
  16292. }
  16293. else if(strcmp(str, "trs")== 0)
  16294. {
  16295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16296. isSuccess = ConfigurationStatus_Accepted;
  16297. }
  16298. else if(strcmp(str, "tsr")== 0)
  16299. {
  16300. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16301. isSuccess = ConfigurationStatus_Accepted;
  16302. }
  16303. else
  16304. {
  16305. isSuccess = ConfigurationStatus_Rejected;
  16306. }
  16307. }
  16308. else
  16309. {
  16310. isSuccess = ConfigurationStatus_Rejected;
  16311. }
  16312. }
  16313. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16314. {
  16315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16316. {
  16317. check_ascii = value[0];
  16318. if( (check_ascii < 48) || (check_ascii > 57) )
  16319. {
  16320. isSuccess = ConfigurationStatus_Rejected;
  16321. }
  16322. else
  16323. {
  16324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16325. isSuccess = ConfigurationStatus_Accepted;
  16326. }
  16327. }
  16328. else
  16329. {
  16330. isSuccess = ConfigurationStatus_Rejected;
  16331. }
  16332. }
  16333. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16334. {
  16335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16336. {
  16337. strcpy(str, (const char*)value);
  16338. for(int i = 0; str[i]; i++)
  16339. {
  16340. str[i] = tolower(str[i]);
  16341. }
  16342. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16344. isSuccess = ConfigurationStatus_Accepted;
  16345. }
  16346. else
  16347. {
  16348. isSuccess = ConfigurationStatus_Rejected;
  16349. }
  16350. }
  16351. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16352. {
  16353. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16354. {
  16355. strcpy(str, (const char*)value);
  16356. for(int i = 0; str[i]; i++)
  16357. {
  16358. str[i] = tolower(str[i]);
  16359. }
  16360. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16362. isSuccess = ConfigurationStatus_Accepted;
  16363. }
  16364. else
  16365. {
  16366. isSuccess = ConfigurationStatus_Rejected;
  16367. }
  16368. }
  16369. if(strcmp(key, "StopTxnAlignedData") == 0)
  16370. {
  16371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16372. {
  16373. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16374. isSuccess = ConfigurationStatus_Accepted;
  16375. }
  16376. else
  16377. {
  16378. isSuccess = ConfigurationStatus_Rejected;
  16379. }
  16380. }
  16381. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16382. {
  16383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16384. {
  16385. check_ascii = value[0];
  16386. if( (check_ascii < 48) || (check_ascii > 57) )
  16387. {
  16388. isSuccess = ConfigurationStatus_Rejected;
  16389. }
  16390. else
  16391. {
  16392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16393. isSuccess = ConfigurationStatus_Accepted;
  16394. }
  16395. }
  16396. else
  16397. {
  16398. isSuccess = ConfigurationStatus_Rejected;
  16399. }
  16400. }
  16401. if(strcmp(key, "StopTxnSampledData") == 0)
  16402. {
  16403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16404. {
  16405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16406. isSuccess = ConfigurationStatus_Accepted;
  16407. }
  16408. else
  16409. {
  16410. isSuccess = ConfigurationStatus_Rejected;
  16411. }
  16412. }
  16413. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16414. {
  16415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16416. {
  16417. check_ascii = value[0];
  16418. if( (check_ascii < 48) || (check_ascii > 57) )
  16419. {
  16420. isSuccess = ConfigurationStatus_Rejected;
  16421. }
  16422. else
  16423. {
  16424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16425. isSuccess = ConfigurationStatus_Accepted;
  16426. }
  16427. }
  16428. else
  16429. {
  16430. isSuccess = ConfigurationStatus_Rejected;
  16431. }
  16432. }
  16433. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16434. {
  16435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16436. {
  16437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16438. isSuccess = ConfigurationStatus_Accepted;
  16439. }
  16440. else
  16441. {
  16442. isSuccess = ConfigurationStatus_Rejected;
  16443. }
  16444. }
  16445. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16446. {
  16447. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16448. {
  16449. check_ascii = value[0];
  16450. if( (check_ascii < 48) || (check_ascii > 57) )
  16451. {
  16452. isSuccess = ConfigurationStatus_Rejected;
  16453. }
  16454. else
  16455. {
  16456. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16457. isSuccess = ConfigurationStatus_Accepted;
  16458. }
  16459. }
  16460. else
  16461. {
  16462. isSuccess = ConfigurationStatus_Rejected;
  16463. }
  16464. }
  16465. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16466. {
  16467. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16468. {
  16469. check_ascii = value[0];
  16470. if( (check_ascii < 48) || (check_ascii > 57) )
  16471. {
  16472. isSuccess = ConfigurationStatus_Rejected;
  16473. }
  16474. else
  16475. {
  16476. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16478. TransactionMessageAttemptsValue = atoi(value);
  16479. isSuccess = ConfigurationStatus_Accepted;
  16480. }
  16481. }
  16482. else
  16483. {
  16484. isSuccess = ConfigurationStatus_Rejected;
  16485. }
  16486. }
  16487. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16488. {
  16489. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16490. {
  16491. check_ascii = value[0];
  16492. if( (check_ascii < 48) || (check_ascii > 57) )
  16493. {
  16494. isSuccess = ConfigurationStatus_Rejected;
  16495. }
  16496. else
  16497. {
  16498. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16500. TransactionMessageRetryIntervalValue = atoi(value);
  16501. isSuccess = ConfigurationStatus_Accepted;
  16502. }
  16503. }
  16504. else
  16505. {
  16506. isSuccess = ConfigurationStatus_Rejected;
  16507. }
  16508. }
  16509. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16510. {
  16511. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16512. {
  16513. strcpy(str, (const char*)value);
  16514. for(int i = 0; str[i]; i++)
  16515. {
  16516. str[i] = tolower(str[i]);
  16517. }
  16518. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16520. isSuccess = ConfigurationStatus_Accepted;
  16521. }
  16522. else
  16523. {
  16524. isSuccess = ConfigurationStatus_Rejected;
  16525. }
  16526. }
  16527. if(strcmp(key, "WebSocketPingInterval") == 0)
  16528. {
  16529. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16530. {
  16531. check_ascii = value[0];
  16532. if( (check_ascii < 48) || (check_ascii > 57) )
  16533. {
  16534. isSuccess = ConfigurationStatus_Rejected;
  16535. }
  16536. else
  16537. {
  16538. if((atoi(value) == 0) || (atoi(value) >= 10))
  16539. {
  16540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16541. isSuccess = ConfigurationStatus_Accepted;
  16542. }
  16543. else
  16544. isSuccess = ConfigurationStatus_Rejected;
  16545. }
  16546. }
  16547. else
  16548. {
  16549. isSuccess = ConfigurationStatus_Rejected;
  16550. }
  16551. }
  16552. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16553. {
  16554. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16555. {
  16556. strcpy(str, (const char*)value);
  16557. for(int i = 0; str[i]; i++)
  16558. {
  16559. str[i] = tolower(str[i]);
  16560. }
  16561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16562. isSuccess = ConfigurationStatus_Accepted;
  16563. }
  16564. else
  16565. {
  16566. isSuccess = ConfigurationStatus_Rejected;
  16567. }
  16568. }
  16569. if(strcmp(key, "AuthorizationKey") == 0)
  16570. {
  16571. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16572. {
  16573. strcpy(str, (const char*)value);
  16574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16575. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16576. isSuccess = ConfigurationStatus_Accepted;
  16577. }
  16578. else
  16579. {
  16580. isSuccess = ConfigurationStatus_Rejected;
  16581. }
  16582. }
  16583. if(strcmp(key, "SecurityProfile") == 0)
  16584. {
  16585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16586. {
  16587. check_ascii = value[0];
  16588. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16589. {
  16590. isSuccess = ConfigurationStatus_Rejected;
  16591. }
  16592. else if(check_ascii == 0x33)
  16593. {
  16594. isSuccess = NotSupported;
  16595. }
  16596. else
  16597. {
  16598. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16599. {
  16600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16601. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16602. isSuccess = ConfigurationStatus_Accepted;
  16603. }
  16604. else
  16605. isSuccess = ConfigurationStatus_Rejected;
  16606. }
  16607. }
  16608. else
  16609. {
  16610. isSuccess = ConfigurationStatus_Rejected;
  16611. }
  16612. }
  16613. if(strcmp(key, "DefaultPrice") == 0)
  16614. {
  16615. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16616. {
  16617. strcpy(str, (const char*)value);
  16618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16619. isSuccess = ConfigurationStatus_Accepted;
  16620. }
  16621. else
  16622. {
  16623. isSuccess = ConfigurationStatus_Rejected;
  16624. }
  16625. }
  16626. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16627. {
  16628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16629. {
  16630. strcpy(str, (const char*)value);
  16631. for(int i = 0; str[i]; i++)
  16632. {
  16633. str[i] = tolower(str[i]);
  16634. }
  16635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16636. isSuccess = ConfigurationStatus_Accepted;
  16637. }
  16638. else
  16639. {
  16640. isSuccess = ConfigurationStatus_Rejected;
  16641. }
  16642. }
  16643. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16644. {
  16645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16646. {
  16647. strcpy(str, (const char*)value);
  16648. for(int i = 0; str[i]; i++)
  16649. {
  16650. str[i] = tolower(str[i]);
  16651. }
  16652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16653. isSuccess = ConfigurationStatus_Accepted;
  16654. }
  16655. else
  16656. {
  16657. isSuccess = ConfigurationStatus_Rejected;
  16658. }
  16659. }
  16660. if(strcmp(key, "TimeOffset") == 0)
  16661. {
  16662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16663. {
  16664. strcpy(str, (const char*)value);
  16665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16666. isSuccess = ConfigurationStatus_Accepted;
  16667. }
  16668. else
  16669. {
  16670. isSuccess = ConfigurationStatus_Rejected;
  16671. }
  16672. }
  16673. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16674. {
  16675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16676. {
  16677. strcpy(str, (const char*)value);
  16678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16679. isSuccess = ConfigurationStatus_Accepted;
  16680. }
  16681. else
  16682. {
  16683. isSuccess = ConfigurationStatus_Rejected;
  16684. }
  16685. }
  16686. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16687. {
  16688. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16689. {
  16690. strcpy(str, (const char*)value);
  16691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16692. isSuccess = ConfigurationStatus_Accepted;
  16693. }
  16694. else
  16695. {
  16696. isSuccess = ConfigurationStatus_Rejected;
  16697. }
  16698. }
  16699. if(strcmp(key, "SystemUptimeSec") == 0)
  16700. {
  16701. isSuccess = NotSupported;
  16702. }
  16703. if(strcmp(key, "FreeVend") == 0)
  16704. {
  16705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16706. {
  16707. strcpy(str, (const char*)value);
  16708. for(int i = 0; str[i]; i++)
  16709. {
  16710. str[i] = tolower(str[i]);
  16711. }
  16712. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16714. isSuccess = ConfigurationStatus_Accepted;
  16715. }
  16716. else
  16717. {
  16718. isSuccess = ConfigurationStatus_Rejected;
  16719. }
  16720. }
  16721. if(strcmp(key, "FreeVendIdtag") == 0)
  16722. {
  16723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16724. {
  16725. strcpy(str, (const char*)value);
  16726. if(strlen(str) <= 20)
  16727. {
  16728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16729. isSuccess = ConfigurationStatus_Accepted;
  16730. }
  16731. else
  16732. {
  16733. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16734. isSuccess = ConfigurationStatus_Rejected;
  16735. }
  16736. }
  16737. else
  16738. {
  16739. isSuccess = ConfigurationStatus_Rejected;
  16740. }
  16741. }
  16742. if(strcmp(key, "OcppServer") == 0)
  16743. {
  16744. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16745. {
  16746. strcpy(str, (const char*)value);
  16747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16748. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16749. isSuccess = ConfigurationStatus_Accepted;
  16750. }
  16751. else
  16752. {
  16753. isSuccess = ConfigurationStatus_Rejected;
  16754. }
  16755. }
  16756. if(strcmp(key, "MaintainServer") == 0)
  16757. {
  16758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16759. {
  16760. strcpy(str, (const char*)value);
  16761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16762. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16763. isSuccess = ConfigurationStatus_Accepted;
  16764. }
  16765. else
  16766. {
  16767. isSuccess = ConfigurationStatus_Rejected;
  16768. }
  16769. }
  16770. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16771. {
  16772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16773. {
  16774. strcpy(str, (const char*)value);
  16775. for(int i = 0; str[i]; i++)
  16776. {
  16777. str[i] = tolower(str[i]);
  16778. }
  16779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16780. isSuccess = ConfigurationStatus_Accepted;
  16781. }
  16782. else
  16783. {
  16784. isSuccess = ConfigurationStatus_Rejected;
  16785. }
  16786. }
  16787. if(strcmp(key, "StatusNotificationInterval") == 0)
  16788. {
  16789. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16790. {
  16791. check_ascii = value[0];
  16792. if( (check_ascii < 48) || (check_ascii > 57) )
  16793. {
  16794. isSuccess = ConfigurationStatus_Rejected;
  16795. }
  16796. else
  16797. {
  16798. if((atoi(value) == 0) || (atoi(value) >= 10))
  16799. {
  16800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16801. isSuccess = ConfigurationStatus_Accepted;
  16802. }
  16803. else
  16804. isSuccess = ConfigurationStatus_Rejected;
  16805. }
  16806. }
  16807. else
  16808. {
  16809. isSuccess = ConfigurationStatus_Rejected;
  16810. }
  16811. }
  16812. #if 0
  16813. //For OCPP Test Case
  16814. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16815. {
  16816. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16817. {
  16818. strcpy(str, (const char*)value);
  16819. for(int i = 0; str[i]; i++)
  16820. {
  16821. str[i] = tolower(str[i]);
  16822. }
  16823. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16824. isSuccess = ConfigurationStatus_Accepted;
  16825. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16826. }
  16827. else
  16828. {
  16829. isSuccess = ConfigurationStatus_Rejected;
  16830. }
  16831. }
  16832. #endif
  16833. #if 1
  16834. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16835. {
  16836. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16837. {
  16838. strcpy(str, (const char*)value);
  16839. for(int i = 0; str[i]; i++)
  16840. {
  16841. str[i] = tolower(str[i]);
  16842. }
  16843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16844. isSuccess = ConfigurationStatus_Accepted;
  16845. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16846. }
  16847. else
  16848. {
  16849. isSuccess = ConfigurationStatus_Rejected;
  16850. }
  16851. }
  16852. #endif
  16853. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16854. {
  16855. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16856. {
  16857. check_ascii = value[0];
  16858. if( (check_ascii < 48) || (check_ascii > 57) )
  16859. {
  16860. isSuccess = ConfigurationStatus_Rejected;
  16861. }
  16862. else
  16863. {
  16864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16865. isSuccess = ConfigurationStatus_Accepted;
  16866. }
  16867. }
  16868. else
  16869. {
  16870. isSuccess = ConfigurationStatus_Rejected;
  16871. }
  16872. }
  16873. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16874. {
  16875. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16876. {
  16877. check_ascii = value[0];
  16878. if( (check_ascii < 48) || (check_ascii > 57) )
  16879. {
  16880. isSuccess = ConfigurationStatus_Rejected;
  16881. }
  16882. else
  16883. {
  16884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16885. isSuccess = ConfigurationStatus_Accepted;
  16886. }
  16887. }
  16888. else
  16889. {
  16890. isSuccess = ConfigurationStatus_Rejected;
  16891. }
  16892. }
  16893. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16894. {
  16895. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16896. {
  16897. strcpy(str, (const char*)value);
  16898. for(int i = 0; str[i]; i++)
  16899. {
  16900. str[i] = tolower(str[i]);
  16901. }
  16902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16903. isSuccess = ConfigurationStatus_Accepted;
  16904. }
  16905. else
  16906. {
  16907. isSuccess = ConfigurationStatus_Rejected;
  16908. }
  16909. }
  16910. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16911. {
  16912. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16913. {
  16914. check_ascii = value[0];
  16915. if( (check_ascii < 48) || (check_ascii > 57) )
  16916. {
  16917. isSuccess = ConfigurationStatus_Rejected;
  16918. }
  16919. else
  16920. {
  16921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16922. isSuccess = ConfigurationStatus_Accepted;
  16923. }
  16924. }
  16925. else
  16926. {
  16927. isSuccess = ConfigurationStatus_Rejected;
  16928. }
  16929. }
  16930. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16931. {
  16932. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16933. {
  16934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16935. isSuccess = ConfigurationStatus_Accepted;
  16936. }
  16937. else
  16938. {
  16939. isSuccess = ConfigurationStatus_Rejected;
  16940. }
  16941. }
  16942. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16943. {
  16944. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16945. {
  16946. check_ascii = value[0];
  16947. if( (check_ascii < 48) || (check_ascii > 57) )
  16948. {
  16949. isSuccess = ConfigurationStatus_Rejected;
  16950. }
  16951. else
  16952. {
  16953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16954. isSuccess = ConfigurationStatus_Accepted;
  16955. }
  16956. }
  16957. else
  16958. {
  16959. isSuccess = ConfigurationStatus_Rejected;
  16960. }
  16961. }
  16962. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16963. {
  16964. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16965. {
  16966. strcpy(str, (const char*)value);
  16967. for(int i = 0; str[i]; i++)
  16968. {
  16969. str[i] = tolower(str[i]);
  16970. }
  16971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16972. isSuccess = ConfigurationStatus_Accepted;
  16973. }
  16974. else
  16975. {
  16976. isSuccess = ConfigurationStatus_Rejected;
  16977. }
  16978. }
  16979. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16980. {
  16981. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16982. {
  16983. check_ascii = value[0];
  16984. if( (check_ascii < 48) || (check_ascii > 57) )
  16985. {
  16986. isSuccess = ConfigurationStatus_Rejected;
  16987. }
  16988. else
  16989. {
  16990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16991. isSuccess = ConfigurationStatus_Accepted;
  16992. }
  16993. }
  16994. else
  16995. {
  16996. isSuccess = ConfigurationStatus_Rejected;
  16997. }
  16998. }
  16999. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17000. return isSuccess;
  17001. }
  17002. int TransactionMessageAttemptsGet(void)
  17003. {
  17004. return TransactionMessageAttemptsValue;
  17005. }
  17006. int FirstHeartBeatResponse(void)
  17007. {
  17008. return FirstHeartBeat;
  17009. }
  17010. int TransactionMessageRetryIntervalGet(void)
  17011. {
  17012. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17013. }
  17014. int ReadHttpStatus(int sock)
  17015. {
  17016. //char c;
  17017. char buff[1024]="",*ptr=buff+1;
  17018. int bytes_received, status;
  17019. DEBUG_INFO("Begin Response ..\n");
  17020. while((bytes_received = recv(sock, ptr, 1, 0))){
  17021. if(bytes_received==-1){
  17022. perror("ReadHttpStatus");
  17023. exit(1);
  17024. }
  17025. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17026. ptr++;
  17027. }
  17028. *ptr=0;
  17029. ptr=buff+1;
  17030. sscanf(ptr,"%*s %d ", &status);
  17031. DEBUG_INFO("%s\n",ptr);
  17032. DEBUG_INFO("status=%d\n",status);
  17033. DEBUG_INFO("End Response ..\n");
  17034. return (bytes_received>0)?status:0;
  17035. }
  17036. //the only filed that it parsed is 'Content-Length'
  17037. int ParseHeader(int sock)
  17038. {
  17039. //char c;
  17040. char buff[1024]="",*ptr=buff+4;
  17041. int bytes_received;
  17042. DEBUG_INFO("Begin HEADER ..\n");
  17043. while((bytes_received = recv(sock, ptr, 1, 0))){
  17044. if(bytes_received==-1){
  17045. perror("Parse Header");
  17046. exit(1);
  17047. }
  17048. if(
  17049. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17050. (ptr[-1]=='\r') && (*ptr=='\n' )
  17051. ) break;
  17052. ptr++;
  17053. }
  17054. *ptr=0;
  17055. ptr=buff+4;
  17056. //printf("%s",ptr);
  17057. if(bytes_received){
  17058. ptr=strstr(ptr,"Content-Length:");
  17059. if(ptr){
  17060. sscanf(ptr,"%*s %d",&bytes_received);
  17061. }else
  17062. bytes_received=-1; //unknown size
  17063. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17064. }
  17065. DEBUG_INFO("End HEADER ..\n");
  17066. return bytes_received ;
  17067. }
  17068. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17069. {
  17070. int result = TRUE;
  17071. char rmFileCmd[100]={0};
  17072. char FilePath[100]={0};
  17073. char ftpbuf[200];
  17074. int systemresult;
  17075. sprintf(FilePath,"/mnt/%s",filename);
  17076. system("ping 8.8.8.8 &");
  17077. if((access(FilePath,F_OK))!=-1)
  17078. {
  17079. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17080. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17081. system(rmFileCmd);
  17082. }
  17083. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17084. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17085. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17086. systemresult = system(ftpbuf);
  17087. if(systemresult != 0)
  17088. {
  17089. DEBUG_INFO("http DownLoad error!\n");
  17090. result = FALSE;
  17091. }
  17092. system("pkill ping");
  17093. return result;
  17094. }
  17095. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17096. {
  17097. int result = TRUE;
  17098. char rmFileCmd[100]={0};
  17099. char FilePath[100]={0};
  17100. char ftpbuf[200];
  17101. int systemresult;
  17102. sprintf(FilePath,"/mnt/%s",filename);
  17103. system("ping 8.8.8.8 &");
  17104. if((access(FilePath,F_OK))!=-1)
  17105. {
  17106. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17107. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17108. system(rmFileCmd);
  17109. }
  17110. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17111. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  17112. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17113. systemresult = system(ftpbuf);
  17114. if(systemresult != 0)
  17115. {
  17116. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17117. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17118. systemresult = system(ftpbuf);
  17119. if(systemresult != 0)
  17120. {
  17121. DEBUG_WARN("wget error!\n");
  17122. result = FALSE;
  17123. }
  17124. }
  17125. system("pkill ping");
  17126. return result;
  17127. }
  17128. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17129. {
  17130. char rmFileCmd[100]={0};
  17131. char FilePath[100]={0};
  17132. char buf[512];
  17133. int systemresult = 0;
  17134. //DEBUG_INFO("filename=%s\n",filename);
  17135. //DEBUG_INFO("url=%s\n",url);
  17136. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17137. if((access(FilePath,F_OK))!=-1)
  17138. {
  17139. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17140. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17141. system(rmFileCmd);
  17142. }
  17143. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17144. if(fp == NULL)
  17145. {
  17146. DEBUG_INFO("log is NULL\n");
  17147. return FALSE;
  17148. }
  17149. else
  17150. {
  17151. fprintf(fp, "%s\n", url);
  17152. fprintf(fp, "%s\n", filename);
  17153. fclose(fp);
  17154. }
  17155. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17156. if(phpFP == NULL)
  17157. {
  17158. DEBUG_INFO("PHP upload fail.\n");
  17159. return FALSE;
  17160. }
  17161. else
  17162. {
  17163. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17164. {
  17165. if(strstr(buf, "result") != NULL)
  17166. {
  17167. sscanf(buf, "result: %d", &systemresult);
  17168. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17169. }
  17170. }
  17171. pclose(phpFP);
  17172. }
  17173. if(systemresult != 1)
  17174. {
  17175. DEBUG_INFO("HTTP upload error!\n");
  17176. return FALSE;
  17177. }
  17178. return TRUE;
  17179. }
  17180. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17181. {
  17182. int result = FALSE;
  17183. char ftpbuf[200];
  17184. int systemresult;
  17185. /*
  17186. // Domaind name transfer to IP address
  17187. struct hostent* server;
  17188. char *IPbuffer;
  17189. server = gethostbyname(location);
  17190. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17191. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17192. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17193. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17194. systemresult = system(ftpbuf);
  17195. if(systemresult != 0)
  17196. {
  17197. DEBUG_INFO("ftpput error!\n");
  17198. }
  17199. else
  17200. {
  17201. result = TRUE;
  17202. DEBUG_INFO("ftpput OK!\n");
  17203. }
  17204. return result;
  17205. }
  17206. int GetOcppServerURL()
  17207. {
  17208. int result = FALSE;
  17209. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17210. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17211. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17212. struct yuarel url;
  17213. char urlStr[512];
  17214. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17215. {
  17216. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17217. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17218. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17219. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17220. if(yuarel_parse(&url, urlStr) != -1)
  17221. {
  17222. sprintf(OcppProtocol, "%s", url.scheme);
  17223. sprintf(OcppHost, "%s", url.host);
  17224. if(url.path == NULL)
  17225. OcppTempPath[0] = '\0';
  17226. else
  17227. {
  17228. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17229. {
  17230. sprintf(OcppTempPath, "%s/", url.path);
  17231. }
  17232. else
  17233. {
  17234. sprintf(OcppTempPath, "%s", url.path);
  17235. }
  17236. }
  17237. if(url.port == 0)
  17238. {
  17239. if(strcmp(OcppProtocol, "wss") == 0)
  17240. OcppPort = 443;
  17241. else
  17242. OcppPort = 80;
  17243. }
  17244. else
  17245. OcppPort = url.port;
  17246. result = TRUE;
  17247. }
  17248. }
  17249. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17250. {
  17251. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17252. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17253. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17254. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17255. if(yuarel_parse(&url, urlStr) != -1)
  17256. {
  17257. sprintf(OcppProtocol, "%s", url.scheme);
  17258. sprintf(OcppHost, "%s", url.host);
  17259. if(url.path == NULL)
  17260. OcppTempPath[0] = '\0';
  17261. else
  17262. sprintf(OcppTempPath, "%s", url.path);
  17263. if(url.port == 0)
  17264. {
  17265. if(strcmp(OcppProtocol, "wss") == 0)
  17266. OcppPort = 443;
  17267. else
  17268. OcppPort = 80;
  17269. }
  17270. else
  17271. OcppPort = url.port;
  17272. result = TRUE;
  17273. }
  17274. }
  17275. else
  17276. {
  17277. strcpy(OcppHost,"");
  17278. }
  17279. return result;
  17280. }
  17281. int GetOcppPath()
  17282. {
  17283. int result = FALSE;
  17284. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17285. {
  17286. if(OcppTempPath == NULL)
  17287. {
  17288. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17289. }
  17290. else
  17291. {
  17292. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17293. }
  17294. result = TRUE;
  17295. goto End;
  17296. }
  17297. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17298. {
  17299. if(OcppTempPath == NULL)
  17300. {
  17301. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17302. }
  17303. else
  17304. {
  17305. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17306. }
  17307. result = TRUE;
  17308. goto End;
  17309. }
  17310. else
  17311. {
  17312. strcpy(OcppPath,"");
  17313. }
  17314. End:
  17315. return result;
  17316. }
  17317. int GetOcppPort()
  17318. {
  17319. return OcppPort;
  17320. }
  17321. int GetOcppConnStatus(void)
  17322. {
  17323. return ShmOCPP16Data->OcppConnStatus;
  17324. }
  17325. void SetOcppConnStatus(uint8_t status)
  17326. {
  17327. ShmOCPP16Data->OcppConnStatus = status;
  17328. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17329. }
  17330. int GetHeartBeatWithNOResponse(void)
  17331. {
  17332. return HeartBeatWithNOResponse;
  17333. }
  17334. void SetHeartBeatWithNOResponse(void)
  17335. {
  17336. HeartBeatWithNOResponse = 0;
  17337. }
  17338. void GetStartTransactionIdTag(int gun_index)
  17339. {
  17340. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17341. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17342. }
  17343. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17344. {
  17345. char ch;
  17346. FILE *fptr1;
  17347. int temptransactionId;
  17348. char str[100]={0};
  17349. temptransactionId = 0;
  17350. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17351. {
  17352. DEBUG_INFO("IdTag is empty.\n");
  17353. return temptransactionId;
  17354. }
  17355. /*------ Read the file ----------------*/
  17356. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17357. if (!fptr1)
  17358. {
  17359. DEBUG_INFO("QueueTransactionId file open error.\n");
  17360. //printf(" File not found or unable to open the input file!!\n");
  17361. return temptransactionId;
  17362. }
  17363. ch=fgetc(fptr1);
  17364. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17365. rewind(fptr1);
  17366. if(ch!=EOF)
  17367. {
  17368. // printf("%c",ch);
  17369. while (fgets(str, 100, fptr1) != NULL)
  17370. {
  17371. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17372. if(str[0]=='\0')
  17373. {
  17374. break;
  17375. }
  17376. char *revbuf[8] = {0}; // Variable store string split
  17377. int num = 0;// Quantity after string split
  17378. DEBUG_INFO("Transaction queue data= %s\n", str);
  17379. splitstring(str,",",revbuf,&num); // String split
  17380. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17381. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17382. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17383. DEBUG_INFO("------------------------------\n");
  17384. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17385. {
  17386. if(isStopTransaction)
  17387. {
  17388. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17389. {
  17390. temptransactionId = atoi(revbuf[2]);
  17391. //break;
  17392. }
  17393. }
  17394. else
  17395. {
  17396. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17397. {
  17398. temptransactionId = atoi(revbuf[2]);
  17399. //break;
  17400. }
  17401. }
  17402. }
  17403. }
  17404. }
  17405. else
  17406. DEBUG_INFO("EOF\n");
  17407. fclose(fptr1);
  17408. /*------- End of reading ---------------*/
  17409. return temptransactionId;
  17410. }
  17411. void SetTransactionIdZero(int transactionId)
  17412. {
  17413. char ch;
  17414. FILE *fptr1, *fptr2;
  17415. int temptransactionId = 0;
  17416. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17417. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17418. if (!fptr1)
  17419. {
  17420. //printf(" File not found or unable to open the input file!!\n");
  17421. return ;
  17422. }
  17423. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17424. if (!fptr2)
  17425. {
  17426. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17427. fclose(fptr1);
  17428. return ;
  17429. }
  17430. ch=fgetc(fptr1);
  17431. rewind(fptr1);
  17432. if(ch!=EOF)
  17433. {
  17434. // copy all contents to the temporary file except the specific line
  17435. while (fgets(str, 100, fptr1) != NULL)
  17436. {
  17437. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17438. if(str[0]=='\0')
  17439. {
  17440. break;
  17441. }
  17442. char *revbuf[8] = {0};
  17443. int num = 0;
  17444. strcpy(strtemp, str);
  17445. splitstring(str,",",revbuf,&num);
  17446. if(revbuf[2][0] != '\0')
  17447. {
  17448. temptransactionId = atoi(revbuf[2]);
  17449. if(transactionId != temptransactionId)
  17450. {
  17451. fprintf(fptr2, "%s\n", strtemp);
  17452. }
  17453. }
  17454. }
  17455. }
  17456. fclose(fptr1);
  17457. fclose(fptr2);
  17458. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17459. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17460. /*------ Read the file ----------------*/
  17461. }
  17462. int InternetDisconnect(void)
  17463. {
  17464. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17465. }
  17466. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17467. void storeTempStopTransaction(int gun_index)
  17468. {
  17469. char guid[37]={0};
  17470. int tempIndex = 0;
  17471. char TempStopTransaction[256];
  17472. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17473. DEBUG_INFO("storeTempStopTransaction...\n");
  17474. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17475. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17476. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17477. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17478. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17479. {
  17480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17481. {
  17482. tempIndex = ((gun_index==2) ? 1: 0);
  17483. }
  17484. else
  17485. {
  17486. tempIndex = gun_index;
  17487. }
  17488. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17489. {
  17490. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17491. {
  17492. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17493. }
  17494. }// END OF CHAdeMO_QUANTITY
  17495. }
  17496. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17497. {
  17498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17499. {
  17500. tempIndex = ((gun_index==2) ? 1: 0);
  17501. }
  17502. else
  17503. {
  17504. tempIndex = gun_index;
  17505. }
  17506. for (int index = 0; index < CCS_QUANTITY; index++)
  17507. {
  17508. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17509. {
  17510. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17511. }
  17512. }// END OF CCS_QUANTITY
  17513. }
  17514. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17515. {
  17516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17517. {
  17518. tempIndex = ((gun_index==2) ? 1: 0);
  17519. }
  17520. else
  17521. {
  17522. tempIndex = gun_index;
  17523. }
  17524. for (int index = 0; index < GB_QUANTITY; index++)
  17525. {
  17526. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17527. {
  17528. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17529. }
  17530. }// END OF GB_QUANTITY
  17531. }
  17532. else if(gunType[gun_index] == GUN_TYPE_DO)
  17533. {
  17534. tempIndex = gun_index;
  17535. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17536. {
  17537. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17538. {
  17539. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17540. }
  17541. }
  17542. }
  17543. else
  17544. {
  17545. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17546. {
  17547. tempIndex = 2;
  17548. }
  17549. else
  17550. {
  17551. tempIndex = gun_index;
  17552. }
  17553. for (int index = 0; index < AC_QUANTITY; index++)
  17554. {
  17555. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17556. {
  17557. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17558. }
  17559. }// END OF AC_QUANTITY
  17560. }
  17561. //Stop Transaction Time
  17562. struct timeval tmnow;
  17563. struct tm *tm;
  17564. char buf[28];//, usec_buf[6];
  17565. gettimeofday(&tmnow, NULL);
  17566. time_t t;
  17567. t = time(NULL);
  17568. /*UTC time and date*/
  17569. tm = gmtime(&t);
  17570. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17572. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17574. random_uuid(guid);
  17575. /***********************************transactionData******************************************************/
  17576. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17578. //=================================
  17579. //1. Transaction_Begin
  17580. //=================================
  17581. //============================== Energy.Active.Import.Interval ===========================================
  17582. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17583. {
  17584. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  17588. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17589. 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))
  17590. {
  17591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17592. }
  17593. else
  17594. {
  17595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17596. }
  17597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17599. }
  17600. //=================================
  17601. //2. Transaction_End
  17602. //=================================
  17603. //2.1====================================== Current.Import L1 ==============================================
  17604. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17605. {
  17606. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17607. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17608. {
  17609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17610. {
  17611. tempIndex = ((gun_index==2) ? 1: 0);
  17612. }
  17613. else
  17614. {
  17615. tempIndex = gun_index;
  17616. }
  17617. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17618. {
  17619. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17620. {
  17621. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17622. }
  17623. }// End of for CHAdeMO_QUANTITY
  17624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17625. }
  17626. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17627. {
  17628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17629. {
  17630. tempIndex = ((gun_index==2) ? 1: 0);
  17631. }
  17632. else
  17633. {
  17634. tempIndex = gun_index;
  17635. }
  17636. for (int index = 0; index < CCS_QUANTITY; index++)
  17637. {
  17638. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17639. {
  17640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17641. }
  17642. }// End of for CCS_QUANTITY
  17643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17644. }
  17645. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17646. {
  17647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17648. {
  17649. tempIndex = ((gun_index==2) ? 1: 0);
  17650. }
  17651. else
  17652. {
  17653. tempIndex = gun_index;
  17654. }
  17655. for (int index = 0; index < GB_QUANTITY; index++)
  17656. {
  17657. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17658. {
  17659. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17660. }
  17661. }// End of for GB_QUANTITY
  17662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17663. }
  17664. else if(gunType[gun_index] == GUN_TYPE_DO)
  17665. {
  17666. tempIndex = gun_index;
  17667. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17668. {
  17669. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17670. {
  17671. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17672. }
  17673. }
  17674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17675. }
  17676. else
  17677. {
  17678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17679. {
  17680. tempIndex = 2;
  17681. }
  17682. else
  17683. {
  17684. tempIndex = gun_index;
  17685. }
  17686. for (int index = 0; index < AC_QUANTITY; index++)
  17687. {
  17688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17689. {
  17690. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17691. }
  17692. }// End of for AC_QUANTITY
  17693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17694. }
  17695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17698. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17701. }
  17702. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17703. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17704. {
  17705. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17706. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17707. {
  17708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17709. {
  17710. tempIndex = ((gun_index==2) ? 1: 0);
  17711. }
  17712. else
  17713. {
  17714. tempIndex = gun_index;
  17715. }
  17716. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17717. {
  17718. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17719. {
  17720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17721. }
  17722. }// END OF CHAdeMO_QUANTITY
  17723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17724. }
  17725. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17726. {
  17727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17728. {
  17729. tempIndex = ((gun_index==2) ? 1: 0);
  17730. }
  17731. else
  17732. {
  17733. tempIndex = gun_index;
  17734. }
  17735. for (int index = 0; index < CCS_QUANTITY; index++)
  17736. {
  17737. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17738. {
  17739. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17740. }
  17741. }// END OF CCS_QUANTITY
  17742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17743. }
  17744. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17745. {
  17746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17747. {
  17748. tempIndex = ((gun_index==2) ? 1: 0);
  17749. }
  17750. else
  17751. {
  17752. tempIndex = gun_index;
  17753. }
  17754. for (int index = 0; index < GB_QUANTITY; index++)
  17755. {
  17756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17757. {
  17758. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17759. }
  17760. }// END OF GB_QUANTITY
  17761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17762. }
  17763. else if(gunType[gun_index] == GUN_TYPE_DO)
  17764. {
  17765. tempIndex = gun_index;
  17766. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17767. {
  17768. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17769. {
  17770. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17771. }
  17772. }
  17773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17774. }
  17775. else
  17776. {
  17777. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17778. {
  17779. tempIndex = 2;
  17780. }
  17781. else
  17782. {
  17783. tempIndex = gun_index;
  17784. }
  17785. for (int index = 0; index < AC_QUANTITY; index++)
  17786. {
  17787. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17788. {
  17789. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17790. }
  17791. }// END OF AC_QUANTITY
  17792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17793. }
  17794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17797. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17800. }
  17801. //2.3====================================== Power.Active.Import =========================================
  17802. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17803. {
  17804. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17805. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17806. {
  17807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17808. {
  17809. tempIndex = ((gun_index==2) ? 1: 0);
  17810. }
  17811. else
  17812. {
  17813. tempIndex = gun_index;
  17814. }
  17815. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17816. {
  17817. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17818. {
  17819. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17820. }
  17821. } // End for CHAdeMO_QUANTITY
  17822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17823. }
  17824. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17825. {
  17826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17827. {
  17828. tempIndex = ((gun_index==2) ? 1: 0);
  17829. }
  17830. else
  17831. {
  17832. tempIndex = gun_index;
  17833. }
  17834. for (int index = 0; index < CCS_QUANTITY; index++)
  17835. {
  17836. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17837. {
  17838. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17839. }
  17840. } // END for CCS_QUANTITY
  17841. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17842. }
  17843. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17844. {
  17845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17846. {
  17847. tempIndex = ((gun_index==2) ? 1: 0);
  17848. }
  17849. else
  17850. {
  17851. tempIndex = gun_index;
  17852. }
  17853. for (int index = 0; index < GB_QUANTITY; index++)
  17854. {
  17855. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17856. {
  17857. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17858. }
  17859. }// END for GB_QUANTITY
  17860. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17861. }
  17862. else if(gunType[gun_index] == GUN_TYPE_DO)
  17863. {
  17864. tempIndex = gun_index;
  17865. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17866. {
  17867. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17868. {
  17869. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17870. }
  17871. }
  17872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17873. }
  17874. else
  17875. {
  17876. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17877. {
  17878. tempIndex = 2;
  17879. }
  17880. else
  17881. {
  17882. tempIndex = gun_index;
  17883. }
  17884. for (int index = 0; index < AC_QUANTITY; index++)
  17885. {
  17886. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17887. {
  17888. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17889. }
  17890. } // END for AC_QUANTITY
  17891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17892. }
  17893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17896. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17899. }
  17900. //2.4====================================== Voltage L1 ====================================================
  17901. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17902. {
  17903. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17904. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17905. {
  17906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17907. {
  17908. tempIndex = ((gun_index==2) ? 1: 0);
  17909. }
  17910. else
  17911. {
  17912. tempIndex = gun_index;
  17913. }
  17914. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17915. {
  17916. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17917. {
  17918. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17919. }
  17920. } // END OF FOR CHAdeMO_QUANTITY
  17921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17922. }
  17923. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17924. {
  17925. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17926. {
  17927. tempIndex = ((gun_index==2) ? 1: 0);
  17928. }
  17929. else
  17930. {
  17931. tempIndex = gun_index;
  17932. }
  17933. for (int index = 0; index < CCS_QUANTITY; index++)
  17934. {
  17935. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17936. {
  17937. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17938. }
  17939. } // END OF FOR CCS_QUANTITY
  17940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17941. }
  17942. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17943. {
  17944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17945. {
  17946. tempIndex = ((gun_index==2) ? 1: 0);
  17947. }
  17948. else
  17949. {
  17950. tempIndex = gun_index;
  17951. }
  17952. for (int index = 0; index < GB_QUANTITY; index++)
  17953. {
  17954. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17955. {
  17956. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17957. }
  17958. } // END OF FOR GB_QUANTITY
  17959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17960. }
  17961. else if(gunType[gun_index] == GUN_TYPE_DO)
  17962. {
  17963. tempIndex = gun_index;
  17964. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17965. {
  17966. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17967. {
  17968. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17969. }
  17970. }
  17971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17972. }
  17973. else
  17974. {
  17975. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17976. {
  17977. tempIndex = 2;
  17978. }
  17979. else
  17980. {
  17981. tempIndex = gun_index;
  17982. }
  17983. for (int index = 0; index < AC_QUANTITY; index++)
  17984. {
  17985. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17986. {
  17987. 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
  17988. }
  17989. } // END OF FOR AC_QUANTITY
  17990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17991. }
  17992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17995. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17998. }
  17999. //2.5============================================== End SoC =========================================================
  18000. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18001. {
  18002. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18003. 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))
  18004. {
  18005. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18006. {
  18007. tempIndex = ((gun_index==2) ? 1: 0);
  18008. }
  18009. else
  18010. {
  18011. tempIndex = gun_index;
  18012. }
  18013. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18014. {
  18015. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18016. {
  18017. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18018. {
  18019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18020. }
  18021. }
  18022. }
  18023. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18024. {
  18025. for (int index = 0; index < CCS_QUANTITY; index++)
  18026. {
  18027. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18028. {
  18029. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18030. }
  18031. }
  18032. }
  18033. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18034. {
  18035. for (int index = 0; index < GB_QUANTITY; index++)
  18036. {
  18037. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18038. {
  18039. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18040. }
  18041. }
  18042. }
  18043. else if(gunType[gun_index] == GUN_TYPE_DO)
  18044. {
  18045. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18046. {
  18047. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18048. {
  18049. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18050. }
  18051. }
  18052. }
  18053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18059. } // END FOR DC CASE
  18060. }
  18061. //2.6====================================== Current.Import L2 ==============================================
  18062. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18063. {
  18064. // AC 3 phase L2 current
  18065. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18066. {
  18067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18068. {
  18069. tempIndex = 2;
  18070. }
  18071. else
  18072. {
  18073. tempIndex = gun_index;
  18074. }
  18075. for (int index = 0; index < AC_QUANTITY; index++)
  18076. {
  18077. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18078. {
  18079. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18080. }
  18081. }// End of for AC_QUANTITY
  18082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18083. }
  18084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18089. }
  18090. //2.7====================================== Current.Import L3 ==============================================
  18091. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18092. {
  18093. // AC 3 phase L3 current
  18094. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18095. {
  18096. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18097. {
  18098. tempIndex = 2;
  18099. }
  18100. else
  18101. {
  18102. tempIndex = gun_index;
  18103. }
  18104. for (int index = 0; index < AC_QUANTITY; index++)
  18105. {
  18106. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18107. {
  18108. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18109. }
  18110. }// End of for AC_QUANTITY
  18111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18112. }
  18113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18118. }
  18119. //2.9====================================== Voltage L2 ====================================================
  18120. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18121. {
  18122. // AC 3 phase L2 volatge
  18123. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18124. {
  18125. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18126. {
  18127. tempIndex = 2;
  18128. }
  18129. else
  18130. {
  18131. tempIndex = gun_index;
  18132. }
  18133. for (int index = 0; index < AC_QUANTITY; index++)
  18134. {
  18135. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18136. {
  18137. 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
  18138. }
  18139. } // END OF FOR AC_QUANTITY
  18140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18141. }
  18142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18147. }
  18148. //2.10====================================== Voltage L3 ====================================================
  18149. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18150. {
  18151. // AC 3 phase L3 volatge
  18152. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18153. {
  18154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18155. {
  18156. tempIndex = 2;
  18157. }
  18158. else
  18159. {
  18160. tempIndex = gun_index;
  18161. }
  18162. for (int index = 0; index < AC_QUANTITY; index++)
  18163. {
  18164. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18165. {
  18166. 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
  18167. }
  18168. } // END OF FOR AC_QUANTITY
  18169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18170. }
  18171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18176. }
  18177. //====================== Start SoC ================================
  18178. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18179. {
  18180. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18181. 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))
  18182. {
  18183. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18184. {
  18185. tempIndex = ((gun_index==2) ? 1: 0);
  18186. }
  18187. else
  18188. {
  18189. tempIndex = gun_index;
  18190. }
  18191. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18192. {
  18193. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18194. {
  18195. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18196. {
  18197. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18198. }
  18199. }
  18200. }
  18201. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18202. {
  18203. for (int index = 0; index < CCS_QUANTITY; index++)
  18204. {
  18205. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18206. {
  18207. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18208. }
  18209. }
  18210. }
  18211. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18212. {
  18213. for (int index = 0; index < GB_QUANTITY; index++)
  18214. {
  18215. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18216. {
  18217. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18218. }
  18219. }
  18220. }
  18221. else if(gunType[gun_index] == GUN_TYPE_DO)
  18222. {
  18223. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18224. {
  18225. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18226. {
  18227. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18228. }
  18229. }
  18230. }
  18231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18237. } // END FOR DC CASE
  18238. }
  18239. //======================================== Message create ==============================================
  18240. json_object *StopTransaction = json_object_new_object();
  18241. json_object *transactionDatas = json_object_new_array();
  18242. json_object *sampledValues = json_object_new_array();
  18243. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18244. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18245. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18246. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18247. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18248. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18249. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18250. {
  18251. json_object *transactionData = json_object_new_object();
  18252. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18253. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18254. {
  18255. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18256. {
  18257. json_object *sampledValue = json_object_new_object();
  18258. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18259. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18260. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18261. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18262. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18263. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18264. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18265. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18266. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18267. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18268. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18269. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18270. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18271. json_object_array_add(sampledValues, sampledValue);
  18272. }
  18273. }
  18274. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18275. json_object_array_add(transactionDatas, transactionData);
  18276. }
  18277. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18278. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18279. ,MESSAGE_TYPE_CALL
  18280. ,guid
  18281. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18282. json_object_put(StopTransaction);
  18283. // Check File "TempStopTransaction" Exist
  18284. if((access(TempStopTransaction,F_OK))!=-1)
  18285. {
  18286. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18287. fclose(fopen(TempStopTransaction, "w"));
  18288. }
  18289. else
  18290. {
  18291. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18292. FILE *log = fopen(TempStopTransaction, "w+");
  18293. if(log == NULL)
  18294. {
  18295. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18296. return ;
  18297. }
  18298. else
  18299. {
  18300. fclose(log);
  18301. }
  18302. }
  18303. //Add TempStopTransaction | Update TempStopTransaction
  18304. // open file for writing
  18305. FILE *outfile;
  18306. outfile = fopen (TempStopTransaction, "a");
  18307. //DEBUG_INFO("data = %s\n", queuedata);
  18308. fputs(queuedata, outfile);
  18309. fputs("\n", outfile);
  18310. fclose (outfile);
  18311. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18312. OCPP_updatePeriodEnergy(gun_index);
  18313. }
  18314. void checkTempStopTransaction(int gun_index)
  18315. {
  18316. FILE *fptr1;
  18317. char ch;
  18318. char str[QUEUE_MESSAGE_LENGTH]={0};
  18319. char guid[37]={0};
  18320. char tempdata[65]={0};
  18321. char connectorStr[2]={0};
  18322. char TempStopTransaction[256];
  18323. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18324. fptr1 = fopen(TempStopTransaction, "r");
  18325. //TempStopTransaction格式: 槍號,StopTransaction封包
  18326. if (!fptr1)
  18327. {
  18328. //printf(" File not found or unable to open the input file!!\n");
  18329. return ;
  18330. }
  18331. ch=fgetc(fptr1);
  18332. //printf(" Now the content of the file %s is : \n",fname);
  18333. rewind(fptr1);
  18334. if(ch!=EOF)
  18335. {
  18336. // copy all contents to the temporary file except the specific line
  18337. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18338. {
  18339. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18340. if(str[0]=='\0')
  18341. {
  18342. break;
  18343. }
  18344. //TempStopTransaction格式: 槍號,StopTransaction封包
  18345. strncpy(connectorStr, str, 1);
  18346. if(atoi(connectorStr) != (gun_index+1))
  18347. {
  18348. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18349. fclose(fptr1);
  18350. return ;
  18351. }
  18352. //random_uuid(guid);
  18353. strncpy(guid, str+6, 36); //copy guid
  18354. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18355. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18356. {
  18357. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18358. }
  18359. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18360. OCPP_insert_transaction_msg(NO, str);
  18361. memset(str,0,ARRAY_SIZE(str));
  18362. }
  18363. }
  18364. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18365. fclose(fptr1);
  18366. remove(TempStopTransaction); // remove the original file
  18367. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18368. }
  18369. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18370. {
  18371. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18372. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18373. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18374. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18375. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18376. }
  18377. int GetWebSocketPingInterval(void)
  18378. {
  18379. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18380. }
  18381. int GetServerSign(void)
  18382. {
  18383. return server_sign;
  18384. }
  18385. uint8_t GetOcppSecurityProfile()
  18386. {
  18387. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18388. }
  18389. void GetOcppChargerBoxId(uint8_t *data)
  18390. {
  18391. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18392. }
  18393. void GetOcppSecurityPassword(uint8_t *data)
  18394. {
  18395. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18396. }
  18397. void SetOcppVersion(uint8_t *version)
  18398. {
  18399. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18400. DEBUG_INFO("ocpp version: %s\n", version);
  18401. if(strstr((char*)version, "ocpp1.6") != NULL)
  18402. {
  18403. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18404. }
  18405. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18406. {
  18407. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18408. system("pkill OcppBackend");
  18409. }
  18410. }
  18411. void SetServerSign(int value)
  18412. {
  18413. server_sign = value;
  18414. }
  18415. int GetBootNotificationInterval(void)
  18416. {
  18417. return BootNotificationInterval;
  18418. }
  18419. int GetInternetConn(void)
  18420. {
  18421. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18422. }
  18423. int GetBackendConnectionTimeout(void)
  18424. {
  18425. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18426. }
  18427. int isConnectorInitMode(int gun_index)
  18428. {
  18429. int tempIndex = 0;
  18430. int result = TRUE;
  18431. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18432. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18433. {
  18434. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18435. {
  18436. tempIndex = ((gun_index==2) ? 1: 0);
  18437. }
  18438. else
  18439. {
  18440. tempIndex = gun_index;
  18441. }
  18442. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18443. {
  18444. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18445. {
  18446. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18447. } //end of the same index
  18448. }//end of for CHAdeMO_QUANTITY
  18449. }
  18450. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18451. {
  18452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18453. {
  18454. tempIndex = ((gun_index==2) ? 1: 0);
  18455. }
  18456. else
  18457. {
  18458. tempIndex = gun_index;
  18459. }
  18460. for (int index = 0; index < CCS_QUANTITY; index++)
  18461. {
  18462. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18463. {
  18464. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18465. } //end of the same index
  18466. } // end of for CCS_QUANTITY
  18467. }
  18468. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18469. {
  18470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18471. {
  18472. tempIndex = ((gun_index==2) ? 1: 0);
  18473. }
  18474. else
  18475. {
  18476. tempIndex = gun_index;
  18477. }
  18478. for (int index = 0; index < GB_QUANTITY; index++)
  18479. {
  18480. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18481. {
  18482. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18483. } //end of the same index
  18484. } // end of for GB_QUANTITY
  18485. }
  18486. else if(gunType[gun_index] == GUN_TYPE_DO)
  18487. {
  18488. tempIndex = gun_index;
  18489. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18490. {
  18491. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18492. {
  18493. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18494. } //end of the same index
  18495. }
  18496. }
  18497. else
  18498. {
  18499. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18500. {
  18501. tempIndex = 2;
  18502. }
  18503. else
  18504. {
  18505. tempIndex = gun_index;
  18506. }
  18507. for (int index = 0; index < AC_QUANTITY; index++)
  18508. {
  18509. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18510. {
  18511. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18512. }//end of the same index
  18513. }//end of for AC_QUANTITY
  18514. }
  18515. return result;
  18516. }
  18517. void refreshProcDogTimer()
  18518. {
  18519. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18520. }
  18521. void InitialSystemValue(void)
  18522. {
  18523. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18524. locallistVersion=0;
  18525. BootNotificationInterval = 0;
  18526. authorizeRetryTimes = 0;
  18527. GunStatusInterval = 10;
  18528. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18529. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18530. //Hear Beat
  18531. HeartBeatWithNOResponse = 0;
  18532. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18533. FirstHeartBeat = 0;
  18534. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18535. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18536. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18537. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18538. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18539. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18540. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18541. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18542. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18543. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18544. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18545. //Status && ConnectorPlugIn Setting
  18546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18547. {
  18548. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18549. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18550. }
  18551. for (int index = 0; index < CCS_QUANTITY; index++)
  18552. {
  18553. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18554. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18555. }
  18556. for (int index = 0; index < GB_QUANTITY; index++)
  18557. {
  18558. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18559. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18560. }
  18561. for (int index = 0; index < AC_QUANTITY; index++)
  18562. {
  18563. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18564. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18565. }
  18566. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18567. {
  18568. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18569. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18570. }
  18571. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18572. {
  18573. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18574. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18575. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18576. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18577. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18578. }
  18579. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18580. refreshStartTimer(&clientTime.Heartbeat);
  18581. sleep(1);
  18582. }
  18583. void LWS_Send(char *str)
  18584. {
  18585. //=====================================================
  18586. // Check InternetConn 0: disconnected, 1: connected
  18587. //====================================================
  18588. if(GetOcppConnStatus() == 0)
  18589. {
  18590. DEBUG_INFO("offline now !!!\n");
  18591. return;
  18592. }
  18593. // Only disable isWebsocketSendable operation initiated by charger
  18594. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18595. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18596. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18597. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18598. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18599. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18600. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18601. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18602. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18603. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18604. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18605. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18606. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18607. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18608. {
  18609. isWebsocketSendable = 0;
  18610. }
  18611. pthread_mutex_lock(&lock_send);
  18612. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18613. sprintf((char *)SendBuffer, "%s", str);
  18614. SendBufLen = strlen(str);
  18615. pthread_mutex_unlock(&lock_send);
  18616. lws_callback_on_writable(wsi_client);
  18617. //lws_service(context, 0);
  18618. //sleep(1);
  18619. }
  18620. void LWS_SendNow(char *str)
  18621. {
  18622. //=====================================================
  18623. // Check InternetConn 0: disconnected, 1: connected
  18624. //====================================================
  18625. if(GetOcppConnStatus() == 0)
  18626. {
  18627. DEBUG_INFO("offline now !!!\n");
  18628. return;
  18629. }
  18630. // Only disable isWebsocketSendable operation initiated by charger
  18631. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18632. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18633. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18634. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18635. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18636. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18637. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18638. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18639. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18640. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18641. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18642. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18643. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18644. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18645. {
  18646. isWebsocketSendable = 0;
  18647. }
  18648. pthread_mutex_lock(&lock_send);
  18649. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18650. sprintf((char *)SendBuffer, "%s", str);
  18651. SendBufLen = strlen(str);
  18652. pthread_mutex_unlock(&lock_send);
  18653. lws_callback_on_writable(wsi_client);
  18654. lws_service(context, 0);
  18655. //sleep(1);
  18656. }