MessageHandler.c 937 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405
  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 or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  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((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. if(dataType == ReadingContext_Sample_Clock)
  6353. {
  6354. struct tm *tmTarget;
  6355. struct timeb tbTarget;
  6356. tbTarget.time = mktime(tm);
  6357. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6358. tmTarget = gmtime(&tbTarget.time);
  6359. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6360. }
  6361. else
  6362. {
  6363. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6364. }
  6365. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6366. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6367. //********************************(1)Current.Import L1************************************************/
  6368. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6369. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6370. (dataType == ReadingContext_Trigger))
  6371. {
  6372. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6373. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6374. {
  6375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6376. {
  6377. tempIndex = ((gun_index==2) ? 1: 0);
  6378. }
  6379. else
  6380. {
  6381. tempIndex = gun_index;
  6382. }
  6383. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6384. {
  6385. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6386. {
  6387. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6388. }
  6389. }
  6390. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6391. }
  6392. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6393. {
  6394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6395. {
  6396. tempIndex = ((gun_index==2) ? 1: 0);
  6397. }
  6398. else
  6399. {
  6400. tempIndex = gun_index;
  6401. }
  6402. for (int index = 0; index < CCS_QUANTITY; index++)
  6403. {
  6404. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6405. {
  6406. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6407. }
  6408. }
  6409. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6410. }
  6411. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6412. {
  6413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6414. {
  6415. tempIndex = ((gun_index==2) ? 1: 0);
  6416. }
  6417. else
  6418. {
  6419. tempIndex = gun_index;
  6420. }
  6421. for (int index = 0; index < GB_QUANTITY; index++)
  6422. {
  6423. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6424. {
  6425. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6426. }
  6427. }
  6428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6429. }
  6430. else if(gunType[gun_index] == GUN_TYPE_DO)
  6431. {
  6432. tempIndex = gun_index;
  6433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6434. {
  6435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6436. {
  6437. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6438. }
  6439. }
  6440. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6441. }
  6442. else
  6443. {
  6444. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6445. {
  6446. tempIndex = 2;
  6447. }
  6448. else
  6449. {
  6450. tempIndex = gun_index;
  6451. }
  6452. for (int index = 0; index < AC_QUANTITY; index++)
  6453. {
  6454. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6455. {
  6456. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6457. }
  6458. }
  6459. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6460. }
  6461. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6462. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6463. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6464. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6465. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6466. }
  6467. //********************************(2)Energy.Active.Import.Register ************************************************/
  6468. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6469. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6470. (dataType == ReadingContext_Trigger))
  6471. {
  6472. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6473. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6474. {
  6475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6476. {
  6477. tempIndex = ((gun_index==2) ? 1: 0);
  6478. }
  6479. else
  6480. {
  6481. tempIndex = gun_index;
  6482. }
  6483. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6484. {
  6485. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6486. {
  6487. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6488. }
  6489. }
  6490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6491. }
  6492. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6493. {
  6494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6495. {
  6496. tempIndex = ((gun_index==2) ? 1: 0);
  6497. }
  6498. else
  6499. {
  6500. tempIndex = gun_index;
  6501. }
  6502. for (int index = 0; index < CCS_QUANTITY; index++)
  6503. {
  6504. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6505. {
  6506. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6507. }
  6508. }
  6509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6510. }
  6511. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6512. {
  6513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6514. {
  6515. tempIndex = ((gun_index==2) ? 1: 0);
  6516. }
  6517. else
  6518. {
  6519. tempIndex = gun_index;
  6520. }
  6521. for (int index = 0; index < GB_QUANTITY; index++)
  6522. {
  6523. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6524. {
  6525. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6526. }
  6527. }
  6528. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6529. }
  6530. else if(gunType[gun_index] == GUN_TYPE_DO)
  6531. {
  6532. tempIndex = gun_index;
  6533. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6534. {
  6535. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6536. {
  6537. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6538. }
  6539. }
  6540. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6541. }
  6542. else
  6543. {
  6544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6545. {
  6546. tempIndex = 2;
  6547. }
  6548. else
  6549. {
  6550. tempIndex = gun_index;
  6551. }
  6552. for (int index = 0; index < AC_QUANTITY; index++)
  6553. {
  6554. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6555. {
  6556. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6557. }
  6558. }
  6559. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6560. }
  6561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6562. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6563. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6566. }
  6567. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6568. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6569. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6570. (dataType == ReadingContext_Trigger))
  6571. {
  6572. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6573. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6574. {
  6575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6576. {
  6577. tempIndex = ((gun_index==2) ? 1: 0);
  6578. }
  6579. else
  6580. {
  6581. tempIndex = gun_index;
  6582. }
  6583. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6584. {
  6585. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6586. {
  6587. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6588. }
  6589. } // END OF FOR CHAdeMO_QUANTITY
  6590. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6591. }
  6592. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6593. {
  6594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6595. {
  6596. tempIndex = ((gun_index==2) ? 1: 0);
  6597. }
  6598. else
  6599. {
  6600. tempIndex = gun_index;
  6601. }
  6602. for (int index = 0; index < CCS_QUANTITY; index++)
  6603. {
  6604. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6605. {
  6606. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6607. }
  6608. } // END OF CCS_QUANTITY
  6609. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6610. }
  6611. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6612. {
  6613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6614. {
  6615. tempIndex = ((gun_index==2) ? 1: 0);
  6616. }
  6617. else
  6618. {
  6619. tempIndex = gun_index;
  6620. }
  6621. for (int index = 0; index < GB_QUANTITY; index++)
  6622. {
  6623. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6624. {
  6625. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6626. }
  6627. } // END OF GB_QUANTITY
  6628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6629. }
  6630. else if(gunType[gun_index] == GUN_TYPE_DO)
  6631. {
  6632. tempIndex = gun_index;
  6633. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6634. {
  6635. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6636. {
  6637. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6638. }
  6639. }
  6640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6641. }
  6642. else
  6643. {
  6644. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6645. {
  6646. tempIndex = 2;
  6647. }
  6648. else
  6649. {
  6650. tempIndex = gun_index;
  6651. }
  6652. for (int index = 0; index < AC_QUANTITY; index++)
  6653. {
  6654. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6655. {
  6656. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6657. }
  6658. }
  6659. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6660. }
  6661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6662. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6666. }
  6667. //********************************(4)Power.Active.Import************************************************/
  6668. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6669. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6670. (dataType == ReadingContext_Trigger))
  6671. {
  6672. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6673. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6674. {
  6675. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6676. {
  6677. tempIndex = ((gun_index==2) ? 1: 0);
  6678. }
  6679. else
  6680. {
  6681. tempIndex = gun_index;
  6682. }
  6683. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6684. {
  6685. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6686. {
  6687. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6688. }
  6689. } // END OF FOR
  6690. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6691. }
  6692. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6693. {
  6694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6695. {
  6696. tempIndex = ((gun_index==2) ? 1: 0);
  6697. }
  6698. else
  6699. {
  6700. tempIndex = gun_index;
  6701. }
  6702. for (int index = 0; index < CCS_QUANTITY; index++)
  6703. {
  6704. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6705. {
  6706. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6707. }
  6708. }
  6709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6710. }
  6711. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6712. {
  6713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6714. {
  6715. tempIndex = ((gun_index==2) ? 1: 0);
  6716. }
  6717. else
  6718. {
  6719. tempIndex = gun_index;
  6720. }
  6721. for (int index = 0; index < GB_QUANTITY; index++)
  6722. {
  6723. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6724. {
  6725. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6726. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6727. }
  6728. }
  6729. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6730. }
  6731. else if(gunType[gun_index] == GUN_TYPE_DO)
  6732. {
  6733. tempIndex = gun_index;
  6734. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6735. {
  6736. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6737. {
  6738. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6739. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6740. }
  6741. }
  6742. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6743. }
  6744. else
  6745. {
  6746. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6747. {
  6748. tempIndex = 2;
  6749. }
  6750. else
  6751. {
  6752. tempIndex = gun_index;
  6753. }
  6754. for (int index = 0; index < AC_QUANTITY; index++)
  6755. {
  6756. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6757. {
  6758. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6759. }
  6760. }
  6761. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6762. }
  6763. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6764. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6765. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6766. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6767. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6768. }
  6769. //***********************************************(5)VOLTAGE L1******************************************************/
  6770. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6771. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6772. (dataType == ReadingContext_Trigger))
  6773. {
  6774. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6775. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6776. {
  6777. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6778. {
  6779. tempIndex = ((gun_index==2) ? 1: 0);
  6780. }
  6781. else
  6782. {
  6783. tempIndex = gun_index;
  6784. }
  6785. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6786. {
  6787. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6788. {
  6789. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6790. }
  6791. }
  6792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6793. }
  6794. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6795. {
  6796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6797. {
  6798. tempIndex = ((gun_index==2) ? 1: 0);
  6799. }
  6800. else
  6801. {
  6802. tempIndex = gun_index;
  6803. }
  6804. for (int index = 0; index < CCS_QUANTITY; index++)
  6805. {
  6806. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6807. {
  6808. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6809. }
  6810. }
  6811. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6812. }
  6813. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6814. {
  6815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6816. {
  6817. tempIndex = ((gun_index==2) ? 1: 0);
  6818. }
  6819. else
  6820. {
  6821. tempIndex = gun_index;
  6822. }
  6823. for (int index = 0; index < GB_QUANTITY; index++)
  6824. {
  6825. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6826. {
  6827. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6828. }
  6829. }
  6830. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6831. }
  6832. else if(gunType[gun_index] == GUN_TYPE_DO)
  6833. {
  6834. tempIndex = gun_index;
  6835. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6836. {
  6837. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6838. {
  6839. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6840. }
  6841. }
  6842. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6843. }
  6844. else
  6845. {
  6846. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6847. {
  6848. tempIndex = 2;
  6849. }
  6850. else
  6851. {
  6852. tempIndex = gun_index;
  6853. }
  6854. for (int index = 0; index < AC_QUANTITY; index++)
  6855. {
  6856. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6857. {
  6858. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6859. }
  6860. }
  6861. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6862. }
  6863. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6865. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6866. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6867. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6868. }
  6869. //***********************************************(6)SOC******************************************************/
  6870. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6871. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6872. (dataType == ReadingContext_Trigger))
  6873. {
  6874. 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))
  6875. {
  6876. //idx_sample=5;
  6877. //sampledValue = NULL;
  6878. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6879. {
  6880. tempIndex = ((gun_index==2) ? 1: 0);
  6881. }
  6882. else
  6883. {
  6884. tempIndex = gun_index;
  6885. }
  6886. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6887. {
  6888. //tempIndex = ((gun_index==2) ? 1: 0);
  6889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6890. {
  6891. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6892. {
  6893. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6894. }
  6895. }
  6896. }
  6897. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6898. {
  6899. //tempIndex = ((gun_index==2) ? 1: 0);
  6900. for (int index = 0; index < CCS_QUANTITY; index++)
  6901. {
  6902. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6903. {
  6904. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6905. }
  6906. }
  6907. }
  6908. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6909. {
  6910. //tempIndex = ((gun_index==2) ? 1: 0);
  6911. for (int index = 0; index < GB_QUANTITY; index++)
  6912. {
  6913. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6914. {
  6915. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6916. }
  6917. }
  6918. }
  6919. else if(gunType[gun_index] == GUN_TYPE_DO)
  6920. {
  6921. //tempIndex = ((gun_index==2) ? 1: 0);
  6922. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6923. {
  6924. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6925. {
  6926. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6927. }
  6928. }
  6929. }
  6930. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6936. }
  6937. }
  6938. //********************************(7)Current.Import L2************************************************/
  6939. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6940. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6941. (dataType == ReadingContext_Trigger))
  6942. {
  6943. // Only for AC 3 phase
  6944. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6945. {
  6946. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6947. {
  6948. tempIndex = 2;
  6949. }
  6950. else
  6951. {
  6952. tempIndex = gun_index;
  6953. }
  6954. for (int index = 0; index < AC_QUANTITY; index++)
  6955. {
  6956. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6957. {
  6958. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6959. }
  6960. }
  6961. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6962. }
  6963. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6964. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6965. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6966. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6967. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6968. }
  6969. //********************************(8)Current.Import L3************************************************/
  6970. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6971. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6972. (dataType == ReadingContext_Trigger))
  6973. {
  6974. // Only for AC 3 phase
  6975. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6976. {
  6977. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6978. {
  6979. tempIndex = 2;
  6980. }
  6981. else
  6982. {
  6983. tempIndex = gun_index;
  6984. }
  6985. for (int index = 0; index < AC_QUANTITY; index++)
  6986. {
  6987. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6988. {
  6989. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6990. }
  6991. }
  6992. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6993. }
  6994. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6995. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6996. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6997. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6998. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6999. }
  7000. //***********************************************(9)VOLTAGE L2******************************************************/
  7001. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7002. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7003. (dataType == ReadingContext_Trigger))
  7004. {
  7005. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7006. {
  7007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7008. {
  7009. tempIndex = 2;
  7010. }
  7011. else
  7012. {
  7013. tempIndex = gun_index;
  7014. }
  7015. for (int index = 0; index < AC_QUANTITY; index++)
  7016. {
  7017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7018. {
  7019. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7020. }
  7021. }
  7022. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7023. }
  7024. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7025. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7026. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7027. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7028. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7029. }
  7030. //***********************************************(10)VOLTAGE L3******************************************************/
  7031. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7032. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7033. (dataType == ReadingContext_Trigger))
  7034. {
  7035. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7036. {
  7037. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7038. {
  7039. tempIndex = 2;
  7040. }
  7041. else
  7042. {
  7043. tempIndex = gun_index;
  7044. }
  7045. for (int index = 0; index < AC_QUANTITY; index++)
  7046. {
  7047. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7048. {
  7049. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7050. }
  7051. }
  7052. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7053. }
  7054. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7055. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7056. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7057. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7058. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7059. }
  7060. //***********************************************(11)Current.Offered******************************************************/
  7061. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7062. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7063. (dataType == ReadingContext_Trigger))
  7064. {
  7065. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7066. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7067. {
  7068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7069. {
  7070. tempIndex = ((gun_index==2) ? 1: 0);
  7071. }
  7072. else
  7073. {
  7074. tempIndex = gun_index;
  7075. }
  7076. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7077. {
  7078. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7079. {
  7080. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7081. }
  7082. } // END OF FOR CHAdeMO_QUANTITY
  7083. }
  7084. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7085. {
  7086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7087. {
  7088. tempIndex = ((gun_index==2) ? 1: 0);
  7089. }
  7090. else
  7091. {
  7092. tempIndex = gun_index;
  7093. }
  7094. for (int index = 0; index < CCS_QUANTITY; index++)
  7095. {
  7096. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7097. {
  7098. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7099. }
  7100. } // END OF CCS_QUANTITY
  7101. }
  7102. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7103. {
  7104. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7105. {
  7106. tempIndex = ((gun_index==2) ? 1: 0);
  7107. }
  7108. else
  7109. {
  7110. tempIndex = gun_index;
  7111. }
  7112. for (int index = 0; index < GB_QUANTITY; index++)
  7113. {
  7114. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7115. {
  7116. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7117. }
  7118. } // END OF GB_QUANTITY
  7119. }
  7120. else if(gunType[gun_index] == GUN_TYPE_DO)
  7121. {
  7122. tempIndex = gun_index;
  7123. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7124. {
  7125. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7126. {
  7127. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7128. }
  7129. }
  7130. }
  7131. else
  7132. {
  7133. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7134. {
  7135. tempIndex = 2;
  7136. }
  7137. else
  7138. {
  7139. tempIndex = gun_index;
  7140. }
  7141. for (int index = 0; index < AC_QUANTITY; index++)
  7142. {
  7143. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7144. {
  7145. uint16_t currentOffer;
  7146. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7147. {
  7148. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7149. }
  7150. else
  7151. {
  7152. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7153. }
  7154. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7155. }
  7156. }
  7157. }
  7158. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7159. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7160. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7161. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7162. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7163. }
  7164. //***********************************************(12)Power.Offered******************************************************/
  7165. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7166. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7167. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7168. {
  7169. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7170. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7171. {
  7172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7173. {
  7174. tempIndex = ((gun_index==2) ? 1: 0);
  7175. }
  7176. else
  7177. {
  7178. tempIndex = gun_index;
  7179. }
  7180. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7181. {
  7182. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7183. {
  7184. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7185. }
  7186. } // END OF FOR CHAdeMO_QUANTITY
  7187. }
  7188. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7189. {
  7190. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7191. {
  7192. tempIndex = ((gun_index==2) ? 1: 0);
  7193. }
  7194. else
  7195. {
  7196. tempIndex = gun_index;
  7197. }
  7198. for (int index = 0; index < CCS_QUANTITY; index++)
  7199. {
  7200. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7201. {
  7202. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7203. }
  7204. } // END OF CCS_QUANTITY
  7205. }
  7206. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7207. {
  7208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7209. {
  7210. tempIndex = ((gun_index==2) ? 1: 0);
  7211. }
  7212. else
  7213. {
  7214. tempIndex = gun_index;
  7215. }
  7216. for (int index = 0; index < GB_QUANTITY; index++)
  7217. {
  7218. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7219. {
  7220. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7221. }
  7222. } // END OF GB_QUANTITY
  7223. }
  7224. else if(gunType[gun_index] == GUN_TYPE_DO)
  7225. {
  7226. tempIndex = gun_index;
  7227. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7228. {
  7229. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7230. {
  7231. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7232. }
  7233. }
  7234. }
  7235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7236. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7238. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7240. }
  7241. // Message create ====================================================================================================
  7242. if(TRUE)
  7243. {
  7244. json_object *MeterValueReq = json_object_new_object();
  7245. json_object *MeterValues = json_object_new_array();
  7246. json_object *sampledValues = json_object_new_array();
  7247. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7248. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7249. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7250. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7251. {
  7252. json_object *MeterValue = json_object_new_object();
  7253. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7254. {
  7255. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7256. {
  7257. json_object *sampledValue = json_object_new_object();
  7258. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7259. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7260. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7261. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7262. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7263. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7264. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7265. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7266. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7267. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7268. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7269. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7270. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7271. json_object_array_add(sampledValues, sampledValue);
  7272. }
  7273. }
  7274. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7275. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7276. json_object_array_add(MeterValues, MeterValue);
  7277. }
  7278. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7279. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7280. ,gun_index + 1
  7281. ,MESSAGE_TYPE_CALL
  7282. ,guid
  7283. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7284. json_object_put(MeterValueReq);
  7285. }
  7286. // Put request guid to hash map
  7287. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7288. 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*/)
  7289. {
  7290. result = PASS;
  7291. //DEBUG_INFO("MeterValues mapitem pass\n");
  7292. }
  7293. if((dataType != ReadingContext_Trigger) &&
  7294. (dataType != ReadingContext_Sample_Clock) &&
  7295. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7296. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7297. else
  7298. {
  7299. if(FirstHeartBeat)
  7300. LWS_Send(queuedata +2);
  7301. }
  7302. return result;
  7303. }
  7304. int sendLogStatusNotificationRequest(char *status)
  7305. {
  7306. mtrace();
  7307. int result = PASS;
  7308. char message[4096]={0};
  7309. char guid[37]={0};
  7310. char tempdata[128]={0};
  7311. json_object *LogStatusNotification = json_object_new_object();
  7312. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7313. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7314. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7315. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7316. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7317. random_uuid(guid);
  7318. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7319. json_object_put(LogStatusNotification);
  7320. LWS_Send(message);
  7321. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7322. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7323. {
  7324. result = PASS;
  7325. }
  7326. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7327. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7328. return result;
  7329. }
  7330. int sendSecurityEventNotificationRequest()
  7331. {
  7332. mtrace();
  7333. int result = PASS;
  7334. char message[4096]={0};
  7335. char guid[37]={0};
  7336. char tempdata[128]={0};
  7337. json_object *SecurityEventNotification = json_object_new_object();
  7338. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7339. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7340. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7341. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7342. random_uuid(guid);
  7343. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7344. json_object_put(SecurityEventNotification);
  7345. LWS_Send(message);
  7346. sprintf(tempdata, "SecurityEventNotification,0");
  7347. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7348. {
  7349. result = PASS;
  7350. }
  7351. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7352. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7353. return result;
  7354. }
  7355. int sendSignCertificateRequest()
  7356. {
  7357. mtrace();
  7358. int result = PASS;
  7359. char message[4096]={0};
  7360. char guid[37]={0};
  7361. char tempdata[128]={0};
  7362. json_object *SignCertificate = json_object_new_object();
  7363. DEBUG_INFO("sendSignCertificateRequest...\n");
  7364. // Read csr file content
  7365. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7366. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7367. char *line = NULL;
  7368. size_t len = 0;
  7369. while(getline(&line, &len, fp) != -1)
  7370. {
  7371. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7372. {
  7373. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7374. }
  7375. }
  7376. fclose(fp);
  7377. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7378. random_uuid(guid);
  7379. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7380. json_object_put(SignCertificate);
  7381. LWS_Send(message);
  7382. sprintf(tempdata, "SignCertificate,0");
  7383. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7384. {
  7385. result = PASS;
  7386. }
  7387. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7388. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7389. return result;
  7390. }
  7391. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7392. {
  7393. mtrace();
  7394. int result = PASS;
  7395. char message[110]={0};
  7396. char guid[37]={0};
  7397. char tempdata[65]={0};
  7398. json_object *FirmwareStatusNotification = json_object_new_object();
  7399. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7400. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7401. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7402. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7403. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7404. random_uuid(guid);
  7405. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7406. json_object_put(FirmwareStatusNotification);
  7407. LWS_Send(message);
  7408. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7409. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7410. {
  7411. result = PASS;
  7412. }
  7413. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7414. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7415. return result;
  7416. }
  7417. //==========================================
  7418. // send confirm routine
  7419. //==========================================
  7420. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7421. {
  7422. mtrace();
  7423. int result = FAIL;
  7424. char message[100]={0};
  7425. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7426. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7427. LWS_Send(message);
  7428. result = TRUE;
  7429. return result;
  7430. }
  7431. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7432. {
  7433. mtrace();
  7434. int result = FAIL;
  7435. char message[100]={0};
  7436. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7437. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7438. LWS_Send(message);
  7439. result = TRUE;
  7440. return result;
  7441. }
  7442. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7443. {
  7444. mtrace();
  7445. int result = FAIL;
  7446. char message[100]={0};
  7447. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7448. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7449. LWS_Send(message);
  7450. result = TRUE;
  7451. return result;
  7452. }
  7453. int sendClearCacheConfirmation(char *uuid,char *payload)
  7454. {
  7455. mtrace();
  7456. int result = FAIL;
  7457. char message[500]={0};
  7458. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7459. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7460. LWS_Send(message);
  7461. return result;
  7462. }
  7463. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7464. {
  7465. mtrace();
  7466. int result = FAIL;
  7467. char message[500]={0};
  7468. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7469. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7470. LWS_Send(message);
  7471. return result;
  7472. }
  7473. int sendDataTransferConfirmation(char *uuid,char *payload)
  7474. {
  7475. mtrace();
  7476. char statusStr[20]={0};
  7477. char dataStr[10]={0};
  7478. char sstr[20]={0};
  7479. int c = 0;
  7480. char *loc;
  7481. int result = FAIL;
  7482. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7483. /**********************status**************************/
  7484. loc = strstr(payload, "status");
  7485. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7486. c = 0;
  7487. while (loc[3+strlen("status")+c] != '\"')
  7488. {
  7489. sstr[c] = loc[3+strlen("status")+c];
  7490. c++;
  7491. }
  7492. sstr[c] = '\0';
  7493. strcpy(statusStr, sstr);
  7494. /**********************data**************************/
  7495. loc = strstr(payload, "data");
  7496. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7497. c = 0;
  7498. while (loc[3+strlen("data")+c] != '\"')
  7499. {
  7500. sstr[c] = loc[3+strlen("data")+c];
  7501. c++;
  7502. }
  7503. sstr[c] = '\0';
  7504. strcpy(dataStr, sstr);
  7505. return result;
  7506. }
  7507. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7508. {
  7509. mtrace();
  7510. int result = FAIL;
  7511. char message[1000]={0};
  7512. int CompositeScheduleIndex = 0;
  7513. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7514. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7515. if(nPeriod == 0)
  7516. {
  7517. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7518. {
  7519. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7520. ,MESSAGE_TYPE_CALLRESULT
  7521. ,uuid
  7522. ,payload
  7523. ,connectorIdInt);
  7524. }
  7525. else
  7526. {
  7527. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7528. ,MESSAGE_TYPE_CALLRESULT
  7529. ,uuid
  7530. ,payload
  7531. ,connectorIdInt
  7532. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7533. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7534. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7535. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7536. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7537. }
  7538. }
  7539. else
  7540. {
  7541. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7542. ,MESSAGE_TYPE_CALLRESULT
  7543. ,uuid
  7544. ,payload
  7545. ,connectorIdInt
  7546. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7547. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7548. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7549. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7550. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7551. {
  7552. if (idx_sample == 0)
  7553. {
  7554. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7555. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7556. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7557. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7558. }
  7559. else
  7560. {
  7561. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7562. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7563. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7564. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7565. }
  7566. }
  7567. sprintf(message + strlen(message), "]}}]");
  7568. }
  7569. LWS_Send(message);
  7570. result = TRUE;
  7571. return result;
  7572. }
  7573. int sendGetConfigurationConfirmation(char *uuid)
  7574. {
  7575. mtrace();
  7576. int result = FAIL;
  7577. int MaxKeySupported = 0;
  7578. int sentConfigurationNumber= 0;
  7579. int sentunConfigurationNumber= 0;
  7580. char message[1024*10]={0};
  7581. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7582. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7583. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7584. ,MESSAGE_TYPE_CALLRESULT
  7585. ,uuid );
  7586. //configuration key
  7587. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7588. {
  7589. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7590. {
  7591. if (sentConfigurationNumber == 0)
  7592. {
  7593. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7594. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7595. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7596. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7597. }
  7598. else
  7599. {
  7600. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7601. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7602. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7603. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7604. }
  7605. sentConfigurationNumber = sentConfigurationNumber + 1;
  7606. }
  7607. }
  7608. sprintf(message + strlen(message), "]");
  7609. if(UnknownKeynum != 0)
  7610. {
  7611. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7612. //unkown key
  7613. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7614. {
  7615. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7616. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7617. if(sentunConfigurationNumber == 0)
  7618. {
  7619. sprintf(message + strlen(message), "\"%s\""
  7620. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7621. }
  7622. else
  7623. {
  7624. sprintf(message + strlen(message), ",\"%s\""
  7625. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7626. }
  7627. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7628. }
  7629. sprintf(message + strlen(message), "]");
  7630. }
  7631. sprintf(message + strlen(message), "}]");
  7632. LWS_Send(message);
  7633. return result;
  7634. }
  7635. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7636. {
  7637. mtrace();
  7638. int result = FAIL;
  7639. char message[400]={0};
  7640. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7641. if(strcmp(payload,"")==0)
  7642. {
  7643. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7644. }
  7645. else
  7646. {
  7647. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7648. }
  7649. LWS_Send(message);
  7650. result = TRUE;
  7651. return result;
  7652. }
  7653. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7654. {
  7655. mtrace();
  7656. int result = FAIL;
  7657. char message[80]={0};
  7658. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7659. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7660. LWS_Send(message);
  7661. result = TRUE;
  7662. return result;
  7663. }
  7664. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7665. {
  7666. mtrace();
  7667. int result = FAIL;
  7668. char message[80]={0};
  7669. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7670. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7671. LWS_Send(message);
  7672. result = TRUE;
  7673. return result;
  7674. }
  7675. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7676. {
  7677. mtrace();
  7678. int result = FAIL;
  7679. char message[80]={0};
  7680. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\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 sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7687. {
  7688. mtrace();
  7689. int result = FAIL;
  7690. char message[80]={0};
  7691. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7692. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  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 sendResetConfirmation(char *uuid,char *payload)
  7699. {
  7700. mtrace();
  7701. int result = FAIL;
  7702. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7703. char message[80]={0};
  7704. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7705. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7706. LWS_Send(message);
  7707. result = TRUE;
  7708. return result;
  7709. }
  7710. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7711. {
  7712. mtrace();
  7713. int result = FAIL;
  7714. char message[500]={0};
  7715. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7716. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7717. LWS_Send(message);
  7718. result = TRUE;
  7719. return result;
  7720. }
  7721. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7722. {
  7723. mtrace();
  7724. int result = FAIL;
  7725. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7726. char message[80]={0};
  7727. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7728. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7729. LWS_Send(message);
  7730. result = TRUE;
  7731. return result;
  7732. }
  7733. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7734. {
  7735. mtrace();
  7736. int result = FAIL;
  7737. char message[80]={0};
  7738. DEBUG_INFO("sendTriggerMessageConfirmation...\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 sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7745. {
  7746. mtrace();
  7747. int result = FAIL;
  7748. char message[80]={0};
  7749. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7750. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7751. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7752. LWS_Send(message);
  7753. result = TRUE;
  7754. return result;
  7755. }
  7756. int sendUpdateFirmwareConfirmation(char *uuid)
  7757. {
  7758. mtrace();
  7759. int result = FAIL;
  7760. char message[60]={0};
  7761. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7762. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7763. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7764. LWS_Send(message);
  7765. result = TRUE;
  7766. return result;
  7767. }
  7768. int sendCertificateSignedConfirmation(char *uuid)
  7769. {
  7770. mtrace();
  7771. int result = PASS;
  7772. char message[4096]={0};
  7773. json_object *CertificateSigned = json_object_new_object();
  7774. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7775. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7776. sprintf(message,"[%d,\"%s\",%s]"
  7777. ,MESSAGE_TYPE_CALLRESULT
  7778. ,uuid
  7779. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7780. json_object_put(CertificateSigned);
  7781. LWS_Send(message);
  7782. return result;
  7783. }
  7784. int sendDeleteCertificateConfirmation(char *uuid)
  7785. {
  7786. mtrace();
  7787. int result = PASS;
  7788. char message[4096]={0};
  7789. json_object *DeleteCertificate = json_object_new_object();
  7790. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7791. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7792. sprintf(message,"[%d,\"%s\",%s]"
  7793. ,MESSAGE_TYPE_CALLRESULT
  7794. ,uuid
  7795. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7796. json_object_put(DeleteCertificate);
  7797. LWS_Send(message);
  7798. return result;
  7799. }
  7800. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7801. {
  7802. mtrace();
  7803. int result = PASS;
  7804. char message[4096]={0};
  7805. json_object *ExtendedTriggerMessage = json_object_new_object();
  7806. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7807. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7808. sprintf(message,"[%d,\"%s\",%s]"
  7809. ,MESSAGE_TYPE_CALLRESULT
  7810. ,uuid
  7811. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7812. json_object_put(ExtendedTriggerMessage);
  7813. LWS_Send(message);
  7814. return result;
  7815. }
  7816. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7817. {
  7818. mtrace();
  7819. int result = PASS;
  7820. char message[4096]={0};
  7821. json_object *GetInstalledCertificateIds = json_object_new_object();
  7822. json_object *certificateHashDataDatas = json_object_new_array();
  7823. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7824. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7825. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7826. {
  7827. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7828. {
  7829. json_object *certificateHashData = json_object_new_object();
  7830. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7831. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7832. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7833. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7834. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7835. }
  7836. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7837. }
  7838. else
  7839. {
  7840. json_object_put(certificateHashDataDatas);
  7841. }
  7842. sprintf(message,"[%d,\"%s\",%s]"
  7843. ,MESSAGE_TYPE_CALLRESULT
  7844. ,uuid
  7845. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7846. json_object_put(GetInstalledCertificateIds);
  7847. LWS_Send(message);
  7848. return result;
  7849. }
  7850. int sendGetLogConfirmation(char *uuid)
  7851. {
  7852. mtrace();
  7853. int result = PASS;
  7854. char message[4096]={0};
  7855. json_object *GetLog = json_object_new_object();
  7856. DEBUG_INFO("sendGetLogConfirmation...\n");
  7857. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7858. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7859. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7860. sprintf(message,"[%d,\"%s\",%s]"
  7861. ,MESSAGE_TYPE_CALLRESULT
  7862. ,uuid
  7863. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7864. json_object_put(GetLog);
  7865. LWS_Send(message);
  7866. return result;
  7867. }
  7868. int sendInstallCertificateConfirmation(char *uuid)
  7869. {
  7870. mtrace();
  7871. int result = PASS;
  7872. char message[4096]={0};
  7873. json_object *InstallCertificate = json_object_new_object();
  7874. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7875. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7876. sprintf(message,"[%d,\"%s\",%s]"
  7877. ,MESSAGE_TYPE_CALLRESULT
  7878. ,uuid
  7879. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7880. json_object_put(InstallCertificate);
  7881. LWS_Send(message);
  7882. return result;
  7883. }
  7884. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7885. {
  7886. mtrace();
  7887. int result = PASS;
  7888. char message[4096]={0};
  7889. json_object *SignedUpdateFirmware = json_object_new_object();
  7890. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7891. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7892. sprintf(message,"[%d,\"%s\",%s]"
  7893. ,MESSAGE_TYPE_CALLRESULT
  7894. ,uuid
  7895. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7896. json_object_put(SignedUpdateFirmware);
  7897. LWS_Send(message);
  7898. return result;
  7899. }
  7900. int sendUnknownConfirmation(char *uuid)
  7901. {
  7902. mtrace();
  7903. int result = PASS;
  7904. char message[256]={0};
  7905. DEBUG_INFO("sendUnknownConfirmation...\n");
  7906. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7907. LWS_Send(message);
  7908. return result;
  7909. }
  7910. //==========================================
  7911. // Handle server request routine Start
  7912. //==========================================
  7913. int handleCancelReservationRequest(char *uuid, char *payload)
  7914. {
  7915. mtrace();
  7916. int result = FAIL;
  7917. int gunNO = 0;
  7918. int reservationIdInt = -1;
  7919. char comfirmstr[20];
  7920. DEBUG_INFO("handleCancelReservationRequest...\n");
  7921. json_object *CancelReservation;
  7922. CancelReservation = json_tokener_parse(payload);
  7923. if(!is_error(CancelReservation))
  7924. {
  7925. // Required data
  7926. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7927. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7928. }
  7929. json_object_put(CancelReservation);
  7930. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7931. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7932. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7933. if(reservationIdInt != -1)
  7934. {
  7935. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7936. //check Transaction active
  7937. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7938. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7939. {
  7940. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7941. {
  7942. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7943. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7944. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7945. {
  7946. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7947. }
  7948. else
  7949. {
  7950. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7951. }
  7952. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7953. goto end;
  7954. }
  7955. }
  7956. for (int index = 0; index < CCS_QUANTITY; index++)
  7957. {
  7958. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7959. {
  7960. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7961. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7962. if(gunType[2] == GUN_TYPE_CCS)
  7963. {
  7964. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7965. }
  7966. else
  7967. {
  7968. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7969. }
  7970. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7971. goto end;
  7972. }
  7973. }
  7974. for (int index = 0; index < GB_QUANTITY; index++)
  7975. {
  7976. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7977. {
  7978. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7979. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7980. if(gunType[2] == GUN_TYPE_GBT)
  7981. {
  7982. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7983. }
  7984. else
  7985. {
  7986. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7987. }
  7988. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7989. goto end;
  7990. }
  7991. }
  7992. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7993. {
  7994. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7995. {
  7996. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7997. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7998. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7999. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8000. goto end;
  8001. }
  8002. }
  8003. for (int index = 0; index < AC_QUANTITY; index++)
  8004. {
  8005. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8006. {
  8007. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8008. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8009. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8010. {
  8011. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8012. }
  8013. else
  8014. {
  8015. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8016. }
  8017. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8018. goto end;
  8019. }
  8020. }
  8021. }
  8022. //The reservationId does NOT match the reservationId
  8023. sendCancelReservationConfirmation(uuid, comfirmstr);
  8024. end:
  8025. // Fill in ocpp packet uuid
  8026. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8027. return result;
  8028. }
  8029. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8030. {
  8031. mtrace();
  8032. int result = FAIL;
  8033. int gunIndex = -1;
  8034. char typeStr[16]={0};
  8035. char comfirmstr[20];
  8036. int specificId = FALSE;
  8037. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8038. json_object *ChangeAvailability;
  8039. ChangeAvailability = json_tokener_parse(payload);
  8040. if(!is_error(ChangeAvailability))
  8041. {
  8042. // Required data
  8043. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8044. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8045. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8046. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8047. }
  8048. json_object_put(ChangeAvailability);
  8049. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8050. {
  8051. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8052. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8053. }
  8054. else if(gunIndex == 0)
  8055. {
  8056. for(int i=0; i < gunTotalNumber; i++)
  8057. {
  8058. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8059. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8060. }
  8061. }
  8062. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8063. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8064. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8065. {
  8066. specificId = TRUE;
  8067. }
  8068. if(specificId == FALSE)
  8069. goto end;
  8070. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8071. {
  8072. //----------------------gunIndex is 0 ------------------------------------------------//
  8073. if(gunIndex == 0)
  8074. {
  8075. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8076. {
  8077. for(int i=0; i < gunTotalNumber; i++)
  8078. {
  8079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8080. {
  8081. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8082. {
  8083. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8084. {
  8085. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8086. goto end;
  8087. }
  8088. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8089. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8090. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8091. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8092. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8093. {
  8094. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8095. goto end;
  8096. }
  8097. }
  8098. }//END FOR CHAdeMO_QUANTITY
  8099. for (int index = 0; index < CCS_QUANTITY; index++)
  8100. {
  8101. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8102. {
  8103. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8104. {
  8105. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8106. goto end;
  8107. }
  8108. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8109. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8110. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8111. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8112. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8113. {
  8114. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8115. goto end;
  8116. }
  8117. }
  8118. }//END FOR CCS_QUANTITY
  8119. for (int index = 0; index < GB_QUANTITY; index++)
  8120. {
  8121. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8122. {
  8123. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8124. {
  8125. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8126. goto end;
  8127. }
  8128. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8129. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8130. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8131. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8132. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8133. {
  8134. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8135. goto end;
  8136. }
  8137. }
  8138. }// END FOR GB_QUANTITY
  8139. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8140. {
  8141. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8142. {
  8143. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8144. {
  8145. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8146. goto end;
  8147. }
  8148. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8149. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8150. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8151. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8152. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8153. {
  8154. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8155. goto end;
  8156. }
  8157. }
  8158. }// END FOR GENERAL_GUN_QUANTITY
  8159. for (int index = 0; index < AC_QUANTITY; index++)
  8160. {
  8161. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8162. {
  8163. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8164. {
  8165. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8166. goto end;
  8167. }
  8168. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8169. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8170. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8171. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8172. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8173. {
  8174. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8175. goto end;
  8176. }
  8177. }
  8178. }//END FOR AC_QUANTITY
  8179. }// END FOR gunTotalNumber
  8180. }
  8181. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8182. {
  8183. for(int i=0; i < gunTotalNumber; i++)
  8184. {
  8185. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8186. {
  8187. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8188. goto end;
  8189. }
  8190. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8191. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8192. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8193. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8194. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8195. {
  8196. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8197. goto end;
  8198. }
  8199. }
  8200. }
  8201. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8202. goto end;
  8203. }
  8204. //----------------------gunIndex is not 0 ------------------------------------------------//
  8205. //check Transaction active
  8206. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8207. {
  8208. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8209. {
  8210. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8211. {
  8212. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8213. goto end;
  8214. }
  8215. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8216. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8217. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8218. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8219. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8220. {
  8221. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8222. goto end;
  8223. }
  8224. else
  8225. {
  8226. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8227. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8228. goto end;
  8229. }
  8230. }
  8231. }//END FOR CHAdeMO_QUANTITY
  8232. for (int index = 0; index < CCS_QUANTITY; index++)
  8233. {
  8234. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8235. {
  8236. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8237. {
  8238. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8239. goto end;
  8240. }
  8241. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8242. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8243. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8244. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8245. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8246. {
  8247. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8248. goto end;
  8249. }
  8250. else
  8251. {
  8252. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8253. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8254. goto end;
  8255. }
  8256. }
  8257. }//END FOR CCS_QUANTITY
  8258. for (int index = 0; index < GB_QUANTITY; index++)
  8259. {
  8260. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8261. {
  8262. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8263. {
  8264. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8265. goto end;
  8266. }
  8267. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8268. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8269. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8270. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8271. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8272. {
  8273. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8274. goto end;
  8275. }
  8276. else
  8277. {
  8278. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8279. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8280. goto end;
  8281. }
  8282. }
  8283. }// END FOR GB_QUANTITY
  8284. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8285. {
  8286. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8287. {
  8288. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8289. {
  8290. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8291. goto end;
  8292. }
  8293. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8294. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8295. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8296. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8297. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8298. {
  8299. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8300. goto end;
  8301. }
  8302. else
  8303. {
  8304. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8305. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8306. goto end;
  8307. }
  8308. }
  8309. }// END FOR GENERAL_GUN_QUANTITY
  8310. for (int index = 0; index < AC_QUANTITY; index++)
  8311. {
  8312. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8313. {
  8314. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8315. {
  8316. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8317. goto end;
  8318. }
  8319. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8320. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8321. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8322. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8323. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8324. {
  8325. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8326. goto end;
  8327. }
  8328. else
  8329. {
  8330. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8331. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8332. goto end;
  8333. }
  8334. }
  8335. }//END FOR AC_QUANTITY
  8336. }//END FOR AvailabilityTypeStr[Inoperative]
  8337. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8338. {
  8339. //----------------------gunIndex is 0 ------------------------------------------------//
  8340. if(gunIndex == 0)
  8341. {
  8342. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8343. {
  8344. for(int i=0; i < gunTotalNumber; i++)
  8345. {
  8346. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8347. {
  8348. 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
  8349. {
  8350. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8351. goto end;
  8352. }
  8353. }//END FOR CHAdeMO_QUANTITY
  8354. for (int index = 0; index < CCS_QUANTITY; index++)
  8355. {
  8356. 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
  8357. {
  8358. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8359. goto end;
  8360. }
  8361. }//END FOR CCS_QUANTITY
  8362. for (int index = 0; index < GB_QUANTITY; index++)
  8363. {
  8364. 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
  8365. {
  8366. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8367. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8368. goto end;
  8369. }
  8370. }// END FOR GB_QUANTITY
  8371. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8372. {
  8373. 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
  8374. {
  8375. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8376. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8377. goto end;
  8378. }
  8379. }// END FOR GENERAL_GUN_QUANTITY
  8380. for (int index = 0; index < AC_QUANTITY; index++)
  8381. {
  8382. 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
  8383. {
  8384. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8385. goto end;
  8386. }
  8387. }//END FOR CHAdeMO_QUANTITY
  8388. }// END FOR gunTotalNumber
  8389. }
  8390. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8391. {
  8392. for(int i=0; i < gunTotalNumber; i++)
  8393. {
  8394. for (int index = 0; index < AC_QUANTITY; index++)
  8395. {
  8396. 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
  8397. {
  8398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8399. goto end;
  8400. }
  8401. }//END FOR CHAdeMO_QUANTITY
  8402. } // END FOR gunTotalNumber
  8403. }
  8404. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8405. goto end;
  8406. }
  8407. //----------------------gunIndex is not 0 ------------------------------------------------//
  8408. //check Transaction active
  8409. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8410. {
  8411. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8412. {
  8413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8414. goto end;
  8415. }
  8416. }//END FOR CHAdeMO_QUANTITY
  8417. for (int index = 0; index < CCS_QUANTITY; index++)
  8418. {
  8419. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8420. {
  8421. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8422. goto end;
  8423. }
  8424. }//END FOR CCS_QUANTITY
  8425. for (int index = 0; index < GB_QUANTITY; index++)
  8426. {
  8427. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8428. {
  8429. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8430. goto end;
  8431. }
  8432. }// END FOR GB_QUANTITY
  8433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8434. {
  8435. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8436. {
  8437. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8438. goto end;
  8439. }
  8440. }// END FOR GENERAL_GUN_QUANTITY
  8441. for (int index = 0; index < AC_QUANTITY; index++)
  8442. {
  8443. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8444. {
  8445. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8446. goto end;
  8447. }
  8448. }//END FOR AC_QUANTITY
  8449. }//END FOR AvailabilityTypeStr[Operative]
  8450. end:
  8451. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8452. {
  8453. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8454. }
  8455. else
  8456. {
  8457. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8458. }
  8459. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8460. {
  8461. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8462. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8463. }
  8464. else if(gunIndex == 0)
  8465. {
  8466. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8467. {
  8468. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8469. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8470. }
  8471. }
  8472. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8473. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8474. return result;
  8475. }
  8476. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8477. {
  8478. mtrace();
  8479. int valueInvalid = NO;
  8480. int result = FAIL;
  8481. char keystr[40]={0};
  8482. char valuestr[501]={0}; //value should be limited in 500 bytes
  8483. char comfirmstr[20]={0};
  8484. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8485. json_object *ChangeConfiguration;
  8486. ChangeConfiguration = json_tokener_parse(payload);
  8487. if(!is_error(ChangeConfiguration))
  8488. {
  8489. // Required data
  8490. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8491. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8492. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8493. {
  8494. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8495. }
  8496. else
  8497. {
  8498. valueInvalid = YES;
  8499. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8500. }
  8501. }
  8502. json_object_put(ChangeConfiguration);
  8503. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8504. {
  8505. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8506. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8507. }
  8508. else
  8509. {
  8510. int status = setKeyValue(keystr, valuestr);
  8511. switch(status)
  8512. {
  8513. case ConfigurationStatus_Accepted:
  8514. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8515. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8516. StoreConfigurationTable();
  8517. break;
  8518. case RebootRequired:
  8519. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8520. StoreConfigurationTable();
  8521. break;
  8522. case NotSupported:
  8523. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8524. break;
  8525. case ConfigurationStatus_Rejected:
  8526. default:
  8527. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8528. break;
  8529. }
  8530. }
  8531. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8532. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8533. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8534. {
  8535. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8536. SetOcppConnStatus(FALSE);
  8537. }
  8538. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8539. {
  8540. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8541. }
  8542. return result;
  8543. }
  8544. int handleClearCacheRequest(char *uuid, char *payload)
  8545. {
  8546. mtrace();
  8547. int result = FAIL;
  8548. char comfirmstr[20];
  8549. char rmFileCmd[100]={0};
  8550. struct stat stats;
  8551. DEBUG_INFO("handleClearCacheRequest...\n");
  8552. stat("/Storage/OCPP", &stats);
  8553. // Check for directory existence
  8554. if (S_ISDIR(stats.st_mode) == 1)
  8555. {}
  8556. else
  8557. {
  8558. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8559. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8560. system(rmFileCmd);
  8561. }
  8562. if(OCPP_cleanLocalCache())
  8563. {
  8564. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8565. }
  8566. else
  8567. {
  8568. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8569. }
  8570. sendClearCacheConfirmation(uuid, comfirmstr);
  8571. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8572. return result;
  8573. }
  8574. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8575. {
  8576. mtrace();
  8577. int result = FAIL;
  8578. int resultRename;
  8579. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8580. char chargingProfilePurposeStr[26]={0};
  8581. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8582. char tempchargingProfilePurposeStr[26]={0};
  8583. char str[100]={0};
  8584. char fname[200]={0};
  8585. char comfirmstr[20]={0};
  8586. char word[1600]={0};
  8587. int clearflag = FALSE;
  8588. int chargingProfileIdIsNULL = FALSE;
  8589. int connectorIsNULL = FALSE;
  8590. int chargingProfilePurposeIsNULL = FALSE;
  8591. int stackLevelIsNULL = FALSE;
  8592. //int GotoEnd = FALSE;
  8593. FILE *fptr1, *fptr2;
  8594. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8595. int n_chargingProfile=0;
  8596. int isEmptyFile = FALSE;
  8597. char sLineWord[1600]={0};
  8598. char chargingProfiles[10][100]={0};
  8599. int ChargeProfileCount = 0;
  8600. int ch;
  8601. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8602. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8603. json_object *ClearChargingProfile;
  8604. ClearChargingProfile = json_tokener_parse(payload);
  8605. if(!is_error(ClearChargingProfile))
  8606. {
  8607. // Optional data
  8608. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8609. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8610. else
  8611. chargingProfileIdIsNULL = TRUE;
  8612. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8613. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8614. else
  8615. connectorIsNULL = TRUE;
  8616. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8617. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8618. else
  8619. chargingProfilePurposeIsNULL = TRUE;
  8620. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8621. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8622. else
  8623. stackLevelIsNULL = TRUE;
  8624. }
  8625. json_object_put(ClearChargingProfile);
  8626. if(connectorIsNULL == FALSE)
  8627. {
  8628. switch(connectorIdInt)
  8629. {
  8630. case 0:
  8631. if(chargingProfilePurposeIsNULL == TRUE)
  8632. {
  8633. int l = 0;
  8634. strcpy(fname, ChargePointMaxProfile_JSON);
  8635. if((access(fname,F_OK))!=-1)
  8636. {
  8637. strcpy(chargingProfiles[l], fname);
  8638. l = l + 1;
  8639. }
  8640. strcpy(fname, TxDefaultProfile_0_JSON);
  8641. if((access(fname,F_OK))!=-1)
  8642. {
  8643. strcpy(chargingProfiles[l], fname);
  8644. l = l + 1;
  8645. }
  8646. ChargeProfileCount = l;
  8647. }
  8648. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8649. {
  8650. strcpy(fname, ChargePointMaxProfile_JSON);
  8651. if((access(fname,F_OK))!=-1)
  8652. {
  8653. strcpy(chargingProfiles[0], fname);
  8654. ChargeProfileCount = 1;
  8655. }
  8656. }
  8657. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8658. {
  8659. strcpy(fname, TxDefaultProfile_0_JSON);
  8660. if((access(fname,F_OK))!=-1)
  8661. {
  8662. strcpy(chargingProfiles[0], fname);
  8663. ChargeProfileCount = 1;
  8664. }
  8665. }
  8666. break;
  8667. default:
  8668. if(chargingProfilePurposeIsNULL == TRUE)
  8669. {
  8670. int m = 0;
  8671. memset(fname, 0, ARRAY_SIZE(fname));
  8672. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8673. if((access(fname,F_OK))!=-1)
  8674. {
  8675. strcpy(chargingProfiles[m], fname);
  8676. m = m + 1;
  8677. }
  8678. memset(fname, 0, ARRAY_SIZE(fname));
  8679. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8680. if((access(fname,F_OK))!=-1)
  8681. {
  8682. strcpy(chargingProfiles[m], fname);
  8683. m = m + 1;
  8684. }
  8685. ChargeProfileCount = m;
  8686. }
  8687. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8688. {
  8689. //strcpy(fname, TxDefaultProfile_1_JSON);
  8690. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8691. if((access(fname,F_OK))!=-1)
  8692. {
  8693. strcpy(chargingProfiles[0], fname);
  8694. ChargeProfileCount = 1;
  8695. }
  8696. }
  8697. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8698. {
  8699. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8700. if((access(fname,F_OK))!=-1)
  8701. {
  8702. strcpy(chargingProfiles[0], fname);
  8703. ChargeProfileCount = 1;
  8704. }
  8705. //strcpy(fname, TxProfile_1_JSON);
  8706. }
  8707. //strcpy(fname, ChargePointMaxProfile_JSON );
  8708. break;
  8709. }
  8710. }
  8711. else // Check all Charging Profiles
  8712. {
  8713. int i = 0;
  8714. char fnametemp[200]={0};
  8715. ChargeProfileCount = 0;
  8716. //Check ChargePointMaxProfile.json exit
  8717. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8718. {
  8719. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8720. i = i + 1;
  8721. }
  8722. //Check TxDefaultProfile_0.json exit
  8723. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8724. {
  8725. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8726. i = i + 1;
  8727. }
  8728. //Check TxDefaultProfile_%d.json
  8729. for(int j=1; j <= gunTotalNumber; j++)
  8730. {
  8731. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8732. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8733. if((access(fnametemp,F_OK))!=-1)
  8734. {
  8735. strcpy(chargingProfiles[i], fnametemp);
  8736. i = i + 1;
  8737. }
  8738. }
  8739. //Check TxProfile_%d.json
  8740. for(int j=1; j <= gunTotalNumber; j++)
  8741. {
  8742. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8743. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8744. if((access(fnametemp,F_OK))!=-1)
  8745. {
  8746. strcpy(chargingProfiles[i], fnametemp);
  8747. i = i + 1;
  8748. }
  8749. }
  8750. ChargeProfileCount = i;
  8751. }// End connectorIsNULL is TRUE
  8752. if(ChargeProfileCount == 0)
  8753. {
  8754. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8755. goto end;
  8756. }
  8757. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8758. {
  8759. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8760. goto end;
  8761. }
  8762. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8763. {
  8764. memset(str, 0, ARRAY_SIZE(str));
  8765. // clear temp file
  8766. sprintf(str,"rm -f %s",temp);
  8767. system(str);
  8768. for(int k=0; k < ChargeProfileCount; k++)
  8769. {
  8770. memset(str, 0, ARRAY_SIZE(str));
  8771. //clear file in C
  8772. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8773. system(str);
  8774. }
  8775. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8776. goto end;
  8777. }
  8778. else if(connectorIsNULL == TRUE)
  8779. {
  8780. for(int k=0; k < ChargeProfileCount; k++)
  8781. {
  8782. fptr1 = fopen(chargingProfiles[k], "r");
  8783. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8784. //Check Charging Profile Count
  8785. while(fscanf(fptr1, "%s", word) != EOF)
  8786. {
  8787. //DEBUG_INFO("word=%s\n",word);
  8788. if(strstr(word, "chargingProfileId")!= NULL)
  8789. {
  8790. //DEBUG_INFO("test chargingProfileId \n");
  8791. n_chargingProfile = n_chargingProfile + 1;
  8792. //DEBUG_INFO("chargingProfileId Found\n");
  8793. }
  8794. }
  8795. rewind(fptr1);
  8796. //search Charging Profile Element
  8797. //int i= 0;
  8798. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8799. {
  8800. json_object *tmpProfilee;
  8801. tmpProfilee = json_tokener_parse(sLineWord);
  8802. if(!is_error(tmpProfilee))
  8803. {
  8804. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8805. {
  8806. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8807. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8808. }
  8809. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8810. {
  8811. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8812. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8813. }
  8814. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8815. {
  8816. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8817. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8818. }
  8819. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8820. {
  8821. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8822. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8823. }
  8824. }
  8825. json_object_put(tmpProfilee);
  8826. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8827. {
  8828. //------- not write to fptr2-------//
  8829. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8830. //clearflag = TRUE;
  8831. }
  8832. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8833. {
  8834. //------- not write to fptr2-------//
  8835. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8836. }
  8837. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8838. {
  8839. //------- not write to fptr2-------//
  8840. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8841. }
  8842. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8843. {
  8844. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8845. }
  8846. else
  8847. {
  8848. fprintf(fptr2, sLineWord);//writing data into file
  8849. }
  8850. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8851. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8852. if(clearflag == TRUE)
  8853. {
  8854. fclose(fptr1);
  8855. fclose(fptr2);
  8856. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8857. system(str);
  8858. // clear temp file
  8859. sprintf(str,"rm -f %s",temp);
  8860. system(str);
  8861. }
  8862. else
  8863. {
  8864. fclose(fptr1);
  8865. fclose(fptr2);
  8866. memset(str, 0, ARRAY_SIZE(str));
  8867. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8868. system(str);
  8869. resultRename = rename(temp, chargingProfiles[k]);
  8870. if(resultRename == 0)
  8871. {
  8872. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8873. }
  8874. else
  8875. {
  8876. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8877. }
  8878. if(comfirmstr[0]== 0)
  8879. {
  8880. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8881. }
  8882. //Check chargingProfile is empty file
  8883. /*------ Read the file ----------------*/
  8884. fptr1=fopen(chargingProfiles[k],"r");
  8885. ch=fgetc(fptr1);
  8886. rewind(fptr1);
  8887. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8888. if(ch!=EOF)
  8889. {
  8890. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8891. {
  8892. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8893. if(sLineWord[0]=='\0')
  8894. {
  8895. isEmptyFile = TRUE;
  8896. break;
  8897. }
  8898. else
  8899. {
  8900. isEmptyFile = FALSE;
  8901. break;
  8902. }
  8903. }
  8904. }
  8905. else
  8906. isEmptyFile = TRUE;
  8907. fclose(fptr1);
  8908. if(isEmptyFile == TRUE)
  8909. {
  8910. memset(str, 0, ARRAY_SIZE(str));
  8911. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8912. system(str);
  8913. }
  8914. }
  8915. }// End of while(int k=0; k < ChargePointCount; k++)
  8916. }
  8917. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8918. {
  8919. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8920. for(int k=0; k < ChargeProfileCount; k++)
  8921. {
  8922. fptr1 = fopen(chargingProfiles[k], "r");
  8923. fptr2 = fopen(temp, "w+");
  8924. //Check Charging Profile Count
  8925. while(fscanf(fptr1, "%s", word) != EOF)
  8926. {
  8927. //DEBUG_INFO("word=%s\n",word);
  8928. if(strstr(word, "chargingProfileId")!= NULL)
  8929. {
  8930. n_chargingProfile = n_chargingProfile + 1;
  8931. }
  8932. }
  8933. rewind(fptr1);
  8934. //search Charging Profile Element
  8935. //int i= 0;
  8936. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8937. {
  8938. json_object *tmpProfilee;
  8939. tmpProfilee = json_tokener_parse(sLineWord);
  8940. if(!is_error(tmpProfilee))
  8941. {
  8942. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8943. {
  8944. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8945. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8946. }
  8947. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8948. {
  8949. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8950. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8951. }
  8952. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8953. {
  8954. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8955. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8956. }
  8957. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8958. {
  8959. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8960. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8961. }
  8962. }
  8963. json_object_put(tmpProfilee);
  8964. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8965. {
  8966. //------- not write to fptr2-------//
  8967. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8968. //clearflag = TRUE;
  8969. }
  8970. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8971. {
  8972. //------- not write to fptr2-------//
  8973. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8974. }
  8975. else if(stackLevelIsNULL == TRUE)
  8976. {
  8977. //Clear Whole File
  8978. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8979. clearflag = TRUE;
  8980. break;
  8981. }
  8982. else
  8983. {
  8984. fprintf(fptr2, sLineWord);//writing data into file
  8985. }
  8986. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8987. }
  8988. if(clearflag == TRUE)
  8989. {
  8990. fclose(fptr1);
  8991. fclose(fptr2);
  8992. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8993. system(str);
  8994. // clear temp file
  8995. sprintf(str,"rm -f %s",temp);
  8996. system(str);
  8997. }
  8998. else
  8999. {
  9000. fclose(fptr1);
  9001. fclose(fptr2);
  9002. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9003. system(str);
  9004. resultRename = rename(temp, chargingProfiles[k]);
  9005. if(resultRename == 0)
  9006. {
  9007. DEBUG_INFO("File ChargingProfile renamed successfully");
  9008. }
  9009. else
  9010. {
  9011. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9012. }
  9013. if(comfirmstr[0]== 0)
  9014. {
  9015. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9016. }
  9017. //Check chargingProfile is empty file
  9018. /*------ Read the file ----------------*/
  9019. fptr1=fopen(chargingProfiles[k],"r");
  9020. ch=fgetc(fptr1);
  9021. rewind(fptr1);
  9022. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9023. if(ch!=EOF)
  9024. {
  9025. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9026. {
  9027. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9028. if(sLineWord[0]=='\0')
  9029. {
  9030. isEmptyFile = TRUE;
  9031. break;
  9032. }
  9033. else
  9034. {
  9035. isEmptyFile = FALSE;
  9036. break;
  9037. }
  9038. }
  9039. }
  9040. else
  9041. isEmptyFile = TRUE;
  9042. fclose(fptr1);
  9043. if(isEmptyFile == TRUE)
  9044. {
  9045. memset(str, 0, ARRAY_SIZE(str));
  9046. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9047. system(str);
  9048. }
  9049. /*------- End of reading ---------------*/
  9050. }
  9051. } // while(int k=0; k < ChargeProfileCount; k++)
  9052. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9053. end:
  9054. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9055. {
  9056. if(connectorIdInt == 0)
  9057. {
  9058. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9059. {
  9060. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9061. }
  9062. }
  9063. else
  9064. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9065. }
  9066. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9067. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9068. return result;
  9069. }
  9070. void createFirmwareVersionByDataTransfer(void)
  9071. {
  9072. json_object *FirmwareDataTransfer = json_object_new_object();
  9073. // AC & DC model
  9074. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9075. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9076. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9077. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9078. // DC model
  9079. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9080. {
  9081. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9082. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9083. (gunType[3] != GUN_TYPE_UNKNOWN))
  9084. {
  9085. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9086. }
  9087. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9088. {
  9089. // DS DM DW
  9090. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9091. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9092. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9093. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9094. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9095. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9096. }
  9097. else
  9098. {
  9099. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9100. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9101. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9102. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9103. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9104. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9105. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9106. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9107. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9108. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9109. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9110. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9111. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9112. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9113. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9114. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9115. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9116. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9117. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9118. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9119. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9120. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9121. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9122. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9123. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9124. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9125. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9126. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9127. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9128. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9129. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9130. }
  9131. }
  9132. // 4G model
  9133. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9134. {
  9135. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9136. }
  9137. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9138. json_object_put(FirmwareDataTransfer);
  9139. }
  9140. int handleDataTransferRequest(char *uuid, char *payload)
  9141. {
  9142. mtrace();
  9143. json_object *response = json_object_new_object();
  9144. int result = FAIL;
  9145. char tempvendorId[255]={0};
  9146. char tempmessageId[50]={0};
  9147. char tempdata[512]={0};
  9148. char message[2048]={0};
  9149. DEBUG_INFO("handleDataTransferRequest...\n");
  9150. if((uuid != NULL) && (payload != NULL))
  9151. {
  9152. json_object *DataTransfer;
  9153. DataTransfer = json_tokener_parse(payload);
  9154. if(!is_error(DataTransfer))
  9155. {
  9156. // Required data
  9157. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9158. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9159. // Optional data
  9160. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9161. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9162. if(json_object_object_get(DataTransfer, "data") != NULL)
  9163. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9164. result = PASS;
  9165. }
  9166. json_object_put(DataTransfer);
  9167. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9168. {
  9169. // Send all moudle firmware version on EVSE
  9170. createFirmwareVersionByDataTransfer();
  9171. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9172. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9173. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9174. json_object_put(response);
  9175. }
  9176. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9177. {
  9178. system("/usr/bin/run_tmate_restart.sh &");
  9179. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9180. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9181. json_object_put(response);
  9182. }
  9183. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9184. {
  9185. json_object *data;
  9186. data = json_tokener_parse(tempdata);
  9187. if(!is_error(data))
  9188. {
  9189. 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))
  9190. {
  9191. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9192. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9193. if(json_object_object_get(data, "SOC") != NULL)
  9194. {
  9195. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9196. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9197. }
  9198. if(json_object_object_get(data, "Energy") != NULL)
  9199. {
  9200. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9201. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9202. }
  9203. if(json_object_object_get(data, "Duration") != NULL)
  9204. {
  9205. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9206. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9207. }
  9208. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9209. }
  9210. else
  9211. {
  9212. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9213. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9214. }
  9215. }
  9216. else
  9217. {
  9218. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9219. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9220. }
  9221. json_object_put(data);
  9222. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9223. json_object_put(response);
  9224. }
  9225. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9226. {
  9227. json_object *data;
  9228. data = json_tokener_parse(tempdata);
  9229. if(!is_error(data))
  9230. {
  9231. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9232. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9233. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9234. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9235. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9236. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9237. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9238. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9239. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9240. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9241. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9242. }
  9243. else
  9244. {
  9245. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9246. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9247. }
  9248. json_object_put(data);
  9249. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9250. json_object_put(response);
  9251. }
  9252. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9253. {
  9254. json_object *data;
  9255. data = json_tokener_parse(tempdata);
  9256. if(!is_error(data))
  9257. {
  9258. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9259. if(json_object_object_get(data, "idToken") != NULL)
  9260. {
  9261. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9262. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9263. }
  9264. if(json_object_object_get(data, "price") != NULL)
  9265. {
  9266. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9267. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9268. }
  9269. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9270. }
  9271. else
  9272. {
  9273. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9274. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9275. }
  9276. json_object_put(data);
  9277. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9278. json_object_put(response);
  9279. }
  9280. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9281. {
  9282. json_object *data;
  9283. data = json_tokener_parse(tempdata);
  9284. if(!is_error(data))
  9285. {
  9286. if(json_object_object_get(data, "txId") != NULL)
  9287. {
  9288. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9289. for(int idx = 0;idx<gunTotalNumber;idx++)
  9290. {
  9291. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9292. {
  9293. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9294. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9295. if(json_object_object_get(data, "description") != NULL)
  9296. {
  9297. // California pricing V1.0
  9298. DEBUG_INFO("California pricing V1.0\n");
  9299. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9300. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9301. }
  9302. else
  9303. {
  9304. // California pricing V1.1
  9305. DEBUG_INFO("California pricing V1.1\n");
  9306. if(json_object_object_get(data, "timestamp") != NULL)
  9307. {
  9308. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9309. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9310. }
  9311. if(json_object_object_get(data, "meterValue") != NULL)
  9312. {
  9313. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9314. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9315. }
  9316. if(json_object_object_get(data, "cost") != NULL)
  9317. {
  9318. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9319. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9320. }
  9321. if(json_object_object_get(data, "state") != NULL)
  9322. {
  9323. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9324. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9325. }
  9326. if(json_object_object_get(data, "chargingPrice") != NULL)
  9327. {
  9328. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9329. {
  9330. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9331. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9332. }
  9333. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9334. {
  9335. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9336. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9337. }
  9338. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9339. {
  9340. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9341. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9342. }
  9343. }
  9344. if(json_object_object_get(data, "idlePrice") != NULL)
  9345. {
  9346. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9347. {
  9348. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9349. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9350. }
  9351. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9352. {
  9353. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9354. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9355. }
  9356. }
  9357. if(json_object_object_get(data, "nextPeriod") != NULL)
  9358. {
  9359. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9360. {
  9361. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9362. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9363. }
  9364. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9365. {
  9366. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9367. {
  9368. 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")));
  9369. 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"));
  9370. }
  9371. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9372. {
  9373. 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")));
  9374. 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"));
  9375. }
  9376. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9377. {
  9378. 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")));
  9379. 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"));
  9380. }
  9381. }
  9382. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9383. {
  9384. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9385. {
  9386. 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")));
  9387. 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"));
  9388. }
  9389. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9390. {
  9391. 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")));
  9392. 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"));
  9393. }
  9394. }
  9395. }
  9396. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9397. {
  9398. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9399. {
  9400. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9401. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9402. }
  9403. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9404. {
  9405. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9406. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9407. }
  9408. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9409. {
  9410. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9411. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9412. }
  9413. }
  9414. }
  9415. }
  9416. }
  9417. }
  9418. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9419. }
  9420. else
  9421. {
  9422. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9423. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9424. }
  9425. json_object_put(data);
  9426. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9427. json_object_put(response);
  9428. }
  9429. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9430. {
  9431. json_object *data;
  9432. data = json_tokener_parse(tempdata);
  9433. if(!is_error(data))
  9434. {
  9435. if(json_object_object_get(data, "txId") != NULL)
  9436. {
  9437. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9438. for(int idx = 0;idx<gunTotalNumber;idx++)
  9439. {
  9440. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9441. {
  9442. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9443. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9444. if(json_object_object_get(data, "description") != NULL)
  9445. {
  9446. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9447. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9448. }
  9449. }
  9450. }
  9451. }
  9452. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9453. }
  9454. else
  9455. {
  9456. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9457. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9458. }
  9459. json_object_put(data);
  9460. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9461. json_object_put(response);
  9462. }
  9463. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9464. {
  9465. json_object *data;
  9466. data = json_tokener_parse(tempdata);
  9467. if(!is_error(data))
  9468. {
  9469. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9470. if(json_object_object_get(data, "Content_Type") != NULL)
  9471. {
  9472. 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))
  9473. {
  9474. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9475. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9476. {
  9477. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9478. }
  9479. }
  9480. else
  9481. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9482. }
  9483. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9484. }
  9485. else
  9486. {
  9487. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9488. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9489. }
  9490. json_object_put(data);
  9491. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9492. json_object_put(response);
  9493. }
  9494. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9495. {
  9496. json_object *data;
  9497. data = json_tokener_parse(tempdata);
  9498. if(!is_error(data))
  9499. {
  9500. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9501. if(json_object_object_get(data, "ConnectorId") != NULL)
  9502. {
  9503. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9504. }
  9505. if(json_object_object_get(data, "SerialNo") != NULL)
  9506. {
  9507. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9508. }
  9509. if(json_object_object_get(data, "Page_Index") != NULL)
  9510. {
  9511. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9512. }
  9513. if(json_object_object_get(data, "Duration") != NULL)
  9514. {
  9515. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9516. }
  9517. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9518. }
  9519. else
  9520. {
  9521. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9522. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9523. }
  9524. json_object_put(data);
  9525. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9526. json_object_put(response);
  9527. }
  9528. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9529. {
  9530. json_object *data;
  9531. data = json_tokener_parse(tempdata);
  9532. if(!is_error(data))
  9533. {
  9534. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9535. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9536. {
  9537. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9538. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9539. else
  9540. {
  9541. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9542. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9543. }
  9544. }
  9545. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9546. {
  9547. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9548. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9549. else
  9550. {
  9551. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9552. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9553. }
  9554. }
  9555. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9556. {
  9557. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9558. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9559. else
  9560. {
  9561. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9562. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9563. }
  9564. }
  9565. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9566. {
  9567. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9568. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9569. else
  9570. {
  9571. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9572. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9573. }
  9574. }
  9575. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9576. {
  9577. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9578. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  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, "OfflinePolicy") != NULL)
  9586. {
  9587. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9588. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9589. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9590. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9591. else
  9592. {
  9593. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9594. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9595. }
  9596. }
  9597. if(json_object_object_get(data, "isAuthentication") != NULL)
  9598. {
  9599. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9600. {
  9601. case 0:
  9602. case 1:
  9603. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9604. break;
  9605. default:
  9606. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9607. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9608. break;
  9609. }
  9610. }
  9611. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9612. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9613. }
  9614. else
  9615. {
  9616. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9617. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9618. }
  9619. json_object_put(data);
  9620. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9621. json_object_put(response);
  9622. }
  9623. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9624. {
  9625. json_object *data;
  9626. data = json_tokener_parse(tempdata);
  9627. if(!is_error(data))
  9628. {
  9629. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9630. {
  9631. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9632. {
  9633. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9634. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  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("Present charged energy data can not get."));
  9640. }
  9641. }
  9642. else
  9643. {
  9644. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9645. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9646. }
  9647. }
  9648. else
  9649. {
  9650. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9651. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9652. }
  9653. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9654. json_object_put(response);
  9655. }
  9656. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9657. {
  9658. json_object *data;
  9659. data = json_tokener_parse(tempdata);
  9660. if(!is_error(data))
  9661. {
  9662. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9663. if(json_object_object_get(data, "stationName") != NULL)
  9664. {
  9665. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  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("station_name data can not get."));
  9671. }
  9672. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9673. {
  9674. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9675. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9676. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9677. }
  9678. }
  9679. else
  9680. {
  9681. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9682. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9683. }
  9684. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9685. json_object_put(response);
  9686. }
  9687. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9688. {
  9689. json_object *data;
  9690. data = json_tokener_parse(tempdata);
  9691. if(!is_error(data))
  9692. {
  9693. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9694. if(json_object_object_get(data, "weatherId") != NULL)
  9695. {
  9696. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9697. }
  9698. else
  9699. {
  9700. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9701. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9702. }
  9703. if(json_object_object_get(data, "Temperature") != NULL)
  9704. {
  9705. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9706. }
  9707. else
  9708. {
  9709. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9710. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9711. }
  9712. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9713. {
  9714. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9715. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9716. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9717. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9718. );
  9719. }
  9720. }
  9721. else
  9722. {
  9723. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9724. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9725. }
  9726. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9727. json_object_put(response);
  9728. }
  9729. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9730. {
  9731. json_object *data;
  9732. data = json_tokener_parse(tempdata);
  9733. if(!is_error(data))
  9734. {
  9735. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9736. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9737. {
  9738. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9739. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9740. }
  9741. else
  9742. {
  9743. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9744. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9745. }
  9746. }
  9747. else
  9748. {
  9749. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9750. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9751. }
  9752. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9753. json_object_put(response);
  9754. }
  9755. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9756. {
  9757. json_object *data;
  9758. data = json_tokener_parse(tempdata);
  9759. if(!is_error(data))
  9760. {
  9761. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9762. {
  9763. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9764. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9765. if(gun_index < gunTotalNumber)
  9766. {
  9767. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9768. {
  9769. json_object *responsedata = json_object_new_object();
  9770. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  9771. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9772. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  9773. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  9774. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9775. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  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("txId doesn't match the current transactionId."));
  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("ConnectorId is invalid."));
  9787. }
  9788. }
  9789. else
  9790. {
  9791. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9792. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9793. }
  9794. }
  9795. else
  9796. {
  9797. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9798. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9799. }
  9800. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9801. json_object_put(response);
  9802. }
  9803. else
  9804. {
  9805. // Can not find valid message id
  9806. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9807. }
  9808. }
  9809. else
  9810. {
  9811. // Payload is null
  9812. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9813. }
  9814. LWS_Send(message);
  9815. return result;
  9816. }
  9817. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9818. {
  9819. mtrace();
  9820. int result = FAIL;
  9821. int connectorIdInt, durationInt;
  9822. char chargingRateUnitStr[4]={0};
  9823. char comfirmstr[20];
  9824. int confirmPeriods = 0;
  9825. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9826. json_object *GetCompositeSchedule;
  9827. GetCompositeSchedule = json_tokener_parse(payload);
  9828. if(!is_error(GetCompositeSchedule))
  9829. {
  9830. // Required data
  9831. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9832. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9833. else
  9834. connectorIdInt = -1;
  9835. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9836. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9837. else
  9838. durationInt = 86400;
  9839. // Optional data
  9840. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9841. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9842. }
  9843. json_object_put(GetCompositeSchedule);
  9844. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9845. if((connectorIdInt == 0) ||
  9846. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9847. {
  9848. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9849. struct StructChargingProfile tmpProfile[1];
  9850. if(strstr(chargingRateUnitStr, "W") != NULL)
  9851. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9852. else
  9853. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9854. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9855. {
  9856. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9857. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9858. }
  9859. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9860. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9861. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9862. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9863. {
  9864. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9865. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9866. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9867. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9868. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9869. {
  9870. confirmPeriods = idx;
  9871. break;
  9872. }
  9873. }
  9874. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9875. {
  9876. confirmPeriods += 1;
  9877. }
  9878. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9879. }
  9880. else
  9881. {
  9882. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9883. }
  9884. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9885. return result;
  9886. }
  9887. int handleGetConfigurationRequest(char *uuid, char *payload)
  9888. {
  9889. mtrace();
  9890. int result = FAIL;
  9891. int MaxKeySupported = 0;
  9892. int n_keys = 0;
  9893. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9894. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9895. json_object *GetConfiguration;
  9896. GetConfiguration = json_tokener_parse(payload);
  9897. if(!is_error(GetConfiguration))
  9898. {
  9899. // Optional data
  9900. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9901. {
  9902. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9903. {
  9904. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9905. n_keys = idx + 1;
  9906. }
  9907. }
  9908. }
  9909. json_object_put(GetConfiguration);
  9910. UnknownKeynum = 0;
  9911. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9912. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9913. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9914. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9915. if(n_keys != 0)
  9916. {
  9917. for(int i=0;i<n_keys;i++)
  9918. {
  9919. getKeyValue(requestKey[i]);
  9920. }
  9921. }
  9922. else
  9923. {
  9924. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9925. getKeyValue("");
  9926. }
  9927. processUnkownKey();
  9928. sendGetConfigurationConfirmation(uuid);
  9929. return result;
  9930. }
  9931. static char fnamePlusPath[100]={0};
  9932. static char fnamePWithNoPath[60]={0};
  9933. void checkUploadLog(void)
  9934. {
  9935. FILE *fp;
  9936. /* Open the command for reading. */
  9937. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9938. if (fp == NULL) {
  9939. DEBUG_WARN("Failed to run command\n" );
  9940. exit(1);
  9941. }
  9942. int ftppathlen = 0;
  9943. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9944. int i = 0;
  9945. /* Read the output a line at a time - output it. */
  9946. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9947. if(i==0)
  9948. {
  9949. ftppathlen = strlen(fnamePlusPath);
  9950. DEBUG_INFO("%s\n", fnamePlusPath);
  9951. fnamePlusPath[ftppathlen]='\0';
  9952. break;
  9953. }
  9954. i= i+1;
  9955. }
  9956. /* close */
  9957. pclose(fp);
  9958. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9959. {
  9960. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9961. {
  9962. fnamePlusPath[k]='\0';
  9963. }
  9964. }
  9965. i=1;
  9966. //char fname[60]={0};
  9967. while(i < ftppathlen)
  9968. {
  9969. int len=ftppathlen-i;
  9970. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9971. {
  9972. DEBUG_INFO("compare '/' all right\n");
  9973. break;
  9974. }
  9975. i=i+1;
  9976. }
  9977. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9978. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9979. fnamePWithNoPath[i+1] = '\0';
  9980. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9981. {
  9982. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9983. {
  9984. fnamePWithNoPath[j]='\0';
  9985. }
  9986. }
  9987. FILE* fp1 = fopen(fnamePlusPath, "r");
  9988. if (fp1)
  9989. {
  9990. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9991. // file exists
  9992. fclose(fp1);
  9993. }
  9994. else
  9995. {
  9996. // file doesn't exist
  9997. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9998. }
  9999. }
  10000. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10001. {
  10002. mtrace();
  10003. int result = FAIL;
  10004. time_t CurrentTime;
  10005. struct tm *tm;
  10006. pthread_t th_Status;
  10007. CurrentTime = time(NULL);
  10008. tm = localtime(&CurrentTime);
  10009. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10010. 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);
  10011. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10012. if(!interLock.isGetDiagnosticGoing)
  10013. {
  10014. interLock.isGetDiagnosticGoing = 1;
  10015. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10016. sleep(1);
  10017. }
  10018. else
  10019. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10020. return result;
  10021. }
  10022. void* GetDiagnosticsProcess(void* data)
  10023. {
  10024. pthread_detach(pthread_self());
  10025. mtrace();
  10026. int retriesInt=0, retryIntervalInt=0;
  10027. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10028. 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};
  10029. int port=0;
  10030. int isSuccess = FALSE;
  10031. char cmdBuf[2048];
  10032. struct tm *tmNow;
  10033. time_t CurrentTime;
  10034. struct tm tmStart;
  10035. struct tm tmStop;
  10036. CurrentTime = time(NULL);
  10037. tmNow=localtime(&CurrentTime);
  10038. uint16_t targetYear, targetMonth;
  10039. json_object *GetDiagnostics;
  10040. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10041. GetDiagnostics = json_tokener_parse(data);
  10042. if(!is_error(GetDiagnostics))
  10043. {
  10044. // Required data
  10045. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10046. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10047. // Optional data
  10048. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10049. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10050. else
  10051. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10052. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10053. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10054. else
  10055. retryIntervalInt = 30;
  10056. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10057. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10058. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10059. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10060. }
  10061. json_object_put(GetDiagnostics);
  10062. // Pack log to compress file
  10063. 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) &&
  10064. (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))
  10065. {
  10066. // Pack system log
  10067. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10068. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10069. targetYear = tmStart.tm_year;
  10070. targetMonth = tmStart.tm_mon;
  10071. do
  10072. {
  10073. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10074. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10075. if(targetMonth+1>=13)
  10076. {
  10077. targetYear += 1;
  10078. targetMonth = 1;
  10079. }
  10080. else
  10081. {
  10082. targetMonth += 1;
  10083. }
  10084. }while((targetYear < (tmNow->tm_year+1900)) ||
  10085. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10086. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10087. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10088. system(cmdBuf);
  10089. // Pack charging & event log
  10090. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10091. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10092. targetYear = tmStart.tm_year;
  10093. targetMonth = tmStart.tm_mon;
  10094. do
  10095. {
  10096. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10097. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10098. if(targetMonth+1>=13)
  10099. {
  10100. targetYear += 1;
  10101. targetMonth = 1;
  10102. }
  10103. else
  10104. {
  10105. targetMonth += 1;
  10106. }
  10107. }while((targetYear < (tmNow->tm_year+1900)) ||
  10108. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10109. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10110. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10111. system(cmdBuf);
  10112. // Combine log file
  10113. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10114. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10115. }
  10116. else
  10117. {
  10118. system("exec /root/logPackTools 'log' 6");
  10119. }
  10120. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10121. system(cmdBuf);
  10122. checkUploadLog();
  10123. //****************location*******************/
  10124. if(strcmp(locationstr,"")==0)
  10125. {
  10126. DEBUG_INFO("location is <Empty>!\n");
  10127. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10128. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10129. goto end;
  10130. }
  10131. memset(protocol, 0, ARRAY_SIZE(protocol));
  10132. memset(user, 0, ARRAY_SIZE(user) );
  10133. memset(password, 0, ARRAY_SIZE(password));
  10134. memset(host, 0, ARRAY_SIZE(host));
  10135. memset(path, 0, ARRAY_SIZE(path));
  10136. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10137. memset(host1, 0, ARRAY_SIZE(host1));
  10138. memset(path1, 0, ARRAY_SIZE(path1));
  10139. /*location: ftp://user:password@host:port/path*/
  10140. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10141. if((access(fnamePlusPath,F_OK))!=-1)
  10142. {
  10143. DEBUG_INFO("fnamePlusPath exist.\n");
  10144. }
  10145. else
  10146. {
  10147. DEBUG_INFO("fnamePlusPath not exist!\n");
  10148. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10149. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10150. goto end;
  10151. }
  10152. if(strchr(locationstr,'@')==NULL)
  10153. {
  10154. sscanf(locationstr,
  10155. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10156. protocol, host, &port, path);
  10157. strcpy(user,"anonymous");
  10158. strcpy(password,"");
  10159. }
  10160. else
  10161. {
  10162. //DEBUG_INFO("pch=%s\n", pch);
  10163. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10164. protocol, user, password, host, &port, path);
  10165. }
  10166. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10167. {
  10168. DEBUG_INFO("protocol is not ftp/http ! \n");
  10169. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10170. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10171. goto end;
  10172. }
  10173. if(strncmp(locationstr,"http", 4) == 0)
  10174. {
  10175. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10176. sprintf(ftppath,"/%s", path);
  10177. do
  10178. {
  10179. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10180. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10181. sleep(3);
  10182. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10183. if(!isSuccess)
  10184. {
  10185. DEBUG_INFO("Diagnostics fail.\n");
  10186. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10187. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10188. sleep(retryIntervalInt);
  10189. }
  10190. else
  10191. {
  10192. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10193. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10194. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10195. }
  10196. retriesInt--;
  10197. }while((isSuccess == 0)&&(retriesInt >= 0));
  10198. }
  10199. else
  10200. {
  10201. sscanf(host,"%[^/]%s",host1, path1);
  10202. if(strlen(path) > 0)
  10203. sprintf(ftppath,"/%s", path);
  10204. else
  10205. sprintf(ftppath,"/%s", path1);
  10206. int ftppathlen=strlen(ftppath);
  10207. int i=1;
  10208. char filenametemp[50];
  10209. while(i < ftppathlen)
  10210. {
  10211. int len=ftppathlen-i;
  10212. if(ftppath[len]== 47) // '/' ascll code: 47
  10213. {
  10214. DEBUG_INFO("find '/' all right\n");
  10215. break;
  10216. }
  10217. i=i+1;
  10218. }
  10219. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10220. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10221. filenametemp[i+1] = 0;
  10222. if(port == 0)
  10223. port = 21;
  10224. do
  10225. {
  10226. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10227. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10228. sleep(3);
  10229. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10230. if(!isSuccess)
  10231. {
  10232. DEBUG_INFO("Diagnostics fail.\n");
  10233. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10234. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10235. sleep(retryIntervalInt);
  10236. }
  10237. else
  10238. {
  10239. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10240. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10241. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10242. }
  10243. retriesInt--;
  10244. }while((!isSuccess)&&(retriesInt >= 0));
  10245. }
  10246. end:
  10247. system("rm -f /mnt/*");
  10248. sleep(5);
  10249. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10250. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10251. interLock.isGetDiagnosticGoing = 0;
  10252. pthread_exit(NULL);
  10253. }
  10254. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10255. {
  10256. mtrace();
  10257. int result = FAIL;
  10258. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10259. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10260. {
  10261. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10262. locallistVersion = -1;
  10263. }
  10264. else
  10265. {
  10266. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10267. OCPP_getListVerion();
  10268. }
  10269. //from db.OCPP_getListVerion
  10270. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10271. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10272. sendGetLocalListVersionConfirmation(uuid,"");
  10273. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10274. return result;
  10275. }
  10276. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10277. {
  10278. mtrace();
  10279. int result = FAIL;
  10280. int connectorIdInt=-1;
  10281. int tempIndex = 0;
  10282. int connectorIdIsNULL, chargingProfileIsNULL;
  10283. char comfirmstr[20]={0};
  10284. char cmdBuf[512];
  10285. json_object *RemoteStartTransaction;
  10286. FILE *fp;
  10287. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10288. if(server_pending == TRUE)
  10289. {
  10290. return 0;
  10291. }
  10292. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10293. RemoteStartTransaction = json_tokener_parse(payload);
  10294. if(!is_error(RemoteStartTransaction))
  10295. {
  10296. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10297. {
  10298. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10299. }
  10300. else
  10301. {
  10302. connectorIdIsNULL = TRUE;
  10303. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10304. {
  10305. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10306. {
  10307. connectorIdIsNULL = FALSE;
  10308. connectorIdInt = (gun_index+1);
  10309. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10310. break;
  10311. }
  10312. }
  10313. }
  10314. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10315. {
  10316. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10317. // Required data
  10318. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10319. // Optional data
  10320. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10321. {
  10322. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10323. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10324. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10325. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10326. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10327. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10328. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10329. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10330. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10331. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10332. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10333. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10334. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10335. {
  10336. 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")));
  10337. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10338. 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"));
  10339. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10340. 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"));
  10341. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10342. 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")));
  10343. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10344. {
  10345. 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++)
  10346. {
  10347. 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"));
  10348. 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"));
  10349. 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)
  10350. 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"));
  10351. }
  10352. }
  10353. }
  10354. }
  10355. else
  10356. {
  10357. chargingProfileIsNULL = TRUE;
  10358. }
  10359. }
  10360. }
  10361. else
  10362. {
  10363. connectorIdIsNULL = TRUE;
  10364. }
  10365. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10366. {
  10367. DEBUG_WARN("Connector id is NULL\n.");
  10368. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10369. goto end;
  10370. }
  10371. /*
  10372. enum _SYSTEM_STATUS
  10373. {
  10374. S_BOOTING = 0,
  10375. S_IDLE, = 1
  10376. S_AUTHORIZING, = 2
  10377. S_REASSIGN_CHECK, = 3
  10378. S_REASSIGN, = 4
  10379. S_PRECHARGE, = 5
  10380. S_PREPARING_FOR_EV, = 6
  10381. S_PREPARING_FOR_EVSE, = 7
  10382. S_CHARGING, = 8
  10383. S_TERMINATING, = 9
  10384. S_COMPLETE, = 10
  10385. S_ALARM, = 11
  10386. S_FAULT = 12
  10387. }
  10388. */
  10389. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10390. {
  10391. //check Transaction active
  10392. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10393. {
  10394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10395. {
  10396. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10397. }
  10398. else
  10399. {
  10400. tempIndex = connectorIdInt -1;
  10401. }
  10402. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10403. {
  10404. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10405. {
  10406. 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))
  10407. {
  10408. //Reserved
  10409. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10410. }
  10411. 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))
  10412. {
  10413. //Reserved
  10414. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10415. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10416. goto end;
  10417. }
  10418. else
  10419. {
  10420. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10421. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10422. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10423. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10424. {
  10425. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10426. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10427. goto end;
  10428. }
  10429. }//END FOR ELSE
  10430. }
  10431. }// END FOR CHAdeMO_QUANTITY
  10432. }
  10433. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10434. {
  10435. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10436. {
  10437. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10438. }
  10439. else
  10440. {
  10441. tempIndex = connectorIdInt -1;
  10442. }
  10443. for (int index = 0; index < CCS_QUANTITY; index++)
  10444. {
  10445. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10446. {
  10447. 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))
  10448. {
  10449. //Reserved
  10450. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10451. }
  10452. 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))
  10453. {
  10454. //Reserved
  10455. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10456. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10457. goto end;
  10458. }
  10459. else
  10460. {
  10461. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10462. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10463. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10464. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10465. {
  10466. DEBUG_WARN("CCS connector not allow start\n.");
  10467. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10468. goto end;
  10469. }
  10470. }// END FOR ELSE
  10471. }
  10472. }// END FOR CCS_QUANTITY
  10473. }
  10474. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10475. {
  10476. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10477. {
  10478. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10479. }
  10480. else
  10481. {
  10482. tempIndex = connectorIdInt -1;
  10483. }
  10484. for (int index = 0; index < GB_QUANTITY; index++)
  10485. {
  10486. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10487. {
  10488. 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))
  10489. {
  10490. //Reserved
  10491. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10492. }
  10493. 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))
  10494. {
  10495. //Reserved
  10496. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10497. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10498. goto end;
  10499. }
  10500. else
  10501. {
  10502. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10503. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10504. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10505. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10506. {
  10507. DEBUG_WARN("GB connector not allow start\n.");
  10508. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10509. goto end;
  10510. }
  10511. }// END FOR ELSE
  10512. }
  10513. } // END FOR GB_QUANTITY
  10514. }
  10515. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10516. {
  10517. tempIndex = connectorIdInt -1;
  10518. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10519. {
  10520. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10521. {
  10522. 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))
  10523. {
  10524. //Reserved
  10525. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10526. }
  10527. 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))
  10528. {
  10529. //Reserved
  10530. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10531. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10532. goto end;
  10533. }
  10534. else
  10535. {
  10536. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10537. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10538. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10539. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10540. {
  10541. DEBUG_WARN("GB connector not allow start\n.");
  10542. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10543. goto end;
  10544. }
  10545. }// END FOR ELSE
  10546. }
  10547. } // END FOR GB_QUANTITY
  10548. }
  10549. else
  10550. {
  10551. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10552. {
  10553. tempIndex = 2;
  10554. }
  10555. else
  10556. {
  10557. tempIndex = connectorIdInt -1;
  10558. }
  10559. for (int index = 0; index < AC_QUANTITY; index++)
  10560. {
  10561. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10562. {
  10563. 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))
  10564. {
  10565. //Reserved
  10566. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10567. }
  10568. 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))
  10569. {
  10570. //Reserved
  10571. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10572. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10573. goto end;
  10574. }
  10575. else
  10576. {
  10577. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10578. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10579. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10580. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10581. {
  10582. DEBUG_WARN("AC connector not allow start\n.");
  10583. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10584. goto end;
  10585. }
  10586. }//END FOR ELSE
  10587. }
  10588. }// END FOR AC_QUANTITY
  10589. }
  10590. if(chargingProfileIsNULL == FALSE)
  10591. {
  10592. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10593. {
  10594. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10595. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10596. //memset idTag
  10597. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10598. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10599. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10600. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10601. // Save profile to file
  10602. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10603. system(cmdBuf);
  10604. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10605. fp = fopen(cmdBuf, "w");
  10606. 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));
  10607. fclose(fp);
  10608. }
  10609. else
  10610. {
  10611. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10612. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10613. }
  10614. }
  10615. else
  10616. {
  10617. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10618. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10619. //memset idTag
  10620. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10621. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10622. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10623. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10624. }
  10625. }
  10626. else
  10627. {
  10628. DEBUG_WARN("Connector id over\n.");
  10629. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10630. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10631. }
  10632. end:
  10633. json_object_put(RemoteStartTransaction);
  10634. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10635. {
  10636. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10637. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10638. }
  10639. //OCPP send RemoteStartConfirmation by first.
  10640. sendRemoteStartConfirmation(uuid, comfirmstr);
  10641. return result;
  10642. }
  10643. int handleRemoteStartRequest(char *uuid, char *payload)
  10644. {
  10645. mtrace();
  10646. int result = PASS;
  10647. int connectorIdInt=-1;
  10648. int tempIndex = 0;
  10649. char comfirmstr[20]={0};
  10650. char cmdBuf[512];
  10651. json_object *RemoteStartTransaction;
  10652. FILE *fp;
  10653. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10654. if(server_pending == TRUE)
  10655. {
  10656. result = FAIL;
  10657. }
  10658. RemoteStartTransaction = json_tokener_parse(payload);
  10659. if(!is_error(RemoteStartTransaction))
  10660. {
  10661. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10662. {
  10663. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10664. }
  10665. else
  10666. {
  10667. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10668. {
  10669. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10670. {
  10671. connectorIdInt = (gun_index+1);
  10672. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10673. break;
  10674. }
  10675. }
  10676. }
  10677. if(connectorIdInt == 0)
  10678. {
  10679. DEBUG_WARN("Connector id shall not equal 0.\n");
  10680. result = FAIL;
  10681. }
  10682. else if(connectorIdInt == -1)
  10683. {
  10684. DEBUG_INFO("Connector id does not specific.\n");
  10685. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10686. {
  10687. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10688. // Required data
  10689. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10690. // Optional data
  10691. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10692. {
  10693. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10694. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10695. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10696. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10697. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10698. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10699. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10700. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10701. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10702. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10703. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10704. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10705. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10706. {
  10707. 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")));
  10708. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10709. 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"));
  10710. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10711. 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"));
  10712. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10713. 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")));
  10714. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10715. {
  10716. 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++)
  10717. {
  10718. 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"));
  10719. 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"));
  10720. 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)
  10721. 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"));
  10722. }
  10723. }
  10724. }
  10725. }
  10726. else
  10727. {
  10728. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10729. }
  10730. }
  10731. }
  10732. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10733. {
  10734. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10735. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10736. // Required data
  10737. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10738. // Optional data
  10739. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10740. {
  10741. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10742. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10743. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10744. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10745. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10746. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10747. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10748. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10749. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10750. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10751. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10752. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10753. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10754. {
  10755. 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")));
  10756. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10757. 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"));
  10758. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10759. 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"));
  10760. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10761. 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")));
  10762. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10763. {
  10764. 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++)
  10765. {
  10766. 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"));
  10767. 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"));
  10768. 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)
  10769. 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"));
  10770. }
  10771. }
  10772. }
  10773. }
  10774. else
  10775. {
  10776. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10777. }
  10778. }
  10779. else
  10780. {
  10781. DEBUG_WARN("Connector id is over maximun value.\n");
  10782. result = FAIL;
  10783. }
  10784. }
  10785. if(result == PASS)
  10786. {
  10787. if(connectorIdInt > 0)
  10788. {
  10789. //check Transaction active
  10790. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10791. {
  10792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10793. {
  10794. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10795. }
  10796. else
  10797. {
  10798. tempIndex = connectorIdInt -1;
  10799. }
  10800. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10801. {
  10802. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10803. {
  10804. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10805. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10806. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10807. {
  10808. //Reserved
  10809. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10810. }
  10811. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10812. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10813. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10814. {
  10815. //Reserved
  10816. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10817. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10818. goto end;
  10819. }
  10820. else
  10821. {
  10822. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10823. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10824. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10825. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10826. {
  10827. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10828. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10829. goto end;
  10830. }
  10831. }//END FOR ELSE
  10832. }
  10833. }// END FOR CHAdeMO_QUANTITY
  10834. }
  10835. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10836. {
  10837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10838. {
  10839. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10840. }
  10841. else
  10842. {
  10843. tempIndex = connectorIdInt -1;
  10844. }
  10845. for (int index = 0; index < CCS_QUANTITY; index++)
  10846. {
  10847. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10848. {
  10849. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10850. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10851. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10852. {
  10853. //Reserved
  10854. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10855. }
  10856. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10857. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10858. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10859. {
  10860. //Reserved
  10861. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10862. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10863. goto end;
  10864. }
  10865. else
  10866. {
  10867. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10868. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10869. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10870. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10871. {
  10872. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10873. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10874. goto end;
  10875. }
  10876. }// END FOR ELSE
  10877. }
  10878. }// END FOR CCS_QUANTITY
  10879. }
  10880. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10881. {
  10882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10883. {
  10884. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10885. }
  10886. else
  10887. {
  10888. tempIndex = connectorIdInt -1;
  10889. }
  10890. for (int index = 0; index < GB_QUANTITY; index++)
  10891. {
  10892. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10893. {
  10894. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10895. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10896. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10897. {
  10898. //Reserved
  10899. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10900. }
  10901. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10902. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10903. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10904. {
  10905. //Reserved
  10906. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10907. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10908. goto end;
  10909. }
  10910. else
  10911. {
  10912. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10913. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10914. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10915. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10916. {
  10917. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10918. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10919. goto end;
  10920. }
  10921. }// END FOR ELSE
  10922. }
  10923. } // END FOR GB_QUANTITY
  10924. }
  10925. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10926. {
  10927. tempIndex = connectorIdInt -1;
  10928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10929. {
  10930. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10931. {
  10932. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10933. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10934. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10935. {
  10936. //Reserved
  10937. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10938. }
  10939. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10940. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10941. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10942. {
  10943. //Reserved
  10944. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10945. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10946. goto end;
  10947. }
  10948. else
  10949. {
  10950. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10951. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10952. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10953. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10954. {
  10955. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10956. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10957. goto end;
  10958. }
  10959. }// END FOR ELSE
  10960. }
  10961. } // END FOR GB_QUANTITY
  10962. }
  10963. else
  10964. {
  10965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10966. {
  10967. tempIndex = 2;
  10968. }
  10969. else
  10970. {
  10971. tempIndex = connectorIdInt -1;
  10972. }
  10973. for (int index = 0; index < AC_QUANTITY; index++)
  10974. {
  10975. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10976. {
  10977. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10978. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10979. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10980. {
  10981. //Reserved
  10982. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10983. }
  10984. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10985. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10986. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10987. {
  10988. //Reserved
  10989. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10990. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10991. goto end;
  10992. }
  10993. else
  10994. {
  10995. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10996. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10997. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10998. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10999. {
  11000. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11001. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11002. goto end;
  11003. }
  11004. }//END FOR ELSE
  11005. }
  11006. }// END FOR AC_QUANTITY
  11007. }
  11008. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11009. {
  11010. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11011. {
  11012. // Save profile to file
  11013. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11014. system(cmdBuf);
  11015. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11016. fp = fopen(cmdBuf, "w");
  11017. 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));
  11018. fclose(fp);
  11019. }
  11020. else
  11021. {
  11022. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11023. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11024. goto end;
  11025. }
  11026. }
  11027. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11028. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11029. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11030. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11031. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11032. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11033. }
  11034. else
  11035. {
  11036. uint8_t isHasIdleConnector = FALSE;
  11037. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11038. {
  11039. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11040. {
  11041. isHasIdleConnector = TRUE;
  11042. break;
  11043. }
  11044. }
  11045. if(isHasIdleConnector == TRUE)
  11046. {
  11047. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11048. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11049. {
  11050. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11051. {
  11052. // Save profile to file
  11053. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11054. system(cmdBuf);
  11055. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11056. fp = fopen(cmdBuf, "w");
  11057. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11058. fclose(fp);
  11059. refreshStartTimer(&clientTime.RemoteStartWait);
  11060. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11061. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11062. }
  11063. else
  11064. {
  11065. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11066. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11067. }
  11068. }
  11069. else
  11070. {
  11071. refreshStartTimer(&clientTime.RemoteStartWait);
  11072. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11073. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11074. }
  11075. }
  11076. else
  11077. {
  11078. DEBUG_INFO("There is not any connector is idle.\n");
  11079. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11080. }
  11081. }
  11082. }
  11083. else
  11084. {
  11085. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11086. }
  11087. end:
  11088. json_object_put(RemoteStartTransaction);
  11089. sendRemoteStartConfirmation(uuid, comfirmstr);
  11090. return result;
  11091. }
  11092. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11093. {
  11094. mtrace();
  11095. int result = FAIL;
  11096. int match = FALSE;
  11097. int GunNO = 0;
  11098. int tempIndex = 0;
  11099. int transactionIdInt=0;
  11100. int transactionIdIsNULL= TRUE;
  11101. char comfirmstr[20];
  11102. json_object *RemoteStopTransaction;
  11103. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11104. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11105. if(server_pending == TRUE)
  11106. {
  11107. return 0;
  11108. }
  11109. RemoteStopTransaction = json_tokener_parse(payload);
  11110. if(!is_error(RemoteStopTransaction))
  11111. {
  11112. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11113. {
  11114. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11115. transactionIdIsNULL = FALSE;
  11116. }
  11117. }
  11118. json_object_put(RemoteStopTransaction);
  11119. if(transactionIdIsNULL == FALSE)
  11120. {
  11121. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11122. {
  11123. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11124. {
  11125. //check Transaction active
  11126. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11127. {
  11128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11129. {
  11130. tempIndex = ((gun_index==2) ? 1: 0);
  11131. }
  11132. else
  11133. {
  11134. tempIndex = gun_index;
  11135. }
  11136. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11137. {
  11138. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11139. {
  11140. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11141. {
  11142. match = TRUE;
  11143. GunNO = gun_index;
  11144. }
  11145. }
  11146. }// END FOR CHAdeMO_QUANTITY
  11147. }
  11148. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11149. {
  11150. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11151. {
  11152. tempIndex = ((gun_index==2) ? 1: 0);
  11153. }
  11154. else
  11155. {
  11156. tempIndex = gun_index;
  11157. }
  11158. for (int index = 0; index < CCS_QUANTITY; index++)
  11159. {
  11160. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11161. {
  11162. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11163. {
  11164. match = TRUE;
  11165. GunNO = gun_index;
  11166. }
  11167. }
  11168. }// END FOR CCS_QUANTITY
  11169. }
  11170. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11171. {
  11172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11173. {
  11174. tempIndex = ((gun_index==2) ? 1: 0);
  11175. }
  11176. else
  11177. {
  11178. tempIndex = gun_index;
  11179. }
  11180. for (int index = 0; index < GB_QUANTITY; index++)
  11181. {
  11182. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11183. {
  11184. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11185. {
  11186. match = TRUE;
  11187. GunNO = gun_index;
  11188. }
  11189. }
  11190. }// END FOR GB_QUANTITY
  11191. }
  11192. else if(gunType[gun_index] == GUN_TYPE_DO)
  11193. {
  11194. tempIndex = gun_index;
  11195. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11196. {
  11197. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11198. {
  11199. 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
  11200. {
  11201. match = TRUE;
  11202. GunNO = gun_index;
  11203. }
  11204. }
  11205. }// END FOR GB_QUANTITY
  11206. }
  11207. else
  11208. {
  11209. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11210. {
  11211. tempIndex = 2;
  11212. }
  11213. else
  11214. {
  11215. tempIndex = gun_index;
  11216. }
  11217. for (int index = 0; index < AC_QUANTITY; index++)
  11218. {
  11219. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11220. {
  11221. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11222. {
  11223. match = TRUE;
  11224. GunNO = gun_index;
  11225. }
  11226. }
  11227. }// END FOR CHAdeMO_QUANTITY
  11228. } // END FOR AC ELSE
  11229. }// CHECK IF ResponseTransactionId == transactionIdInt
  11230. }//END FOR
  11231. if( match == TRUE)
  11232. {
  11233. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11234. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11235. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11236. }
  11237. else
  11238. {
  11239. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11240. }
  11241. }
  11242. else
  11243. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11244. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11245. return result;
  11246. }
  11247. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11248. {
  11249. mtrace();
  11250. int result = FAIL;
  11251. int connectorIdInt=0, reservationIdInt=0;
  11252. int tempIndex = 0;
  11253. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11254. char comfirmstr[20]={0};
  11255. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11256. int c = 0;
  11257. char *loc;
  11258. //char *ptr;
  11259. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11260. strcpy(sstrtemp, stringtrimspace(payload));
  11261. //***(1)connectorId ****/
  11262. c=0;
  11263. loc = strstr(sstrtemp, "connectorId");
  11264. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11265. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11266. {
  11267. sstr[c] = loc[strlen("connectorId")+2+c];
  11268. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11269. c++;
  11270. }
  11271. sstr[c] = '\0';
  11272. connectorIdInt = atoi(sstr);
  11273. //***(2)expiryDate ****/
  11274. loc = strstr(sstrtemp, "expiryDate");
  11275. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11276. c = 0;
  11277. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11278. {
  11279. sstr[c] = loc[3+strlen("expiryDate")+c];
  11280. c++;
  11281. }
  11282. sstr[c] = '\0';
  11283. strcpy(expiryDatestr, sstr);
  11284. //***(3)idTag ****/
  11285. loc = strstr(sstrtemp, "idTag");
  11286. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11287. c = 0;
  11288. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11289. {
  11290. sstr[c] = loc[3+strlen("idTag")+c];
  11291. c++;
  11292. }
  11293. sstr[c] = '\0';
  11294. strcpy(idTagstr, sstr);
  11295. //***(4)parentIdTag ****/
  11296. loc = strstr(sstrtemp, "parentIdTag");
  11297. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11298. c = 0;
  11299. if(loc == NULL)
  11300. {
  11301. strcpy(parentIdTagstr, "");
  11302. }
  11303. else
  11304. {
  11305. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11306. {
  11307. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11308. c++;
  11309. }
  11310. sstr[c] = '\0';
  11311. strcpy(parentIdTagstr, sstr);
  11312. }
  11313. //***(5)reservationId ****/
  11314. c=0;
  11315. loc = strstr(sstrtemp, "reservationId");
  11316. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11317. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11318. {
  11319. sstr[c] = loc[strlen("reservationId")+2+c];
  11320. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11321. c++;
  11322. }
  11323. sstr[c] = '\0';
  11324. reservationIdInt = atoi(sstr);
  11325. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11326. /*
  11327. enum SYSTEM_STATUS
  11328. {
  11329. SYS_MODE_BOOTING = 0,
  11330. SYS_MODE_IDLE = 1,
  11331. SYS_MODE_AUTHORIZING = 2,
  11332. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11333. SYS_MODE_REASSIGN = 4,
  11334. SYS_MODE_PREPARING = 5,
  11335. SYS_MODE_PREPARE_FOR_EV = 6,
  11336. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11337. SYS_MODE_CHARGING = 8,
  11338. SYS_MODE_TERMINATING = 9,
  11339. SYS_MODE_COMPLETE = 10,
  11340. SYS_MODE_ALARM = 11,
  11341. SYS_MODE_FAULT = 12,
  11342. SYS_MODE_RESERVATION = 13,
  11343. SYS_MODE_BOOKING = 14,
  11344. SYS_MODE_MAINTAIN = 15,
  11345. SYS_MODE_DEBUG = 16,
  11346. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11347. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11348. SYS_MODE_UPDATE = 19
  11349. };
  11350. */
  11351. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11352. {
  11353. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11354. goto end;
  11355. }
  11356. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11357. {
  11358. //check Transaction active
  11359. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11360. {
  11361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11362. {
  11363. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11364. }
  11365. else
  11366. {
  11367. tempIndex = connectorIdInt -1;
  11368. }
  11369. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11370. {
  11371. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11372. {
  11373. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11374. {
  11375. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11376. {
  11377. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11378. {
  11379. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11380. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11381. }
  11382. 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'))
  11383. {
  11384. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11385. }
  11386. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11387. {
  11388. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11389. }
  11390. else
  11391. {
  11392. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11393. }
  11394. }
  11395. 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
  11396. {
  11397. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11398. }
  11399. }
  11400. else
  11401. {
  11402. //replace reservation
  11403. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11404. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11405. }
  11406. }
  11407. } // END FOR CHAdeMO_QUANTITY
  11408. }
  11409. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11410. {
  11411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11412. {
  11413. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11414. }
  11415. else
  11416. {
  11417. tempIndex = connectorIdInt -1;
  11418. }
  11419. for (int index = 0; index < CCS_QUANTITY; index++)
  11420. {
  11421. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11422. {
  11423. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11424. {
  11425. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11426. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11427. {
  11428. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11429. {
  11430. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11431. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11432. }
  11433. 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'))
  11434. {
  11435. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11436. }
  11437. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11438. {
  11439. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11440. }
  11441. else
  11442. {
  11443. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11444. }
  11445. }
  11446. 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
  11447. {
  11448. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11449. }
  11450. }
  11451. else
  11452. {
  11453. //replace reservation
  11454. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11455. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11456. }
  11457. }
  11458. } // END FOR CCS_QUANTITY
  11459. }
  11460. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11461. {
  11462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11463. {
  11464. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11465. }
  11466. else
  11467. {
  11468. tempIndex = connectorIdInt -1;
  11469. }
  11470. for (int index = 0; index < GB_QUANTITY; index++)
  11471. {
  11472. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11473. {
  11474. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11475. {
  11476. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11477. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11478. {
  11479. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11480. {
  11481. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11482. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11483. }
  11484. 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'))
  11485. {
  11486. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11487. }
  11488. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11489. {
  11490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11491. }
  11492. else
  11493. {
  11494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11495. }
  11496. }
  11497. 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
  11498. {
  11499. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11500. }
  11501. }
  11502. else
  11503. {
  11504. //replace reservation
  11505. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11506. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11507. }
  11508. }
  11509. }// END FOR GB_QUANTITY
  11510. }
  11511. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11512. {
  11513. tempIndex = connectorIdInt -1;
  11514. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11515. {
  11516. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11517. {
  11518. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11519. {
  11520. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11521. 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
  11522. {
  11523. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11524. {
  11525. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11527. }
  11528. 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'))
  11529. {
  11530. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11531. }
  11532. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11533. {
  11534. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11535. }
  11536. else
  11537. {
  11538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11539. }
  11540. }
  11541. 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
  11542. {
  11543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11544. }
  11545. }
  11546. else
  11547. {
  11548. //replace reservation
  11549. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11551. }
  11552. }
  11553. }// END FOR GB_QUANTITY
  11554. }
  11555. else
  11556. {
  11557. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11558. {
  11559. tempIndex = 2;
  11560. }
  11561. else
  11562. {
  11563. tempIndex = (connectorIdInt -1);
  11564. }
  11565. for (int index = 0; index < AC_QUANTITY; index++)
  11566. {
  11567. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11568. {
  11569. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11570. {
  11571. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11572. {
  11573. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11574. {
  11575. 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))
  11576. {
  11577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11578. }
  11579. else
  11580. {
  11581. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11582. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11583. }
  11584. }
  11585. 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'))
  11586. {
  11587. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11588. }
  11589. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11590. {
  11591. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11592. }
  11593. else
  11594. {
  11595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11596. }
  11597. }
  11598. 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
  11599. {
  11600. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11601. }
  11602. }
  11603. else
  11604. {
  11605. //replace reservation
  11606. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11608. }
  11609. }
  11610. } // END FOR AC_QUANTITY
  11611. }
  11612. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11613. }
  11614. else if(connectorIdInt == 0)
  11615. {
  11616. //check Transaction active
  11617. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11618. {
  11619. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11620. {
  11621. 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'))
  11622. {
  11623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11624. goto end;
  11625. }
  11626. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11627. {
  11628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11629. goto end;
  11630. }
  11631. 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
  11632. {
  11633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11634. goto end;
  11635. }
  11636. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11637. {
  11638. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11639. goto end;
  11640. }
  11641. }
  11642. }// END FOR CHAdeMO_QUANTITY
  11643. for (int index = 0; index < CCS_QUANTITY; index++)
  11644. {
  11645. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11646. {
  11647. 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'))
  11648. {
  11649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11650. goto end;
  11651. }
  11652. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11653. {
  11654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11655. goto end;
  11656. }
  11657. 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
  11658. {
  11659. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11660. goto end;
  11661. }
  11662. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11663. {
  11664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11665. goto end;
  11666. }
  11667. }
  11668. } // END FOR CCS_QUANTITY
  11669. for (int index = 0; index < GB_QUANTITY; index++)
  11670. {
  11671. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11672. {
  11673. 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'))
  11674. {
  11675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11676. goto end;
  11677. }
  11678. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11679. {
  11680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11681. goto end;
  11682. }
  11683. 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
  11684. {
  11685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11686. goto end;
  11687. }
  11688. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11689. {
  11690. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11691. goto end;
  11692. }
  11693. }
  11694. } // END FOR GB_QUANTITY
  11695. for (int index = 0; index < AC_QUANTITY; index++)
  11696. {
  11697. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11698. {
  11699. 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'))
  11700. {
  11701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11702. goto end;
  11703. }
  11704. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11705. {
  11706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11707. goto end;
  11708. }
  11709. 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
  11710. {
  11711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11712. goto end;
  11713. }
  11714. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11715. {
  11716. 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))
  11717. {
  11718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11719. goto end;
  11720. }
  11721. }
  11722. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11723. {
  11724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11725. goto end;
  11726. }
  11727. }
  11728. }// END FOR AC_QUANTITY
  11729. //The connectorId is 0
  11730. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11731. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11732. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11733. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11734. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11735. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11736. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11737. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11738. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11739. result = TRUE;
  11740. return result;
  11741. }
  11742. else
  11743. {
  11744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11745. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11746. }
  11747. if(strcmp(comfirmstr,"Accepted") == 0)
  11748. {
  11749. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11750. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11751. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11752. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11753. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11754. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11755. result = TRUE;
  11756. return result;
  11757. }
  11758. end:
  11759. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11760. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11761. return result;
  11762. }
  11763. int handleResetRequest(char *uuid, char *payload)
  11764. {
  11765. mtrace();
  11766. int result = FAIL;
  11767. char sstr[10]={0},sstrtemp[30]={ 0 };
  11768. char typestr[10]={0};
  11769. char comfirmstr[20]={0};
  11770. int c = 0;
  11771. char *loc;
  11772. DEBUG_INFO("handleResetRequest...\n");
  11773. strcpy(sstrtemp, stringtrimspace(payload));
  11774. loc = strstr(sstrtemp, "type");
  11775. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11776. c = 0;
  11777. while (loc[3+strlen("type")+c] != '\"')
  11778. {
  11779. sstr[c] = loc[3+strlen("type")+c];
  11780. c++;
  11781. }
  11782. sstr[c] = '\0';
  11783. strcpy(typestr,sstr);
  11784. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11785. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11786. {
  11787. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11788. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11789. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11790. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11791. }
  11792. else
  11793. {
  11794. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11795. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11796. result = PASS;
  11797. }
  11798. sendResetConfirmation(uuid, comfirmstr);
  11799. return result;
  11800. }
  11801. int handleSendLocalListRequest(char *uuid, char *payload)
  11802. {
  11803. mtrace();
  11804. int result = FAIL;
  11805. char comfirmstr[20];
  11806. int checkState_Faulted = FALSE;
  11807. json_object *SendLocalList;
  11808. DEBUG_INFO("handleSendLocalListRequest...\n");
  11809. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11810. {
  11811. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11812. goto end;
  11813. }
  11814. //check Charge Point state
  11815. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11816. {
  11817. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11818. {
  11819. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11820. }
  11821. }
  11822. for (int index = 0; index < CCS_QUANTITY; index++)
  11823. {
  11824. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11825. {
  11826. checkState_Faulted = TRUE; //OCPP Status
  11827. }
  11828. }
  11829. for (int index = 0; index < GB_QUANTITY; index++)
  11830. {
  11831. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11832. {
  11833. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11834. }
  11835. }
  11836. //check Charge Point state
  11837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11838. {
  11839. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11840. {
  11841. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11842. }
  11843. }
  11844. //check Charge Point state
  11845. for (int index = 0; index < AC_QUANTITY; index++)
  11846. {
  11847. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11848. {
  11849. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11850. }
  11851. }
  11852. if(checkState_Faulted == TRUE)
  11853. {
  11854. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11855. goto end;
  11856. }
  11857. // Parsing payload
  11858. SendLocalList = json_tokener_parse(payload);
  11859. if(!is_error(SendLocalList))
  11860. {
  11861. // Required data
  11862. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11863. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11864. // Optional data
  11865. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11866. {
  11867. //Check UpdateType
  11868. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11869. {
  11870. //Local list full update
  11871. DEBUG_INFO("Local list full update.\n");
  11872. OCPP_getListVerion();
  11873. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11874. {
  11875. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11876. goto end;
  11877. }
  11878. OCPP_cleanLocalList();
  11879. }
  11880. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11881. {
  11882. //Local list different update
  11883. DEBUG_INFO("Local list different update.\n");
  11884. OCPP_getListVerion();
  11885. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11886. {
  11887. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11888. goto end;
  11889. }
  11890. }
  11891. else
  11892. {
  11893. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11894. goto end;
  11895. }
  11896. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11897. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11898. {
  11899. 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")));
  11900. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11901. {
  11902. 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")));
  11903. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11904. 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")));
  11905. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11906. 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")));
  11907. }
  11908. // Add to db
  11909. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11910. {
  11911. //Local list full update
  11912. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11913. idx,
  11914. ShmOCPP16Data->SendLocalList.ListVersion,
  11915. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11916. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11917. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11918. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11919. // update list
  11920. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11921. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11922. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11923. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11924. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11925. }
  11926. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11927. {
  11928. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11929. idx,
  11930. ShmOCPP16Data->SendLocalList.ListVersion,
  11931. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11932. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11933. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11934. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11935. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11936. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11937. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11938. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11939. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11940. }
  11941. }
  11942. }
  11943. else
  11944. {
  11945. //Check UpdateType
  11946. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11947. {
  11948. //Local list full update
  11949. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11950. OCPP_cleanLocalList();
  11951. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11952. goto end;
  11953. }
  11954. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11955. {
  11956. //Local list different update
  11957. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11958. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11959. goto end;
  11960. }
  11961. }
  11962. result = PASS;
  11963. }
  11964. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11965. end:
  11966. json_object_put(SendLocalList);
  11967. sendSendLocalListConfirmation(uuid, comfirmstr);
  11968. return result;
  11969. }
  11970. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11971. {
  11972. mtrace();
  11973. int result = FAIL;
  11974. struct StructSetChargingProfile SetProfileReq = {0};
  11975. int tempchargingProfileIdInt;
  11976. int tempstackLevelInt;
  11977. int chargingSchedulePeriodCount = 0;
  11978. char comfirmstr[20]={0};
  11979. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11980. char rmFileCmd[128]={0};
  11981. int profileQuantity = 0;
  11982. int isReplaceable = FALSE;
  11983. json_object *SetChargingProfile;
  11984. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11985. SetChargingProfile = json_tokener_parse(payload);
  11986. if(!is_error(SetChargingProfile))
  11987. {
  11988. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11989. {
  11990. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11991. }
  11992. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11993. {
  11994. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11995. {
  11996. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11997. }
  11998. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11999. {
  12000. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12001. }
  12002. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12003. {
  12004. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12005. }
  12006. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12007. {
  12008. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12009. }
  12010. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12011. {
  12012. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12013. }
  12014. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12015. {
  12016. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12017. }
  12018. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12019. {
  12020. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12021. }
  12022. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12023. {
  12024. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12025. }
  12026. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12027. {
  12028. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12029. {
  12030. 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")));
  12031. }
  12032. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12033. {
  12034. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12035. }
  12036. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12037. {
  12038. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12039. }
  12040. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12041. {
  12042. 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")));
  12043. }
  12044. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12045. {
  12046. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12047. if(chargingSchedulePeriodCount <= 10)
  12048. {
  12049. 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++)
  12050. {
  12051. 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)
  12052. {
  12053. 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"));
  12054. }
  12055. 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)
  12056. {
  12057. 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"));
  12058. }
  12059. 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)
  12060. {
  12061. 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"));
  12062. }
  12063. }
  12064. }
  12065. }
  12066. }
  12067. }
  12068. }
  12069. // Profile periods quantity check
  12070. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12071. {
  12072. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12073. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12074. goto end;
  12075. }
  12076. // Check invalid limit
  12077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12078. {
  12079. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12080. {
  12081. 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)))) ||
  12082. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12083. {
  12084. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12085. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12086. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12087. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12088. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12089. goto end;
  12090. }
  12091. }
  12092. }
  12093. else
  12094. {
  12095. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12096. {
  12097. 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))
  12098. {
  12099. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12100. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12101. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12102. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12103. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12104. goto end;
  12105. }
  12106. }
  12107. }
  12108. // Profile purpose info check
  12109. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12110. {
  12111. FILE *fp;
  12112. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12113. if(SetProfileReq.ConnectorId != 0)
  12114. {
  12115. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12116. DEBUG_WARN("Profile connector id is not 0.\n");
  12117. goto end;
  12118. }
  12119. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12120. if (!fp)
  12121. {
  12122. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12123. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12124. }
  12125. else
  12126. {
  12127. char *line = NULL;
  12128. size_t len = 0;
  12129. while(getline(&line, &len, fp) != -1)
  12130. {
  12131. json_object *obj = NULL;
  12132. obj = json_tokener_parse(line);
  12133. if(is_error(obj))
  12134. {
  12135. DEBUG_ERROR("Parse txProfile from file error.\n");
  12136. }
  12137. else
  12138. {
  12139. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12140. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12141. {
  12142. profileQuantity += 1;
  12143. }
  12144. else
  12145. isReplaceable = TRUE;
  12146. }
  12147. }
  12148. }
  12149. fclose(fp);
  12150. }
  12151. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12152. {
  12153. FILE *fp;
  12154. char filename[128]={0};
  12155. int tmpProfileQuantity;
  12156. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12157. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12158. {
  12159. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12160. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12161. goto end;
  12162. }
  12163. if(SetProfileReq.ConnectorId == 0)
  12164. {
  12165. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12166. {
  12167. tmpProfileQuantity = 0;
  12168. memset(filename, 0, ARRAY_SIZE(filename));
  12169. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12170. fp = fopen(filename, "r");
  12171. if (!fp)
  12172. {
  12173. DEBUG_INFO("%s does not create.\n", filename);
  12174. fp = fopen(filename, "w+");
  12175. }
  12176. else
  12177. {
  12178. char *line = NULL;
  12179. size_t len = 0;
  12180. while(getline(&line, &len, fp) != -1)
  12181. {
  12182. json_object *obj = NULL;
  12183. obj = json_tokener_parse(line);
  12184. if(is_error(obj))
  12185. {
  12186. DEBUG_ERROR("Parse txProfile from file error.\n");
  12187. }
  12188. else
  12189. {
  12190. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12191. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12192. {
  12193. tmpProfileQuantity += 1;
  12194. }
  12195. else
  12196. isReplaceable = TRUE;
  12197. }
  12198. }
  12199. }
  12200. fclose(fp);
  12201. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12202. }
  12203. }
  12204. else
  12205. {
  12206. memset(filename, 0, ARRAY_SIZE(filename));
  12207. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12208. fp = fopen(filename, "r");
  12209. if (!fp)
  12210. {
  12211. DEBUG_INFO("%s does not create.\n", filename);
  12212. fp = fopen(filename, "w+");
  12213. }
  12214. else
  12215. {
  12216. char *line = NULL;
  12217. size_t len = 0;
  12218. while(getline(&line, &len, fp) != -1)
  12219. {
  12220. json_object *obj = NULL;
  12221. obj = json_tokener_parse(line);
  12222. if(is_error(obj))
  12223. {
  12224. DEBUG_ERROR("Parse txProfile from file error.\n");
  12225. }
  12226. else
  12227. {
  12228. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12229. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12230. {
  12231. profileQuantity += 1;
  12232. }
  12233. else
  12234. isReplaceable = TRUE;
  12235. }
  12236. }
  12237. }
  12238. fclose(fp);
  12239. }
  12240. }
  12241. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12242. {
  12243. int isMatchTransactiodId= FALSE;
  12244. FILE *fp;
  12245. char filename[128]={0};
  12246. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12247. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12248. if(SetProfileReq.ConnectorId == 0)
  12249. {
  12250. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12251. DEBUG_WARN("Profile connector id is 0.\n");
  12252. goto end;
  12253. }
  12254. int tempIndex = 0;
  12255. //check Transaction active
  12256. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12257. {
  12258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12259. {
  12260. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12261. }
  12262. else
  12263. {
  12264. tempIndex = SetProfileReq.ConnectorId -1;
  12265. }
  12266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12267. {
  12268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12269. {
  12270. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12271. {
  12272. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12273. {
  12274. isMatchTransactiodId = TRUE;
  12275. break;
  12276. }
  12277. }
  12278. }
  12279. }
  12280. }
  12281. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12282. {
  12283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12284. {
  12285. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12286. }
  12287. else
  12288. {
  12289. tempIndex = SetProfileReq.ConnectorId -1;
  12290. }
  12291. for (int index = 0; index < CCS_QUANTITY; index++)
  12292. {
  12293. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12294. {
  12295. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12296. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12297. {
  12298. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12299. {
  12300. isMatchTransactiodId = TRUE;
  12301. break;
  12302. }
  12303. }
  12304. }
  12305. }
  12306. }
  12307. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12308. {
  12309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12310. {
  12311. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12312. }
  12313. else
  12314. {
  12315. tempIndex = SetProfileReq.ConnectorId -1;
  12316. }
  12317. for (int index = 0; index < GB_QUANTITY; index++)
  12318. {
  12319. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12320. {
  12321. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12322. {
  12323. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12324. {
  12325. isMatchTransactiodId = TRUE;
  12326. break;
  12327. }
  12328. }
  12329. }
  12330. }
  12331. }
  12332. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12333. {
  12334. tempIndex = SetProfileReq.ConnectorId -1;
  12335. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12336. {
  12337. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12338. {
  12339. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12340. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12341. {
  12342. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12343. {
  12344. isMatchTransactiodId = TRUE;
  12345. break;
  12346. }
  12347. }
  12348. }
  12349. }
  12350. }
  12351. else
  12352. {
  12353. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12354. {
  12355. tempIndex = 2;
  12356. }
  12357. else
  12358. {
  12359. tempIndex = (SetProfileReq.ConnectorId -1);
  12360. }
  12361. for (int index = 0; index < AC_QUANTITY; index++)
  12362. {
  12363. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12364. {
  12365. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12366. {
  12367. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12368. {
  12369. isMatchTransactiodId = TRUE;
  12370. break;
  12371. }
  12372. }
  12373. }
  12374. }
  12375. }
  12376. //check Transaction active
  12377. if(isMatchTransactiodId == FALSE)
  12378. {
  12379. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12380. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12381. goto end;
  12382. }
  12383. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12384. {
  12385. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12386. DEBUG_WARN("Connector id is over max gun number.\n");
  12387. goto end;
  12388. }
  12389. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12390. fp = fopen(filename, "r");
  12391. if (!fp)
  12392. {
  12393. DEBUG_INFO("%s does not create.\n", filename);
  12394. fp = fopen(filename, "w+");
  12395. }
  12396. else
  12397. {
  12398. char *line = NULL;
  12399. size_t len = 0;
  12400. while(getline(&line, &len, fp) != -1)
  12401. {
  12402. json_object *obj = NULL;
  12403. obj = json_tokener_parse(line);
  12404. if(is_error(obj))
  12405. {
  12406. DEBUG_ERROR("Parse txProfile from file error.\n");
  12407. }
  12408. else
  12409. {
  12410. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12411. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12412. {
  12413. profileQuantity += 1;
  12414. }
  12415. else
  12416. isReplaceable = TRUE;
  12417. }
  12418. }
  12419. }
  12420. fclose(fp);
  12421. }
  12422. // Check ChargeProfileMaxStackLevel
  12423. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12424. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12425. {
  12426. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12427. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12428. goto end;
  12429. }
  12430. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12431. {
  12432. FILE *fp;
  12433. char dataLine[4096]={0};
  12434. char fnametemp[128]={0};
  12435. int tmpProfileQuantity;
  12436. //Check ChargePointMaxProfile.json exit
  12437. profileQuantity = 0;
  12438. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12439. {
  12440. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12441. //Check Charging Profile Count
  12442. tmpProfileQuantity = 0;
  12443. while(fscanf(fp, "%s", dataLine) != EOF)
  12444. {
  12445. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12446. {
  12447. profileQuantity += 1;
  12448. tmpProfileQuantity += 1;
  12449. }
  12450. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12451. }
  12452. fclose(fp);
  12453. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12454. }
  12455. //Check TxDefaultProfile_%d.json
  12456. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12457. {
  12458. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12459. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12460. if((access(fnametemp,F_OK))!=-1)
  12461. {
  12462. fp = fopen(fnametemp, "r");
  12463. //Check Charging Profile Count
  12464. tmpProfileQuantity = 0;
  12465. while(fscanf(fp, "%s", dataLine) != EOF)
  12466. {
  12467. //DEBUG_INFO("word=%s\n",word);
  12468. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12469. {
  12470. profileQuantity += 1;
  12471. tmpProfileQuantity += 1;
  12472. }
  12473. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12474. }
  12475. fclose(fp);
  12476. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12477. }
  12478. }
  12479. //Check TxProfile_%d.json
  12480. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12481. {
  12482. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12483. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12484. if((access(fnametemp,F_OK))!=-1)
  12485. {
  12486. fp = fopen(fnametemp, "r");
  12487. //Check Charging Profile Count
  12488. tmpProfileQuantity = 0;
  12489. while(fscanf(fp, "%s", dataLine) != EOF)
  12490. {
  12491. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12492. {
  12493. profileQuantity += 1;
  12494. tmpProfileQuantity += 1;
  12495. }
  12496. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12497. }
  12498. fclose(fp);
  12499. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12500. }
  12501. }
  12502. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12503. if((profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData)) && (isReplaceable != TRUE))
  12504. {
  12505. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12506. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12507. goto end;
  12508. }
  12509. }
  12510. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12511. //**********************************Write to File********************************************************/
  12512. {
  12513. FILE *infile;
  12514. FILE *outfile;
  12515. char dataLine[4096]={0};
  12516. char filename[128]={0};
  12517. int chkChar=0;
  12518. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12519. {
  12520. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12521. {
  12522. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12523. }
  12524. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12525. {
  12526. if(SetProfileReq.ConnectorId==0)
  12527. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12528. else
  12529. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12530. }
  12531. else
  12532. {
  12533. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12534. }
  12535. infile = fopen (filename, "r");
  12536. outfile = fopen (tempfile, "w");
  12537. chkChar = fgetc(infile);
  12538. rewind(infile);
  12539. if(chkChar == EOF)
  12540. {
  12541. // Profile is empty
  12542. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12543. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12544. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12545. fclose(infile);
  12546. fclose(outfile);
  12547. sprintf(rmFileCmd,"rm -f %s",filename);
  12548. system(rmFileCmd);
  12549. rename(tempfile, filename);
  12550. }
  12551. else
  12552. {
  12553. // Profile is not empty
  12554. int ChargingProfileAdded = FALSE;
  12555. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12556. {
  12557. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12558. json_object *tmpChargingProfile;
  12559. tmpChargingProfile = json_tokener_parse(dataLine);
  12560. if(!is_error(SetChargingProfile))
  12561. {
  12562. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12563. {
  12564. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12565. {
  12566. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12567. }
  12568. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12569. {
  12570. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12571. }
  12572. }
  12573. }
  12574. json_object_put(tmpChargingProfile);
  12575. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12576. {
  12577. if(ChargingProfileAdded == FALSE)
  12578. {
  12579. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12580. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12581. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12582. ChargingProfileAdded = TRUE;
  12583. }
  12584. }
  12585. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12586. {
  12587. if(ChargingProfileAdded == FALSE)
  12588. {
  12589. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12590. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12591. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12592. ChargingProfileAdded = TRUE;
  12593. }
  12594. }
  12595. else
  12596. {
  12597. fprintf(outfile,"%s\n",dataLine);
  12598. if(ChargingProfileAdded == FALSE)
  12599. {
  12600. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12601. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12602. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12603. ChargingProfileAdded = TRUE;
  12604. }
  12605. }
  12606. } // end of while loop
  12607. fclose(infile);
  12608. fclose(outfile);
  12609. sprintf(rmFileCmd,"rm -f %s",filename);
  12610. system(rmFileCmd);
  12611. rename(tempfile, filename);
  12612. }
  12613. }
  12614. sleep(1);
  12615. result = TRUE;
  12616. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12617. }
  12618. end:
  12619. json_object_put(SetChargingProfile);
  12620. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12621. {
  12622. if(SetProfileReq.ConnectorId == 0)
  12623. {
  12624. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12625. {
  12626. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12627. }
  12628. }
  12629. else
  12630. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12631. }
  12632. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12633. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12634. return result;
  12635. }
  12636. int handleTriggerMessageRequest(char *uuid, char *payload)
  12637. {
  12638. mtrace();
  12639. int result = FAIL;
  12640. int connectorIdIsNULL = FALSE;
  12641. int connectorIdInt =0;
  12642. char sstr[40]={0},sstrtemp[100]={ 0 };
  12643. char requestedMessagestr[40]={0};
  12644. char comfirmstr[20]={0};
  12645. int c = 0;
  12646. char *loc;
  12647. DEBUG_INFO("handleTriggerMessageRequest\n");
  12648. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12649. strcpy(sstrtemp, stringtrimspace(payload));
  12650. c = 0;
  12651. loc = strstr(sstrtemp, "requestedMessage");
  12652. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12653. {
  12654. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12655. c++;
  12656. }
  12657. sstr[c] = '\0';
  12658. strcpy(requestedMessagestr, sstr);
  12659. c = 0;
  12660. loc = strstr(sstrtemp, "connectorId");
  12661. if(loc == NULL)
  12662. {
  12663. connectorIdIsNULL = TRUE;
  12664. }
  12665. else
  12666. {
  12667. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12668. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12669. {
  12670. sstr[c] = loc[strlen("connectorId")+2+c];
  12671. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12672. c++;
  12673. }
  12674. sstr[c] = '\0';
  12675. connectorIdInt = atoi(sstr);
  12676. }
  12677. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12678. {
  12679. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12680. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12681. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12682. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12683. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12684. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12685. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12686. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12687. {
  12688. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12689. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12690. return TRUE;
  12691. }
  12692. else
  12693. {
  12694. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12695. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12696. }
  12697. }
  12698. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12699. {
  12700. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12701. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12702. return TRUE;
  12703. }
  12704. //==========================
  12705. // Trigger message
  12706. //==========================
  12707. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12708. {
  12709. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12710. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12711. {
  12712. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12713. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12714. }
  12715. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12716. }
  12717. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12718. {
  12719. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12720. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12721. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12722. }
  12723. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12724. {
  12725. //sendBootNotificationRequest();
  12726. server_sign = FALSE;
  12727. }
  12728. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12729. {
  12730. refreshStartTimer(&clientTime.Heartbeat);
  12731. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12732. }
  12733. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12734. {
  12735. if(connectorIdIsNULL == FALSE)
  12736. {
  12737. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12738. {
  12739. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12740. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12741. }
  12742. }
  12743. else
  12744. {
  12745. for(int idx=0;idx< gunTotalNumber;idx++)
  12746. {
  12747. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12748. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12749. }
  12750. }
  12751. }
  12752. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12753. {
  12754. if(connectorIdIsNULL == FALSE)
  12755. {
  12756. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12757. {
  12758. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12759. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12760. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12761. }
  12762. }
  12763. else
  12764. {
  12765. for(int idx=0;idx< gunTotalNumber;idx++)
  12766. {
  12767. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12768. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12769. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12770. }
  12771. }
  12772. }
  12773. return result;
  12774. }
  12775. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12776. {
  12777. mtrace();
  12778. int result = FAIL;
  12779. int connectorIdInt =0;
  12780. char comfirmstr[20]={0};
  12781. int tempIndex = 0;
  12782. json_object *UnlockConnector;
  12783. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12784. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12785. UnlockConnector = json_tokener_parse(payload);
  12786. if(!is_error(UnlockConnector))
  12787. {
  12788. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12789. {
  12790. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12791. }
  12792. }
  12793. json_object_put(UnlockConnector);
  12794. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12795. if(gunTotalNumber == 0)
  12796. {
  12797. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12798. goto end;
  12799. }
  12800. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12801. {
  12802. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12803. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12804. goto end;
  12805. }
  12806. else
  12807. {
  12808. //check Transaction active
  12809. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12810. {
  12811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12812. {
  12813. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12814. }
  12815. else
  12816. {
  12817. tempIndex = connectorIdInt -1;
  12818. }
  12819. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12820. {
  12821. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12822. {
  12823. //stop Transaction
  12824. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12825. }
  12826. }
  12827. }
  12828. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12829. {
  12830. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12831. {
  12832. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12833. }
  12834. else
  12835. {
  12836. tempIndex = connectorIdInt -1;
  12837. }
  12838. for (int index = 0; index < CCS_QUANTITY; index++)
  12839. {
  12840. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12841. {
  12842. //stop Transaction
  12843. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12844. }
  12845. }
  12846. }
  12847. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12848. {
  12849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12850. {
  12851. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12852. }
  12853. else
  12854. {
  12855. tempIndex = connectorIdInt -1;
  12856. }
  12857. for (int index = 0; index < GB_QUANTITY; index++)
  12858. {
  12859. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12860. {
  12861. //stop Transaction
  12862. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12863. }
  12864. }
  12865. }
  12866. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12867. {
  12868. tempIndex = connectorIdInt -1;
  12869. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12870. {
  12871. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12872. {
  12873. //stop Transaction
  12874. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12875. }
  12876. }
  12877. }
  12878. else
  12879. {
  12880. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12881. {
  12882. tempIndex = 2;
  12883. }
  12884. else
  12885. {
  12886. tempIndex = connectorIdInt-1;
  12887. }
  12888. for (int index = 0; index < AC_QUANTITY; index++)
  12889. {
  12890. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12891. {
  12892. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12893. }
  12894. }
  12895. }
  12896. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12897. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12898. result = TRUE;
  12899. return result;
  12900. }
  12901. end:
  12902. //json_object_put(obj); --- remove temporally
  12903. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12904. return result;
  12905. }
  12906. static char UpdateFirmwarepayloadData[300]={0};
  12907. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12908. {
  12909. mtrace();
  12910. int result = FAIL;
  12911. pthread_t t;
  12912. sendUpdateFirmwareConfirmation(uuid);
  12913. memset(UpdateFirmwarepayloadData, 0, 300);
  12914. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12915. if(!interLock.isUpdateFirmwareGoing)
  12916. {
  12917. interLock.isUpdateFirmwareGoing = 1;
  12918. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12919. sleep(1);
  12920. }
  12921. else
  12922. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12923. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12924. return result;
  12925. }
  12926. void *UpdateFirmwareProcess(void *data)
  12927. {
  12928. pthread_detach(pthread_self());
  12929. mtrace();
  12930. int retriesInt =0, retryIntervalInt=0;
  12931. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12932. int port=0;
  12933. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12934. int isSuccess = 0;
  12935. char ftpbuf[1024];
  12936. char temp[1024];
  12937. char * pch;
  12938. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12939. json_object *UpdateFirmware;
  12940. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12941. if(!is_error(UpdateFirmware))
  12942. {
  12943. // Required data
  12944. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12945. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12946. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12947. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12948. // Optional data
  12949. if(json_object_object_get(UpdateFirmware, "retries"))
  12950. {
  12951. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12952. }
  12953. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12954. {
  12955. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12956. }
  12957. }
  12958. json_object_put(UpdateFirmware);
  12959. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12960. memset(path, 0, ARRAY_SIZE(path));
  12961. // Wait retrieveData
  12962. if(strlen(retrieveDatestr) > 10)
  12963. {
  12964. do
  12965. {
  12966. sleep(1);
  12967. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12968. }
  12969. // Ready to download
  12970. system("rm -f /mnt/*");
  12971. if(strncmp(locationstr,"http", 4) == 0)
  12972. {
  12973. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12974. sprintf(ftppath,"/%s", path);
  12975. DEBUG_INFO("locationstr: %s\n", locationstr);
  12976. DEBUG_INFO("protocol: %s\n",protocol);
  12977. DEBUG_INFO("host: %s\n",host);
  12978. DEBUG_INFO("path: %s\n",path);
  12979. DEBUG_INFO("ftppath: %s\n",ftppath);
  12980. int ftppathlen=strlen(ftppath);
  12981. int i=1;
  12982. char filenametemp[50];
  12983. while(i < ftppathlen)
  12984. {
  12985. int len=ftppathlen-i;
  12986. if(ftppath[len]== 47) // '/' ascll code: 47
  12987. {
  12988. DEBUG_INFO("compare '/' all right\n");
  12989. break;
  12990. }
  12991. i=i+1;
  12992. }
  12993. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12994. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12995. filenametemp[i+1] = 0;
  12996. do
  12997. {
  12998. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12999. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13000. sleep(1);
  13001. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13002. if(!isSuccess)
  13003. {
  13004. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13005. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13006. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13007. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13008. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13009. }
  13010. else
  13011. {
  13012. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13013. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13014. }
  13015. retriesInt--;
  13016. }while((isSuccess == 0)&&(retriesInt >= 0));
  13017. }
  13018. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13019. {
  13020. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13021. memset(temp, 0, ARRAY_SIZE(temp));
  13022. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13023. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13024. int ftppathlen=strlen(ftpbuf);
  13025. int i=1;
  13026. char filenametemp[50];
  13027. while(i < ftppathlen)
  13028. {
  13029. int len=ftppathlen-i;
  13030. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13031. {
  13032. DEBUG_INFO(" compare '/' all right\n");
  13033. break;
  13034. }
  13035. i=i+1;
  13036. }
  13037. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13038. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13039. filenametemp[i+1] = 0;
  13040. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13041. pch=strchr(temp,'@');
  13042. if(pch==NULL)
  13043. {
  13044. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13045. protocol, host, &port, path);
  13046. strcpy(user,"anonymous");
  13047. strcpy(password,"");
  13048. }
  13049. else
  13050. {
  13051. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13052. protocol, user, password, host, &port, path);
  13053. }
  13054. sscanf(host,"%[^/]%s",host1, path1);
  13055. sprintf(ftppath,"%s", path1);
  13056. //DEBUG_INFO("protocol =%s\n",protocol);
  13057. //DEBUG_INFO("user =%s\n",user);
  13058. //DEBUG_INFO("password =%s\n",password);
  13059. //DEBUG_INFO("host1 =%s\n",host1);
  13060. //DEBUG_INFO("port =%d\n",port);
  13061. //DEBUG_INFO("path1 =%s\n",path1);
  13062. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13063. //ftpFile(host, user, password, port, ftppath, fname);
  13064. //download firmware pthred
  13065. if(port == 0)
  13066. {
  13067. port = 21;
  13068. }
  13069. do
  13070. {
  13071. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13072. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13073. sleep(1);
  13074. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13075. if(!isSuccess)
  13076. {
  13077. //BulldogUtil.sleepMs(interval*1000);
  13078. DEBUG_INFO("Update firmware request and download file fail.\n");
  13079. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13080. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13081. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13082. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13083. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13084. }
  13085. else
  13086. {
  13087. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13088. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13089. }
  13090. retriesInt--;
  13091. }while((!isSuccess)&&(retriesInt >= 0));
  13092. }
  13093. else
  13094. {
  13095. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13096. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13097. sleep(1);
  13098. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13099. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13100. }
  13101. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13102. interLock.isUpdateFirmwareGoing = 0;
  13103. pthread_exit(NULL);
  13104. }
  13105. int handleCertificateSignedRequest(char *uuid, char *payload)
  13106. {
  13107. mtrace();
  13108. int result = PASS;
  13109. json_object *CertificateSigned;
  13110. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13111. CertificateSigned = json_tokener_parse(payload);
  13112. if(!is_error(CertificateSigned))
  13113. {
  13114. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13115. }
  13116. json_object_put(CertificateSigned);
  13117. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13118. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13119. fclose(fp);
  13120. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13121. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13122. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13123. sendCertificateSignedConfirmation(uuid);
  13124. return result;
  13125. }
  13126. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13127. {
  13128. mtrace();
  13129. int result = PASS;
  13130. json_object *DeleteCertificate;
  13131. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13132. DeleteCertificate = json_tokener_parse(payload);
  13133. if(!is_error(DeleteCertificate))
  13134. {
  13135. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13136. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13137. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13138. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13139. }
  13140. json_object_put(DeleteCertificate);
  13141. /*
  13142. * TODO: Delete certificateSigned process
  13143. */
  13144. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13145. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13146. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13147. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13148. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13149. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13150. sendDeleteCertificateConfirmation(uuid);
  13151. return result;
  13152. }
  13153. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13154. {
  13155. mtrace();
  13156. int result = PASS;
  13157. json_object *ExtendedTriggerMessage;
  13158. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13159. ExtendedTriggerMessage = json_tokener_parse(payload);
  13160. if(!is_error(ExtendedTriggerMessage))
  13161. {
  13162. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13163. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13164. {
  13165. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13166. }
  13167. else
  13168. {
  13169. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13170. }
  13171. }
  13172. json_object_put(ExtendedTriggerMessage);
  13173. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13174. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13175. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13176. {
  13177. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13178. }
  13179. else
  13180. {
  13181. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13182. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13183. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13184. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13185. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13186. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13187. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13188. {
  13189. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13190. }
  13191. else
  13192. {
  13193. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13194. }
  13195. }
  13196. sendExtendedTriggerMessageConfirmation(uuid);
  13197. //==========================
  13198. // Trigger message
  13199. //==========================
  13200. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13201. {
  13202. //sendBootNotificationRequest();
  13203. server_sign = FALSE;
  13204. }
  13205. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13206. {
  13207. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13208. }
  13209. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13210. {
  13211. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13212. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13213. {
  13214. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13215. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13216. }
  13217. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13218. }
  13219. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13220. {
  13221. refreshStartTimer(&clientTime.Heartbeat);
  13222. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13223. }
  13224. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13225. {
  13226. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13227. {
  13228. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13229. }
  13230. else
  13231. {
  13232. for(int idx=0;idx< gunTotalNumber;idx++)
  13233. {
  13234. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13235. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13236. }
  13237. }
  13238. }
  13239. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13240. {
  13241. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13242. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13243. {
  13244. 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\" &");
  13245. }
  13246. }
  13247. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13248. {
  13249. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13250. {
  13251. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13252. }
  13253. else
  13254. {
  13255. for(int idx=0;idx< gunTotalNumber;idx++)
  13256. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13257. }
  13258. }
  13259. return result;
  13260. }
  13261. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13262. {
  13263. mtrace();
  13264. int result = PASS;
  13265. json_object *GetInstalledCertificateIds;
  13266. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13267. GetInstalledCertificateIds = json_tokener_parse(payload);
  13268. if(!is_error(GetInstalledCertificateIds))
  13269. {
  13270. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13271. }
  13272. json_object_put(GetInstalledCertificateIds);
  13273. /*
  13274. * TODO: Return installed certificate process
  13275. */
  13276. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13277. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13278. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13279. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13280. sendGetInstalledCertificateIdsConfirmation(uuid);
  13281. return result;
  13282. }
  13283. int handleGetLogRequest(char *uuid, char *payload)
  13284. {
  13285. mtrace();
  13286. int result = PASS;
  13287. json_object *GetLog;
  13288. DEBUG_INFO("handleGetLogRequest...\n");
  13289. GetLog = json_tokener_parse(payload);
  13290. if(!is_error(GetLog))
  13291. {
  13292. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13293. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13294. if(json_object_object_get(GetLog, "retries") != NULL)
  13295. {
  13296. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13297. }
  13298. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13299. {
  13300. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13301. }
  13302. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13303. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13304. {
  13305. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13306. }
  13307. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13308. {
  13309. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13310. }
  13311. }
  13312. json_object_put(GetLog);
  13313. /*
  13314. * TODO: Upload log process
  13315. */
  13316. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13317. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13318. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13319. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13320. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13321. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13322. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13323. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13324. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13325. sendGetLogConfirmation(uuid);
  13326. return result;
  13327. }
  13328. int handleInstallCertificateRequest(char *uuid, char *payload)
  13329. {
  13330. mtrace();
  13331. int result = PASS;
  13332. json_object *InstallCertificate;
  13333. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13334. InstallCertificate = json_tokener_parse(payload);
  13335. if(!is_error(InstallCertificate))
  13336. {
  13337. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13338. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13339. /*
  13340. * TODO: Install certificate process
  13341. */
  13342. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13343. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13344. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13345. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13346. sendInstallCertificateConfirmation(uuid);
  13347. }
  13348. json_object_put(InstallCertificate);
  13349. return result;
  13350. }
  13351. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13352. {
  13353. mtrace();
  13354. int result = PASS;
  13355. json_object *SignedUpdateFirmware;
  13356. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13357. SignedUpdateFirmware = json_tokener_parse(payload);
  13358. if(!is_error(SignedUpdateFirmware))
  13359. {
  13360. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13361. {
  13362. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13363. }
  13364. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13365. {
  13366. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13367. }
  13368. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13369. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13370. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13371. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13372. {
  13373. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13374. }
  13375. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13376. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13377. }
  13378. json_object_put(SignedUpdateFirmware);
  13379. /*
  13380. * TODO: Upgrade firmware process
  13381. */
  13382. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13383. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13384. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13385. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13386. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13387. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13388. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13389. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13390. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13391. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13392. sendInstallCertificateConfirmation(uuid);
  13393. return result;
  13394. }
  13395. int handleUnknownRequest(char *uuid, char *payload)
  13396. {
  13397. mtrace();
  13398. int result = PASS;
  13399. DEBUG_INFO("handleUnknownRequest...\n");
  13400. sendUnknownConfirmation(uuid);
  13401. result = PASS;
  13402. return result;
  13403. }
  13404. //==========================================
  13405. // Handle server response routine
  13406. //==========================================
  13407. void handleAuthorizeResponse(char *payload, int gun_index)
  13408. {
  13409. mtrace();
  13410. char expiryDatestr[30]={0};
  13411. char parentIdTagstr[20]={0};
  13412. char statusstr[20]={0};
  13413. int expiryDateISNULL=FALSE;
  13414. int parentIdTagISNULL=FALSE;
  13415. DEBUG_INFO("handleAuthorizeResponse...\n");
  13416. json_object *Authorize;
  13417. Authorize = json_tokener_parse(payload);
  13418. if(!is_error(Authorize))
  13419. {
  13420. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13421. {
  13422. // Required data
  13423. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13424. // Optional data
  13425. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13426. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13427. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13428. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13429. }
  13430. }
  13431. json_object_put(Authorize);
  13432. if(expiryDateISNULL == FALSE)
  13433. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13434. if(parentIdTagISNULL == FALSE)
  13435. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13436. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13437. //Update idTag information to authorization cache if supproted
  13438. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13439. {
  13440. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13441. }
  13442. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13443. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13444. authorizeRetryTimes = 0;
  13445. }
  13446. void handleBootNotificationResponse(char *payload, int gun_index)
  13447. {
  13448. mtrace();
  13449. char statusStr[12]={0};
  13450. char currentTimeStr[30]={0};
  13451. int intervalInt = 0;
  13452. DEBUG_INFO("handleBootNotificationResponse...\n");
  13453. json_object *BootNotification;
  13454. BootNotification = json_tokener_parse(payload);
  13455. if(!is_error(BootNotification))
  13456. {
  13457. // Required data
  13458. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13459. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13460. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13461. }
  13462. json_object_put(BootNotification);
  13463. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13464. BootNotificationInterval = intervalInt;
  13465. //write back to ShmOCPP16Data->BootNotification
  13466. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13467. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13468. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13469. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13470. {
  13471. BootNotificationInterval = 0;
  13472. if((intervalInt == 0) || (intervalInt >= 10))
  13473. {
  13474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13475. HeartBeatWaitTime = intervalInt;
  13476. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13477. }
  13478. server_sign = TRUE;
  13479. server_pending =FALSE;
  13480. }
  13481. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13482. {
  13483. server_pending = TRUE;
  13484. }
  13485. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13486. srand(time(NULL));
  13487. refreshStartTimer(&clientTime.Heartbeat);
  13488. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13489. SetOcppConnStatus(TRUE);
  13490. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13491. }
  13492. void handleDataTransferResponse(char *payload, int gun_index)
  13493. {
  13494. json_object *DataTransfer = json_tokener_parse(payload);
  13495. if(!is_error(DataTransfer))
  13496. {
  13497. // Required data
  13498. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13499. // Optional data
  13500. if(json_object_object_get(DataTransfer, "data") != NULL)
  13501. {
  13502. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13503. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13504. if(!is_error(Data))
  13505. {
  13506. if(json_object_object_get(Data, "msgId") != NULL)
  13507. {
  13508. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13509. {
  13510. 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")));
  13511. }
  13512. }
  13513. }
  13514. json_object_put(Data);
  13515. }
  13516. }
  13517. json_object_put(DataTransfer);
  13518. }
  13519. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13520. {
  13521. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13522. //struct json_object *obj;
  13523. // obj = json_tokener_parse(payload);
  13524. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13525. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13526. //No fields are defined.
  13527. }
  13528. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13529. {
  13530. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13531. //struct json_object *obj;
  13532. // obj = json_tokener_parse(payload);
  13533. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13534. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13535. //No fields are defined.
  13536. }
  13537. void handleHeartbeatResponse(char *payload, int gun_index)
  13538. {
  13539. mtrace();
  13540. DEBUG_INFO("handleHeartbeatResponse...\n");
  13541. json_object *Heartbeat;
  13542. Heartbeat = json_tokener_parse(payload);
  13543. if(!is_error(Heartbeat))
  13544. {
  13545. // Required data
  13546. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13547. }
  13548. json_object_put(Heartbeat);
  13549. if(FirstHeartBeat == 0)
  13550. {
  13551. FirstHeartBeat = 1;
  13552. DEBUG_INFO("FirstHeartBeat \n");
  13553. }
  13554. HeartBeatWithNOResponse = 0;
  13555. refreshStartTimer(&clientTime.Heartbeat);
  13556. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13557. }
  13558. void handleMeterValuesResponse(char *payload, int gun_index)
  13559. {
  13560. mtrace();
  13561. DEBUG_INFO("handleMeterValuesResponse...\n");
  13562. isQueueSendable = 1;
  13563. }
  13564. void handleStartTransactionResponse(char *payload, int gun_index)
  13565. {
  13566. mtrace();
  13567. //int transactionIdInt = 0;
  13568. FILE *outfile;
  13569. char data[100]={0};
  13570. DEBUG_INFO("handleStartTransactionResponse...\n");
  13571. json_object *StartTransaction;
  13572. StartTransaction = json_tokener_parse(payload);
  13573. if(!is_error(StartTransaction))
  13574. {
  13575. // Required data
  13576. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13577. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13578. // Optional data
  13579. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13580. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13581. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13582. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13583. }
  13584. json_object_put(StartTransaction);
  13585. isQueueSendable = 1;
  13586. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13587. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13588. //-----------Start : write to the Queue TransactionId file -----------------//
  13589. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13590. {}
  13591. else
  13592. {
  13593. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13594. if(log == NULL)
  13595. {
  13596. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13597. return ;
  13598. }
  13599. else
  13600. {
  13601. fclose(log);
  13602. }
  13603. }
  13604. // open file for writing
  13605. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13606. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13607. {
  13608. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13609. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13610. fputs(data, outfile);
  13611. fclose (outfile);
  13612. }
  13613. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13614. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13615. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13616. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13617. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13618. }
  13619. void handleStatusNotificationResponse(char *payload, int gun_index)
  13620. {
  13621. mtrace();
  13622. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13623. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13624. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13625. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13626. }
  13627. void handleStopTransactionnResponse(char *payload, int gun_index)
  13628. {
  13629. mtrace();
  13630. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13631. json_object *StopTransaction;
  13632. StopTransaction = json_tokener_parse(payload);
  13633. if(!is_error(StopTransaction))
  13634. {
  13635. // Optional data
  13636. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13637. {
  13638. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13639. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13641. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13642. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13643. }
  13644. }
  13645. json_object_put(StopTransaction);
  13646. isQueueSendable = 1;
  13647. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13648. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13649. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13650. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13651. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13652. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13653. }
  13654. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13655. {
  13656. mtrace();
  13657. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13658. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13659. }
  13660. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13661. {
  13662. mtrace();
  13663. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13664. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13665. }
  13666. void handleSignCertificateResponse(char *payload, int gun_index)
  13667. {
  13668. mtrace();
  13669. DEBUG_INFO("handleSignCertificateResponse...\n");
  13670. json_object *SignCertificate;
  13671. SignCertificate = json_tokener_parse(payload);
  13672. if(!is_error(SignCertificate))
  13673. {
  13674. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13675. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13676. }
  13677. json_object_put(SignCertificate);
  13678. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13679. }
  13680. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13681. {
  13682. mtrace();
  13683. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13684. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13685. }
  13686. //==========================================
  13687. // Handle Error routine
  13688. //==========================================
  13689. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13690. {
  13691. mtrace();
  13692. #ifdef SystemLogMessage
  13693. DEBUG_INFO("errorCode: %s\n", errorCode);
  13694. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13695. DEBUG_INFO("errorDetails: %s\n", payload);
  13696. #endif
  13697. }
  13698. //===============================================
  13699. // Common routine
  13700. //===============================================
  13701. int initialConfigurationTable(void)
  13702. {
  13703. //clock_t start_t, end_t, total_t;
  13704. FILE *fp;
  13705. FILE *outfile;
  13706. char str[512]={0};
  13707. char sstr[256]={0};
  13708. int c = 0;
  13709. char *loc;
  13710. int confVersion = 13;
  13711. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13712. //start_t = clock();
  13713. //printf("Starting of the program, start_t = %ld\n", start_t);
  13714. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13715. // Check configuration file size is correct
  13716. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13717. {
  13718. struct stat st;
  13719. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13720. if(st.st_size < 3100)
  13721. {
  13722. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13723. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13724. }
  13725. }
  13726. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13727. {
  13728. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13729. if(outfile == NULL)
  13730. {
  13731. DEBUG_INFO("Error opening file\n");
  13732. return FALSE;
  13733. }
  13734. /*Core Profile*/
  13735. //AllowOfflineTxForUnknownId
  13736. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13740. //AuthorizationCacheEnabled
  13741. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13745. //AuthorizeRemoteTxRequests
  13746. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13750. //BlinkRepeat
  13751. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13755. //ClockAlignedDataInterval
  13756. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13760. //ConnectionTimeOut
  13761. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13765. //GetConfigurationMaxKeys
  13766. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13770. // HeartbeatInterval
  13771. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13775. // LightIntensity
  13776. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13780. // LocalAuthorizeOffline
  13781. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13785. // LocalPreAuthorize
  13786. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13790. // MaxEnergyOnInvalidId
  13791. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13795. // MeterValuesAlignedData
  13796. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13798. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13799. 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" );
  13800. else
  13801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13803. // MeterValuesAlignedDataMaxLength
  13804. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13808. else
  13809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13811. // MeterValuesSampledData
  13812. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13815. 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" );
  13816. else
  13817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13819. // MeterValuesSampledDataMaxLength
  13820. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13822. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13824. else
  13825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13827. // MeterValueSampleInterval
  13828. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13832. // MinimumStatusDuration
  13833. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13836. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13838. // NumberOfConnectors
  13839. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13841. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13842. {
  13843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13844. }
  13845. else
  13846. {
  13847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13848. }
  13849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13850. // ResetRetries
  13851. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13855. // ConnectorPhaseRotation
  13856. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13860. // ConnectorPhaseRotationMaxLength
  13861. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13865. // StopTransactionOnEVSideDisconnect
  13866. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13870. // StopTransactionOnInvalidId
  13871. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13875. // StopTxnAlignedData
  13876. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13880. // StopTxnAlignedDataMaxLength
  13881. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13885. // StopTxnSampledData
  13886. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13888. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13890. else
  13891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13893. // StopTxnSampledDataMaxLength
  13894. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13896. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13897. {
  13898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13899. }
  13900. else
  13901. {
  13902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13903. }
  13904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13905. // SupportedFeatureProfiles
  13906. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13910. // SupportedFeatureProfilesMaxLength
  13911. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13915. // TransactionMessageAttempts
  13916. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13919. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13921. // TransactionMessageRetryInterval
  13922. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13925. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13927. // UnlockConnectorOnEVSideDisconnect
  13928. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13932. // WebSocketPingInterval
  13933. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13937. // QueueOffLineMeterValues
  13938. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13942. // AuthorizationKey
  13943. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13947. // SecurityProfile
  13948. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13951. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13952. // DefaultPrice
  13953. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13957. // CustomDisplayCostAndPrice
  13958. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13962. // CustomIdleFeeAfterStop
  13963. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13967. // TimeOffset
  13968. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13972. // NextTimeOffsetTransitionDateTime
  13973. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13977. // TimeOffsetNextTransition
  13978. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13982. // SystemUptimeSec
  13983. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13987. // FreeVend
  13988. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13992. // FreeVendIdtag
  13993. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13997. // OcppServer
  13998. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14000. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14002. // MaintainServer
  14003. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14005. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14006. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14007. // StatusNotificationPeriodically
  14008. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14012. // StatusNotificationInterval
  14013. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14017. // Configuration Version
  14018. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14022. //* Local Auth List Management Profile*/
  14023. #if 0
  14024. //For OCTT Test Case
  14025. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14028. #endif
  14029. #if 1
  14030. //LocalAuthListEnabled
  14031. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14035. #endif
  14036. //LocalAuthListMaxLength
  14037. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14041. //SendLocalListMaxLength
  14042. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14046. //ReserveConnectorZeroSupported
  14047. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14051. //* Smart Charging Profile */
  14052. //ChargeProfileMaxStackLevel
  14053. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14057. // ChargingScheduleAllowedChargingRateUnit
  14058. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14062. // ChargingScheduleMaxPeriods
  14063. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14067. // ConnectorSwitch3to1PhaseSupported
  14068. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14072. // MaxChargingProfilesInstalled
  14073. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14077. fclose(outfile);
  14078. }
  14079. else
  14080. {
  14081. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14082. char keystr[60]={0};
  14083. char readonlystr[10]={0};
  14084. char valuestr[256]={0};
  14085. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14086. if(fp == NULL) {
  14087. DEBUG_INFO("Error opening file");
  14088. return FALSE;
  14089. }
  14090. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14091. {
  14092. //DEBUG_INFO("Get Configuration \n");
  14093. if(strlen(str) > 0)
  14094. {
  14095. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14096. //*************************key*********************************/
  14097. if(strstr(str, "key") != NULL)
  14098. {
  14099. loc = strstr(str, "key");
  14100. c = 0;
  14101. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14102. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14103. {
  14104. sstr[c] = loc[strlen("key")+3+c];
  14105. c++;
  14106. }
  14107. sstr[c] = '\0';
  14108. strcpy(keystr,sstr);
  14109. }
  14110. //*************************readonly*********************************/
  14111. if(strstr(str, "readonly") != NULL)
  14112. {
  14113. loc = strstr(str, "readonly");
  14114. c = 0;
  14115. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14116. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14117. {
  14118. sstr[c] = loc[strlen("readonly")+2+c];
  14119. c++;
  14120. }
  14121. sstr[c] = '\0';
  14122. strcpy(readonlystr,sstr);
  14123. }
  14124. //*************************value*********************************/
  14125. if(strstr(str, "value") != NULL)
  14126. {
  14127. loc = strstr(str, "value");
  14128. c = 0;
  14129. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14130. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14131. {
  14132. sstr[c] = loc[strlen("value")+3+c];
  14133. c++;
  14134. }
  14135. sstr[c] = '\0';
  14136. strcpy(valuestr,sstr);
  14137. }
  14138. // DEBUG_INFO("keystr=%s\n",keystr);
  14139. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14140. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14141. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14142. {
  14143. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14144. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14146. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14147. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14148. }
  14149. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14150. {
  14151. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14152. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14154. }
  14155. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14156. {
  14157. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14159. }
  14160. if(strcmp(keystr, "BlinkRepeat") == 0)
  14161. {
  14162. //Charger.BlinkRepeat = Integer.parseInt(value);
  14163. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14165. }
  14166. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14167. {
  14168. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14170. }
  14171. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14172. {
  14173. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14175. }
  14176. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14177. {
  14178. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14180. }
  14181. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14182. {
  14183. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14185. HeartBeatWaitTime = atoi(valuestr);
  14186. }
  14187. if(strcmp(keystr, "LightIntensity") == 0)
  14188. {
  14189. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14191. }
  14192. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14193. {
  14194. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14196. }
  14197. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14198. {
  14199. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14201. }
  14202. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14203. {
  14204. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14206. }
  14207. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14208. {
  14209. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14211. }
  14212. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14213. {
  14214. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14216. }
  14217. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14218. {
  14219. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14221. }
  14222. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14223. {
  14224. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14226. }
  14227. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14228. {
  14229. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14231. }
  14232. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14233. {
  14234. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14236. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14237. }
  14238. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14239. {
  14240. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14242. }
  14243. if(strcmp(keystr, "ResetRetries") == 0)
  14244. {
  14245. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14247. }
  14248. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14249. {
  14250. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14252. }
  14253. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14254. {
  14255. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14257. }
  14258. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14259. {
  14260. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14262. }
  14263. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14264. {
  14265. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14267. }
  14268. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14269. {
  14270. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14272. }
  14273. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14274. {
  14275. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14277. }
  14278. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14279. {
  14280. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14282. }
  14283. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14284. {
  14285. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14287. }
  14288. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14289. {
  14290. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14292. }
  14293. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14294. {
  14295. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14297. }
  14298. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14299. {
  14300. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14302. TransactionMessageAttemptsValue = atoi(valuestr);
  14303. }
  14304. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14305. {
  14306. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14308. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14309. }
  14310. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14311. {
  14312. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14314. }
  14315. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14316. {
  14317. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14319. }
  14320. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14321. {
  14322. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14324. }
  14325. if(strcmp(keystr, "AuthorizationKey") == 0)
  14326. {
  14327. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14328. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14330. }
  14331. if(strcmp(keystr, "SecurityProfile") == 0)
  14332. {
  14333. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14335. }
  14336. if(strcmp(keystr, "DefaultPrice") == 0)
  14337. {
  14338. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14340. }
  14341. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14342. {
  14343. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14345. }
  14346. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14347. {
  14348. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14349. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14350. }
  14351. if(strcmp(keystr, "TimeOffset") == 0)
  14352. {
  14353. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14355. }
  14356. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14357. {
  14358. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14360. }
  14361. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14362. {
  14363. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14365. }
  14366. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14367. {
  14368. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14370. }
  14371. if(strcmp(keystr, "FreeVend") == 0)
  14372. {
  14373. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14375. }
  14376. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14377. {
  14378. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14380. }
  14381. if(strcmp(keystr, "OcppServer") == 0)
  14382. {
  14383. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14384. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14385. }
  14386. if(strcmp(keystr, "MaintainServer") == 0)
  14387. {
  14388. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14389. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14390. }
  14391. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14392. {
  14393. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14395. }
  14396. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14397. {
  14398. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14400. }
  14401. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14402. {
  14403. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14405. }
  14406. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14407. {
  14408. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14410. }
  14411. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14412. {
  14413. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14414. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14415. }
  14416. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14417. {
  14418. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14420. }
  14421. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14422. {
  14423. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14425. }
  14426. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14427. {
  14428. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14430. }
  14431. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14432. {
  14433. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14435. }
  14436. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14437. {
  14438. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14440. }
  14441. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14442. {
  14443. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14445. }
  14446. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14447. {
  14448. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14450. }
  14451. }
  14452. }
  14453. fclose(fp);
  14454. }
  14455. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14456. {
  14457. return PASS;
  14458. }
  14459. else
  14460. {
  14461. return FAIL;
  14462. }
  14463. }
  14464. void StoreConfigurationTable(void)
  14465. {
  14466. FILE *outfile;
  14467. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14468. if(outfile == NULL)
  14469. {
  14470. DEBUG_INFO("Error opening file");
  14471. return ;
  14472. }
  14473. /*Core Profile*/
  14474. //AllowOfflineTxForUnknownId
  14475. /*
  14476. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14477. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14480. */
  14481. //DEBUG_INFO("data=%s\n",data);
  14482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14483. //AuthorizationCacheEnabled
  14484. /*
  14485. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14488. */
  14489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14490. //AuthorizeRemoteTxRequests
  14491. /*
  14492. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14495. */
  14496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14497. //BlinkRepeat
  14498. /*
  14499. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14502. */
  14503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14504. //ClockAlignedDataInterval
  14505. /*
  14506. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14509. */
  14510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14511. //ConnectionTimeOut
  14512. /*
  14513. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14516. */
  14517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14518. //GetConfigurationMaxKeys
  14519. /*
  14520. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14523. */
  14524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14525. // HeartbeatInterval
  14526. /*
  14527. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14530. */
  14531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14532. // LightIntensity
  14533. /*
  14534. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14537. */
  14538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14539. // LocalAuthorizeOffline
  14540. /*
  14541. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14544. */
  14545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14546. // LocalPreAuthorize
  14547. /*
  14548. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14551. */
  14552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14553. // MaxEnergyOnInvalidId
  14554. /*
  14555. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14558. */
  14559. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14561. // MeterValuesAlignedData
  14562. /*
  14563. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14566. */
  14567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14568. // MeterValuesAlignedDataMaxLength
  14569. /*
  14570. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14573. */
  14574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14575. // MeterValuesSampledData
  14576. /*
  14577. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14580. */
  14581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14582. // MeterValuesSampledDataMaxLength
  14583. /*
  14584. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14587. */
  14588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14589. // MeterValueSampleInterval
  14590. /*
  14591. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14594. */
  14595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14596. // MinimumStatusDuration
  14597. /*
  14598. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14601. */
  14602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14603. // NumberOfConnectors
  14604. /*
  14605. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14607. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14608. {
  14609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14610. }
  14611. else
  14612. {
  14613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14614. }
  14615. */
  14616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14617. // ResetRetries
  14618. /*
  14619. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14622. */
  14623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14624. // ConnectorPhaseRotation
  14625. /*
  14626. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14629. */
  14630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14631. // ConnectorPhaseRotationMaxLength
  14632. /*
  14633. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14636. */
  14637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14638. // StopTransactionOnEVSideDisconnect
  14639. /*
  14640. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14643. */
  14644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14645. // StopTransactionOnInvalidId
  14646. /*
  14647. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14650. */
  14651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14652. // StopTxnAlignedData
  14653. /*
  14654. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14657. */
  14658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14659. // StopTxnAlignedDataMaxLength
  14660. /*
  14661. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14664. */
  14665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14666. // StopTxnSampledData
  14667. /*
  14668. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14671. */
  14672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14673. // StopTxnSampledDataMaxLength
  14674. /*
  14675. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14678. */
  14679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14680. // SupportedFeatureProfiles
  14681. /*
  14682. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14685. */
  14686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14687. // SupportedFeatureProfilesMaxLength
  14688. /*
  14689. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14692. */
  14693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14694. // TransactionMessageAttempts
  14695. /*
  14696. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14699. */
  14700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14701. // TransactionMessageRetryInterval
  14702. /*
  14703. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14706. */
  14707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14708. // UnlockConnectorOnEVSideDisconnect
  14709. /*
  14710. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14713. */
  14714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14715. // WebSocketPingInterval
  14716. /*
  14717. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14720. */
  14721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14722. // QueueOffLineMeterValues
  14723. /*
  14724. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14727. */
  14728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14729. // AuthorizationKey
  14730. /*
  14731. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14734. */
  14735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14736. // SecurityProfile
  14737. /*
  14738. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14741. */
  14742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14743. // DefaultPrice
  14744. /*
  14745. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14748. */
  14749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14750. // CustomDisplayCostAndPrice
  14751. /*
  14752. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14755. */
  14756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14757. // CustomIdleFeeAfterStop
  14758. /*
  14759. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14762. */
  14763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14764. // TimeOffset
  14765. /*
  14766. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14769. */
  14770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14771. // NextTimeOffsetTransitionDateTime
  14772. /*
  14773. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14776. */
  14777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14778. // TimeOffsetNextTransition
  14779. /*
  14780. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14783. */
  14784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14785. // SystemUptimeSec
  14786. /*
  14787. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14790. */
  14791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14792. // FreeVend
  14793. /*
  14794. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14797. */
  14798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14799. // FreeVendIdtag
  14800. /*
  14801. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14804. */
  14805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14806. // OcppServer
  14807. /*
  14808. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14811. */
  14812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14813. // MaintainServer
  14814. /*
  14815. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14818. */
  14819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14820. // StatusNotificationPeriodically
  14821. /*
  14822. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14825. */
  14826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14827. // StatusNotificationInterval
  14828. /*
  14829. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14832. */
  14833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14834. // ConfigurationVersion
  14835. /*
  14836. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14839. */
  14840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14841. //* Local Auth List Management Profile*/
  14842. //LocalAuthListEnabled
  14843. /*
  14844. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14847. */
  14848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14849. //LocalAuthListMaxLength
  14850. /*
  14851. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14854. */
  14855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14856. //SendLocalListMaxLength
  14857. /*
  14858. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14861. */
  14862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14863. //ReserveConnectorZeroSupported
  14864. /*
  14865. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14868. */
  14869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14870. //* Smart Charging Profile */
  14871. //ChargeProfileMaxStackLevel
  14872. /*
  14873. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14876. */
  14877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14878. // ChargingScheduleAllowedChargingRateUnit
  14879. /*
  14880. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14883. */
  14884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14885. // ChargingScheduleMaxPeriods
  14886. /*
  14887. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14890. */
  14891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14892. // ConnectorSwitch3to1PhaseSupported
  14893. /*
  14894. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14897. */
  14898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14899. // MaxChargingProfilesInstalled
  14900. /*
  14901. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14904. */
  14905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14906. fclose(outfile);
  14907. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14908. }
  14909. void getKeyValue(char *keyReq)
  14910. {
  14911. int isEmpty = FALSE;
  14912. int isKnowKey = FALSE;
  14913. DEBUG_INFO("keyReq = %s\n", keyReq);
  14914. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14915. isEmpty = TRUE;
  14916. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14917. {
  14918. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14921. {
  14922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14923. }
  14924. else
  14925. {
  14926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14927. }
  14928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14929. isKnowKey = TRUE;
  14930. }
  14931. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14932. {
  14933. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14936. {
  14937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14938. }
  14939. else
  14940. {
  14941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14942. }
  14943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14944. isKnowKey = TRUE;
  14945. }
  14946. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14947. {
  14948. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14951. {
  14952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14953. }
  14954. else
  14955. {
  14956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14957. }
  14958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14959. isKnowKey = TRUE;
  14960. }
  14961. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14962. {
  14963. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14966. {
  14967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14968. }
  14969. else
  14970. {
  14971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14972. }
  14973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14974. isKnowKey = TRUE;
  14975. }
  14976. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14977. {
  14978. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14981. {
  14982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14983. }
  14984. else
  14985. {
  14986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14987. }
  14988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14989. isKnowKey = TRUE;
  14990. }
  14991. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14992. {
  14993. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14996. {
  14997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14998. }
  14999. else
  15000. {
  15001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15002. }
  15003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15004. isKnowKey = TRUE;
  15005. }
  15006. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15007. {
  15008. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15011. {
  15012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15013. }
  15014. else
  15015. {
  15016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15017. }
  15018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15019. isKnowKey = TRUE;
  15020. }
  15021. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15022. {
  15023. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15025. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15026. {
  15027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15028. }
  15029. else
  15030. {
  15031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15032. }
  15033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15034. isKnowKey = TRUE;
  15035. }
  15036. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15037. {
  15038. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15041. {
  15042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15043. }
  15044. else
  15045. {
  15046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15047. }
  15048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15049. isKnowKey = TRUE;
  15050. }
  15051. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15052. {
  15053. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15056. {
  15057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15058. }
  15059. else
  15060. {
  15061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15062. }
  15063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15064. isKnowKey = TRUE;
  15065. }
  15066. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15067. {
  15068. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15071. {
  15072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15073. }
  15074. else
  15075. {
  15076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15077. }
  15078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15079. isKnowKey = TRUE;
  15080. }
  15081. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15082. {
  15083. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15086. {
  15087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15088. }
  15089. else
  15090. {
  15091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15092. }
  15093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15094. isKnowKey = TRUE;
  15095. }
  15096. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15097. {
  15098. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15101. {
  15102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15103. }
  15104. else
  15105. {
  15106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15107. }
  15108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15109. isKnowKey = TRUE;
  15110. }
  15111. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15112. {
  15113. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15116. {
  15117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15118. }
  15119. else
  15120. {
  15121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15122. }
  15123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15124. isKnowKey = TRUE;
  15125. }
  15126. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15127. {
  15128. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15131. {
  15132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15133. }
  15134. else
  15135. {
  15136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15137. }
  15138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15139. isKnowKey = TRUE;
  15140. }
  15141. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15142. {
  15143. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15146. {
  15147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15148. }
  15149. else
  15150. {
  15151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15152. }
  15153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15154. isKnowKey = TRUE;
  15155. }
  15156. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15157. {
  15158. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15161. {
  15162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15163. }
  15164. else
  15165. {
  15166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15167. }
  15168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15169. isKnowKey = TRUE;
  15170. }
  15171. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15172. {
  15173. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15176. {
  15177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15178. }
  15179. else
  15180. {
  15181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15182. }
  15183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15184. isKnowKey = TRUE;
  15185. }
  15186. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15187. {
  15188. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15191. {
  15192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15193. }
  15194. else
  15195. {
  15196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15197. }
  15198. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15200. isKnowKey = TRUE;
  15201. }
  15202. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15203. {
  15204. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15206. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15207. {
  15208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15209. }
  15210. else
  15211. {
  15212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15213. }
  15214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15215. isKnowKey = TRUE;
  15216. }
  15217. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15218. {
  15219. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15221. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15222. {
  15223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15224. }
  15225. else
  15226. {
  15227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15228. }
  15229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15230. isKnowKey = TRUE;
  15231. }
  15232. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15233. {
  15234. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15236. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15237. {
  15238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15239. }
  15240. else
  15241. {
  15242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15243. }
  15244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15245. isKnowKey = TRUE;
  15246. }
  15247. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15248. {
  15249. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15251. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15252. {
  15253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15254. }
  15255. else
  15256. {
  15257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15258. }
  15259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15260. isKnowKey = TRUE;
  15261. }
  15262. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15263. {
  15264. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15266. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15267. {
  15268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15269. }
  15270. else
  15271. {
  15272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15273. }
  15274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15275. isKnowKey = TRUE;
  15276. }
  15277. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15278. {
  15279. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15281. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15282. {
  15283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15284. }
  15285. else
  15286. {
  15287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15288. }
  15289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15290. isKnowKey = TRUE;
  15291. }
  15292. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15293. {
  15294. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15296. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15297. {
  15298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15299. }
  15300. else
  15301. {
  15302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15303. }
  15304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15305. isKnowKey = TRUE;
  15306. }
  15307. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15308. {
  15309. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15312. {
  15313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15314. }
  15315. else
  15316. {
  15317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15318. }
  15319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15320. isKnowKey = TRUE;
  15321. }
  15322. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15323. {
  15324. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15327. {
  15328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15329. }
  15330. else
  15331. {
  15332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15333. }
  15334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15335. isKnowKey = TRUE;
  15336. }
  15337. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15338. {
  15339. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15341. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15342. {
  15343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15344. }
  15345. else
  15346. {
  15347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15348. }
  15349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15350. isKnowKey = TRUE;
  15351. }
  15352. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15353. {
  15354. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15356. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15357. {
  15358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15359. }
  15360. else
  15361. {
  15362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15363. }
  15364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15365. isKnowKey = TRUE;
  15366. }
  15367. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15368. {
  15369. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15372. {
  15373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15374. }
  15375. else
  15376. {
  15377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15378. }
  15379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15380. isKnowKey = TRUE;
  15381. }
  15382. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15383. {
  15384. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15386. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15387. {
  15388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15389. }
  15390. else
  15391. {
  15392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15393. }
  15394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15395. isKnowKey = TRUE;
  15396. }
  15397. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15398. {
  15399. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15401. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15402. {
  15403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15404. }
  15405. else
  15406. {
  15407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15408. }
  15409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15410. isKnowKey = TRUE;
  15411. }
  15412. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15413. {
  15414. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15417. {
  15418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15419. }
  15420. else
  15421. {
  15422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15423. }
  15424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15425. isKnowKey = TRUE;
  15426. }
  15427. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15428. {
  15429. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15432. {
  15433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15434. }
  15435. else
  15436. {
  15437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15438. }
  15439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15440. isKnowKey = TRUE;
  15441. }
  15442. /*
  15443. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15444. {
  15445. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15447. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15448. {
  15449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15450. }
  15451. else
  15452. {
  15453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15454. }
  15455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15456. isKnowKey = TRUE;
  15457. }*/
  15458. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15459. {
  15460. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15463. {
  15464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15465. }
  15466. else
  15467. {
  15468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15469. }
  15470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15471. isKnowKey = TRUE;
  15472. }
  15473. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15474. {
  15475. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15478. {
  15479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15480. }
  15481. else
  15482. {
  15483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15484. }
  15485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15486. isKnowKey = TRUE;
  15487. }
  15488. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15489. {
  15490. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15493. {
  15494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15495. }
  15496. else
  15497. {
  15498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15499. }
  15500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15501. isKnowKey = TRUE;
  15502. }
  15503. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15504. {
  15505. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15507. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15508. {
  15509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15510. }
  15511. else
  15512. {
  15513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15514. }
  15515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15516. isKnowKey = TRUE;
  15517. }
  15518. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15519. {
  15520. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15522. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15523. {
  15524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15525. }
  15526. else
  15527. {
  15528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15529. }
  15530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15531. isKnowKey = TRUE;
  15532. }
  15533. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15534. {
  15535. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15538. {
  15539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15540. }
  15541. else
  15542. {
  15543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15544. }
  15545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15546. isKnowKey = TRUE;
  15547. }
  15548. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15549. {
  15550. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15552. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15553. {
  15554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15555. }
  15556. else
  15557. {
  15558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15559. }
  15560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15561. isKnowKey = TRUE;
  15562. }
  15563. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15564. {
  15565. struct sysinfo s_info;
  15566. int error = sysinfo(&s_info);
  15567. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15569. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15570. {
  15571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15572. }
  15573. else
  15574. {
  15575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15576. }
  15577. if(error != 0)
  15578. {
  15579. DEBUG_WARN("System uptime get error: %d\n", error);
  15580. }
  15581. else
  15582. {
  15583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15584. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15585. }
  15586. isKnowKey = TRUE;
  15587. }
  15588. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15589. {
  15590. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15593. {
  15594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15595. }
  15596. else
  15597. {
  15598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15599. }
  15600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15601. isKnowKey = TRUE;
  15602. }
  15603. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15604. {
  15605. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15608. {
  15609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15610. }
  15611. else
  15612. {
  15613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15614. }
  15615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15616. isKnowKey = TRUE;
  15617. }
  15618. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15619. {
  15620. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15623. {
  15624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15625. }
  15626. else
  15627. {
  15628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15629. }
  15630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15631. isKnowKey = TRUE;
  15632. }
  15633. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15634. {
  15635. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15638. {
  15639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15640. }
  15641. else
  15642. {
  15643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15644. }
  15645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15646. isKnowKey = TRUE;
  15647. }
  15648. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15649. {
  15650. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15653. {
  15654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15655. }
  15656. else
  15657. {
  15658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15659. }
  15660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15661. isKnowKey = TRUE;
  15662. }
  15663. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15664. {
  15665. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15668. {
  15669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15670. }
  15671. else
  15672. {
  15673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15674. }
  15675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15676. isKnowKey = TRUE;
  15677. }
  15678. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15679. {
  15680. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15682. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15683. {
  15684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15685. }
  15686. else
  15687. {
  15688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15689. }
  15690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15691. isKnowKey = TRUE;
  15692. }
  15693. #if 1
  15694. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15695. {
  15696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15698. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15699. {
  15700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15701. }
  15702. else
  15703. {
  15704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15705. }
  15706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15707. isKnowKey = TRUE;
  15708. }
  15709. #endif
  15710. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15711. {
  15712. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15714. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15715. {
  15716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15717. }
  15718. else
  15719. {
  15720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15721. }
  15722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15723. isKnowKey = TRUE;
  15724. }
  15725. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15726. {
  15727. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15729. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15730. {
  15731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15732. }
  15733. else
  15734. {
  15735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15736. }
  15737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15738. isKnowKey = TRUE;
  15739. }
  15740. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15741. {
  15742. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15744. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15745. {
  15746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15747. }
  15748. else
  15749. {
  15750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15751. }
  15752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15753. isKnowKey = TRUE;
  15754. }
  15755. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15756. {
  15757. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15759. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15760. {
  15761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15762. }
  15763. else
  15764. {
  15765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15766. }
  15767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15768. isKnowKey = TRUE;
  15769. }
  15770. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15771. {
  15772. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15774. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15775. {
  15776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15777. }
  15778. else
  15779. {
  15780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15781. }
  15782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15783. isKnowKey = TRUE;
  15784. }
  15785. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15786. {
  15787. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15789. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15790. {
  15791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15792. }
  15793. else
  15794. {
  15795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15796. }
  15797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15798. isKnowKey = TRUE;
  15799. }
  15800. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15801. {
  15802. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15804. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15805. {
  15806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15807. }
  15808. else
  15809. {
  15810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15811. }
  15812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15813. isKnowKey = TRUE;
  15814. }
  15815. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15816. {
  15817. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15819. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15820. {
  15821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15822. }
  15823. else
  15824. {
  15825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15826. }
  15827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15828. isKnowKey = TRUE;
  15829. }
  15830. //=========================================================
  15831. if(!isEmpty && !isKnowKey)
  15832. {
  15833. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15834. strcpy(unknownkey[UnknownKeynum], keyReq);
  15835. UnknownKeynum = UnknownKeynum + 1;
  15836. }
  15837. }
  15838. void processUnkownKey(void)
  15839. {
  15840. DEBUG_INFO("processUnkownKey...\n");
  15841. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15842. for(int index=0; index < UnknownKeynum; index++)
  15843. {
  15844. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15845. {
  15846. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15847. }
  15848. }
  15849. }
  15850. int setKeyValue(char *key, char *value)
  15851. {
  15852. int isSuccess = NotSupported;
  15853. int check_ascii=0;
  15854. char str[501]={0};
  15855. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15856. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15857. {
  15858. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15860. {
  15861. strcpy(str, (const char*)value);
  15862. for(int i = 0; str[i]; i++){
  15863. str[i] = tolower(str[i]);
  15864. }
  15865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15866. isSuccess = ConfigurationStatus_Accepted;
  15867. }
  15868. else
  15869. {
  15870. isSuccess = ConfigurationStatus_Rejected;
  15871. }
  15872. }
  15873. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15874. {
  15875. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15877. {
  15878. strcpy(str, (const char*)value);
  15879. for(int i = 0; str[i]; i++){
  15880. str[i] = tolower(str[i]);
  15881. }
  15882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15883. isSuccess = ConfigurationStatus_Accepted;
  15884. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15885. }
  15886. else
  15887. {
  15888. isSuccess = ConfigurationStatus_Rejected;
  15889. }
  15890. }
  15891. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15892. {
  15893. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15894. {
  15895. strcpy(str, (const char*)value);
  15896. for(int i = 0; str[i]; i++)
  15897. {
  15898. str[i] = tolower(str[i]);
  15899. }
  15900. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15902. isSuccess = ConfigurationStatus_Accepted;
  15903. }
  15904. else
  15905. {
  15906. isSuccess = ConfigurationStatus_Rejected;
  15907. }
  15908. }
  15909. if(strcmp(key, "BlinkRepeat") == 0)
  15910. {
  15911. //Charger.BlinkRepeat = Integer.parseInt(value);
  15912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15913. {
  15914. check_ascii = value[0];
  15915. if( (check_ascii < 48) || (check_ascii > 57) )
  15916. {
  15917. isSuccess = ConfigurationStatus_Rejected;
  15918. }
  15919. else
  15920. {
  15921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15922. isSuccess = ConfigurationStatus_Accepted;
  15923. }
  15924. }
  15925. else
  15926. {
  15927. isSuccess = ConfigurationStatus_Rejected;
  15928. }
  15929. }
  15930. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15931. {
  15932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15933. {
  15934. check_ascii = value[0];
  15935. if( (check_ascii < 48) || (check_ascii > 57) )
  15936. {
  15937. isSuccess = ConfigurationStatus_Rejected;
  15938. }
  15939. else
  15940. {
  15941. if((atoi(value) == 0) || (atoi(value) >= 5))
  15942. {
  15943. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15945. isSuccess = ConfigurationStatus_Accepted;
  15946. }
  15947. else
  15948. isSuccess = ConfigurationStatus_Rejected;
  15949. }
  15950. }
  15951. else
  15952. {
  15953. isSuccess = ConfigurationStatus_Rejected;
  15954. }
  15955. }
  15956. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15957. {
  15958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15959. {
  15960. check_ascii = value[0];
  15961. if( (check_ascii < 48) || (check_ascii > 57) )
  15962. {
  15963. isSuccess = ConfigurationStatus_Rejected;
  15964. }
  15965. else
  15966. {
  15967. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15969. isSuccess = ConfigurationStatus_Accepted;
  15970. }
  15971. }
  15972. else
  15973. {
  15974. isSuccess = ConfigurationStatus_Rejected;
  15975. }
  15976. }
  15977. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15978. {
  15979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15980. {
  15981. check_ascii = value[0];
  15982. if( (check_ascii < 48) || (check_ascii > 57) )
  15983. {
  15984. isSuccess = ConfigurationStatus_Rejected;
  15985. }
  15986. else
  15987. {
  15988. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15990. isSuccess = ConfigurationStatus_Accepted;
  15991. }
  15992. }
  15993. else
  15994. {
  15995. isSuccess = ConfigurationStatus_Rejected;
  15996. }
  15997. }
  15998. if(strcmp(key, "HeartbeatInterval") == 0)
  15999. {
  16000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16001. {
  16002. check_ascii = value[0];
  16003. if( (check_ascii < 48) || (check_ascii > 57) )
  16004. {
  16005. isSuccess = ConfigurationStatus_Rejected;
  16006. }
  16007. else
  16008. {
  16009. if((atoi(value) == 0) || (atoi(value) >= 10))
  16010. {
  16011. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16013. HeartBeatWaitTime = atoi(value);
  16014. isSuccess = ConfigurationStatus_Accepted;
  16015. }
  16016. else
  16017. {
  16018. isSuccess = ConfigurationStatus_Rejected;
  16019. }
  16020. }
  16021. }
  16022. else
  16023. {
  16024. isSuccess = ConfigurationStatus_Rejected;
  16025. }
  16026. }
  16027. if(strcmp(key, "LightIntensity") == 0)
  16028. {
  16029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16030. {
  16031. check_ascii = value[0];
  16032. if( (check_ascii < 48) || (check_ascii > 57) )
  16033. {
  16034. isSuccess = ConfigurationStatus_Rejected;
  16035. }
  16036. else
  16037. {
  16038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16039. isSuccess = ConfigurationStatus_Accepted;
  16040. }
  16041. }
  16042. else
  16043. {
  16044. isSuccess = ConfigurationStatus_Rejected;
  16045. }
  16046. }
  16047. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16048. {
  16049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16050. {
  16051. strcpy(str, (const char*)value);
  16052. for(int i = 0; str[i]; i++)
  16053. {
  16054. str[i] = tolower(str[i]);
  16055. }
  16056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16057. isSuccess = ConfigurationStatus_Accepted;
  16058. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16059. }
  16060. else
  16061. {
  16062. isSuccess = ConfigurationStatus_Rejected;
  16063. }
  16064. }
  16065. if(strcmp(key, "LocalPreAuthorize") == 0)
  16066. {
  16067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16068. {
  16069. strcpy(str, (const char*)value);
  16070. for(int i = 0; str[i]; i++)
  16071. {
  16072. str[i] = tolower(str[i]);
  16073. }
  16074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16075. isSuccess = ConfigurationStatus_Accepted;
  16076. }
  16077. else
  16078. {
  16079. isSuccess = ConfigurationStatus_Rejected;
  16080. }
  16081. }
  16082. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16083. {
  16084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16085. {
  16086. check_ascii = value[0];
  16087. if( (check_ascii < 48) || (check_ascii > 57) )
  16088. {
  16089. isSuccess = ConfigurationStatus_Rejected;
  16090. }
  16091. else
  16092. {
  16093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16094. isSuccess = ConfigurationStatus_Accepted;
  16095. }
  16096. }
  16097. else
  16098. {
  16099. isSuccess = ConfigurationStatus_Rejected;
  16100. }
  16101. }
  16102. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16103. {
  16104. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16105. {
  16106. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16107. isSuccess = ConfigurationStatus_Accepted;
  16108. }
  16109. else
  16110. {
  16111. isSuccess = ConfigurationStatus_Rejected;
  16112. }
  16113. }
  16114. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16115. {
  16116. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16117. {
  16118. check_ascii = value[0];
  16119. if( (check_ascii < 48) || (check_ascii > 57) )
  16120. {
  16121. isSuccess = ConfigurationStatus_Rejected;
  16122. }
  16123. else
  16124. {
  16125. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16127. isSuccess = ConfigurationStatus_Accepted;
  16128. }
  16129. }
  16130. else
  16131. {
  16132. isSuccess = ConfigurationStatus_Rejected;
  16133. }
  16134. }
  16135. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16136. {
  16137. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16138. {
  16139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16140. isSuccess = ConfigurationStatus_Accepted;
  16141. }
  16142. else
  16143. {
  16144. isSuccess = ConfigurationStatus_Rejected;
  16145. }
  16146. }
  16147. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16148. {
  16149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16150. {
  16151. check_ascii = value[0];
  16152. if( (check_ascii < 48) || (check_ascii > 57) )
  16153. {
  16154. isSuccess = ConfigurationStatus_Rejected;
  16155. }
  16156. else
  16157. {
  16158. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16160. isSuccess = ConfigurationStatus_Accepted;
  16161. }
  16162. }
  16163. else
  16164. {
  16165. isSuccess = ConfigurationStatus_Rejected;
  16166. }
  16167. }
  16168. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16169. {
  16170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16171. {
  16172. check_ascii = value[0];
  16173. if( (check_ascii < 48) || (check_ascii > 57) )
  16174. {
  16175. isSuccess = ConfigurationStatus_Rejected;
  16176. }
  16177. else
  16178. {
  16179. if((atoi(value) == 0) || (atoi(value) >= 3))
  16180. {
  16181. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16183. isSuccess = ConfigurationStatus_Accepted;
  16184. }
  16185. else
  16186. {
  16187. isSuccess = ConfigurationStatus_Rejected;
  16188. }
  16189. }
  16190. }
  16191. else
  16192. {
  16193. isSuccess = ConfigurationStatus_Rejected;
  16194. }
  16195. }
  16196. if(strcmp(key, "MinimumStatusDuration") == 0)
  16197. {
  16198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16199. {
  16200. check_ascii = value[0];
  16201. if( (check_ascii < 48) || (check_ascii > 57) )
  16202. {
  16203. isSuccess = ConfigurationStatus_Rejected;
  16204. }
  16205. else
  16206. {
  16207. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16208. {
  16209. isSuccess = ConfigurationStatus_Rejected;
  16210. }
  16211. else
  16212. {
  16213. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16215. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16216. isSuccess = ConfigurationStatus_Accepted;
  16217. }
  16218. }
  16219. }
  16220. else
  16221. {
  16222. isSuccess = ConfigurationStatus_Rejected;
  16223. }
  16224. }
  16225. if(strcmp(key, "NumberOfConnectors") == 0)
  16226. {
  16227. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16228. {
  16229. check_ascii = value[0];
  16230. if( (check_ascii < 48) || (check_ascii > 57) )
  16231. {
  16232. isSuccess = ConfigurationStatus_Rejected;
  16233. }
  16234. else
  16235. {
  16236. //Charger.ResetRetries = Integer.parseInt(value);
  16237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16238. isSuccess = ConfigurationStatus_Accepted;
  16239. }
  16240. }
  16241. else
  16242. {
  16243. isSuccess = ConfigurationStatus_Rejected;
  16244. }
  16245. }
  16246. if(strcmp(key, "ResetRetries") == 0)
  16247. {
  16248. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16249. {
  16250. check_ascii = value[0];
  16251. if( (check_ascii < 48) || (check_ascii > 57) )
  16252. {
  16253. isSuccess = ConfigurationStatus_Rejected;
  16254. }
  16255. else
  16256. {
  16257. //Charger.ResetRetries = Integer.parseInt(value);
  16258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16259. isSuccess = ConfigurationStatus_Accepted;
  16260. }
  16261. }
  16262. else
  16263. {
  16264. isSuccess = ConfigurationStatus_Rejected;
  16265. }
  16266. }
  16267. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16268. {
  16269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16270. {
  16271. strcpy(str, (const char*)value);
  16272. for(int i = 0; str[i]; i++)
  16273. {
  16274. str[i] = tolower(str[i]);
  16275. }
  16276. if(strcmp(str, "notapplicable")== 0)
  16277. {
  16278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16279. isSuccess = ConfigurationStatus_Accepted;
  16280. }
  16281. else if(strcmp(str, "unknown")== 0)
  16282. {
  16283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16284. isSuccess = ConfigurationStatus_Accepted;
  16285. }
  16286. else if(strcmp(str, "rst")== 0)
  16287. {
  16288. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16289. isSuccess = ConfigurationStatus_Accepted;
  16290. }
  16291. else if(strcmp(str, "rts")== 0)
  16292. {
  16293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16294. isSuccess = ConfigurationStatus_Accepted;
  16295. }
  16296. else if(strcmp(str, "srt")== 0)
  16297. {
  16298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16299. isSuccess = ConfigurationStatus_Accepted;
  16300. }
  16301. else if(strcmp(str, "str")== 0)
  16302. {
  16303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16304. isSuccess = ConfigurationStatus_Accepted;
  16305. }
  16306. else if(strcmp(str, "trs")== 0)
  16307. {
  16308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16309. isSuccess = ConfigurationStatus_Accepted;
  16310. }
  16311. else if(strcmp(str, "tsr")== 0)
  16312. {
  16313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16314. isSuccess = ConfigurationStatus_Accepted;
  16315. }
  16316. else
  16317. {
  16318. isSuccess = ConfigurationStatus_Rejected;
  16319. }
  16320. }
  16321. else
  16322. {
  16323. isSuccess = ConfigurationStatus_Rejected;
  16324. }
  16325. }
  16326. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16327. {
  16328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16329. {
  16330. check_ascii = value[0];
  16331. if( (check_ascii < 48) || (check_ascii > 57) )
  16332. {
  16333. isSuccess = ConfigurationStatus_Rejected;
  16334. }
  16335. else
  16336. {
  16337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16338. isSuccess = ConfigurationStatus_Accepted;
  16339. }
  16340. }
  16341. else
  16342. {
  16343. isSuccess = ConfigurationStatus_Rejected;
  16344. }
  16345. }
  16346. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16347. {
  16348. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16349. {
  16350. strcpy(str, (const char*)value);
  16351. for(int i = 0; str[i]; i++)
  16352. {
  16353. str[i] = tolower(str[i]);
  16354. }
  16355. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16357. isSuccess = ConfigurationStatus_Accepted;
  16358. }
  16359. else
  16360. {
  16361. isSuccess = ConfigurationStatus_Rejected;
  16362. }
  16363. }
  16364. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16365. {
  16366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16367. {
  16368. strcpy(str, (const char*)value);
  16369. for(int i = 0; str[i]; i++)
  16370. {
  16371. str[i] = tolower(str[i]);
  16372. }
  16373. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16375. isSuccess = ConfigurationStatus_Accepted;
  16376. }
  16377. else
  16378. {
  16379. isSuccess = ConfigurationStatus_Rejected;
  16380. }
  16381. }
  16382. if(strcmp(key, "StopTxnAlignedData") == 0)
  16383. {
  16384. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16385. {
  16386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16387. isSuccess = ConfigurationStatus_Accepted;
  16388. }
  16389. else
  16390. {
  16391. isSuccess = ConfigurationStatus_Rejected;
  16392. }
  16393. }
  16394. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16395. {
  16396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16397. {
  16398. check_ascii = value[0];
  16399. if( (check_ascii < 48) || (check_ascii > 57) )
  16400. {
  16401. isSuccess = ConfigurationStatus_Rejected;
  16402. }
  16403. else
  16404. {
  16405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16406. isSuccess = ConfigurationStatus_Accepted;
  16407. }
  16408. }
  16409. else
  16410. {
  16411. isSuccess = ConfigurationStatus_Rejected;
  16412. }
  16413. }
  16414. if(strcmp(key, "StopTxnSampledData") == 0)
  16415. {
  16416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16417. {
  16418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16419. isSuccess = ConfigurationStatus_Accepted;
  16420. }
  16421. else
  16422. {
  16423. isSuccess = ConfigurationStatus_Rejected;
  16424. }
  16425. }
  16426. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16427. {
  16428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16429. {
  16430. check_ascii = value[0];
  16431. if( (check_ascii < 48) || (check_ascii > 57) )
  16432. {
  16433. isSuccess = ConfigurationStatus_Rejected;
  16434. }
  16435. else
  16436. {
  16437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16438. isSuccess = ConfigurationStatus_Accepted;
  16439. }
  16440. }
  16441. else
  16442. {
  16443. isSuccess = ConfigurationStatus_Rejected;
  16444. }
  16445. }
  16446. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16447. {
  16448. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16449. {
  16450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16451. isSuccess = ConfigurationStatus_Accepted;
  16452. }
  16453. else
  16454. {
  16455. isSuccess = ConfigurationStatus_Rejected;
  16456. }
  16457. }
  16458. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16459. {
  16460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16461. {
  16462. check_ascii = value[0];
  16463. if( (check_ascii < 48) || (check_ascii > 57) )
  16464. {
  16465. isSuccess = ConfigurationStatus_Rejected;
  16466. }
  16467. else
  16468. {
  16469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16470. isSuccess = ConfigurationStatus_Accepted;
  16471. }
  16472. }
  16473. else
  16474. {
  16475. isSuccess = ConfigurationStatus_Rejected;
  16476. }
  16477. }
  16478. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16479. {
  16480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16481. {
  16482. check_ascii = value[0];
  16483. if( (check_ascii < 48) || (check_ascii > 57) )
  16484. {
  16485. isSuccess = ConfigurationStatus_Rejected;
  16486. }
  16487. else
  16488. {
  16489. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16491. TransactionMessageAttemptsValue = atoi(value);
  16492. isSuccess = ConfigurationStatus_Accepted;
  16493. }
  16494. }
  16495. else
  16496. {
  16497. isSuccess = ConfigurationStatus_Rejected;
  16498. }
  16499. }
  16500. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16501. {
  16502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16503. {
  16504. check_ascii = value[0];
  16505. if( (check_ascii < 48) || (check_ascii > 57) )
  16506. {
  16507. isSuccess = ConfigurationStatus_Rejected;
  16508. }
  16509. else
  16510. {
  16511. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16512. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16513. TransactionMessageRetryIntervalValue = atoi(value);
  16514. isSuccess = ConfigurationStatus_Accepted;
  16515. }
  16516. }
  16517. else
  16518. {
  16519. isSuccess = ConfigurationStatus_Rejected;
  16520. }
  16521. }
  16522. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16523. {
  16524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16525. {
  16526. strcpy(str, (const char*)value);
  16527. for(int i = 0; str[i]; i++)
  16528. {
  16529. str[i] = tolower(str[i]);
  16530. }
  16531. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16533. isSuccess = ConfigurationStatus_Accepted;
  16534. }
  16535. else
  16536. {
  16537. isSuccess = ConfigurationStatus_Rejected;
  16538. }
  16539. }
  16540. if(strcmp(key, "WebSocketPingInterval") == 0)
  16541. {
  16542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16543. {
  16544. check_ascii = value[0];
  16545. if( (check_ascii < 48) || (check_ascii > 57) )
  16546. {
  16547. isSuccess = ConfigurationStatus_Rejected;
  16548. }
  16549. else
  16550. {
  16551. if((atoi(value) == 0) || (atoi(value) >= 10))
  16552. {
  16553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16554. isSuccess = ConfigurationStatus_Accepted;
  16555. }
  16556. else
  16557. isSuccess = ConfigurationStatus_Rejected;
  16558. }
  16559. }
  16560. else
  16561. {
  16562. isSuccess = ConfigurationStatus_Rejected;
  16563. }
  16564. }
  16565. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16566. {
  16567. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16568. {
  16569. strcpy(str, (const char*)value);
  16570. for(int i = 0; str[i]; i++)
  16571. {
  16572. str[i] = tolower(str[i]);
  16573. }
  16574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16575. isSuccess = ConfigurationStatus_Accepted;
  16576. }
  16577. else
  16578. {
  16579. isSuccess = ConfigurationStatus_Rejected;
  16580. }
  16581. }
  16582. if(strcmp(key, "AuthorizationKey") == 0)
  16583. {
  16584. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16585. {
  16586. strcpy(str, (const char*)value);
  16587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16588. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16589. isSuccess = ConfigurationStatus_Accepted;
  16590. }
  16591. else
  16592. {
  16593. isSuccess = ConfigurationStatus_Rejected;
  16594. }
  16595. }
  16596. if(strcmp(key, "SecurityProfile") == 0)
  16597. {
  16598. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16599. {
  16600. check_ascii = value[0];
  16601. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16602. {
  16603. isSuccess = ConfigurationStatus_Rejected;
  16604. }
  16605. else if(check_ascii == 0x33)
  16606. {
  16607. isSuccess = NotSupported;
  16608. }
  16609. else
  16610. {
  16611. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16612. {
  16613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16614. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16615. isSuccess = ConfigurationStatus_Accepted;
  16616. }
  16617. else
  16618. isSuccess = ConfigurationStatus_Rejected;
  16619. }
  16620. }
  16621. else
  16622. {
  16623. isSuccess = ConfigurationStatus_Rejected;
  16624. }
  16625. }
  16626. if(strcmp(key, "DefaultPrice") == 0)
  16627. {
  16628. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16629. {
  16630. strcpy(str, (const char*)value);
  16631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16632. isSuccess = ConfigurationStatus_Accepted;
  16633. }
  16634. else
  16635. {
  16636. isSuccess = ConfigurationStatus_Rejected;
  16637. }
  16638. }
  16639. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16640. {
  16641. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16642. {
  16643. strcpy(str, (const char*)value);
  16644. for(int i = 0; str[i]; i++)
  16645. {
  16646. str[i] = tolower(str[i]);
  16647. }
  16648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16649. isSuccess = ConfigurationStatus_Accepted;
  16650. }
  16651. else
  16652. {
  16653. isSuccess = ConfigurationStatus_Rejected;
  16654. }
  16655. }
  16656. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16657. {
  16658. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16659. {
  16660. strcpy(str, (const char*)value);
  16661. for(int i = 0; str[i]; i++)
  16662. {
  16663. str[i] = tolower(str[i]);
  16664. }
  16665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16666. isSuccess = ConfigurationStatus_Accepted;
  16667. }
  16668. else
  16669. {
  16670. isSuccess = ConfigurationStatus_Rejected;
  16671. }
  16672. }
  16673. if(strcmp(key, "TimeOffset") == 0)
  16674. {
  16675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16676. {
  16677. strcpy(str, (const char*)value);
  16678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16679. isSuccess = ConfigurationStatus_Accepted;
  16680. }
  16681. else
  16682. {
  16683. isSuccess = ConfigurationStatus_Rejected;
  16684. }
  16685. }
  16686. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16687. {
  16688. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16689. {
  16690. strcpy(str, (const char*)value);
  16691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16692. isSuccess = ConfigurationStatus_Accepted;
  16693. }
  16694. else
  16695. {
  16696. isSuccess = ConfigurationStatus_Rejected;
  16697. }
  16698. }
  16699. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  16700. {
  16701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16702. {
  16703. strcpy(str, (const char*)value);
  16704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  16705. isSuccess = ConfigurationStatus_Accepted;
  16706. }
  16707. else
  16708. {
  16709. isSuccess = ConfigurationStatus_Rejected;
  16710. }
  16711. }
  16712. if(strcmp(key, "SystemUptimeSec") == 0)
  16713. {
  16714. isSuccess = NotSupported;
  16715. }
  16716. if(strcmp(key, "FreeVend") == 0)
  16717. {
  16718. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16719. {
  16720. strcpy(str, (const char*)value);
  16721. for(int i = 0; str[i]; i++)
  16722. {
  16723. str[i] = tolower(str[i]);
  16724. }
  16725. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16727. isSuccess = ConfigurationStatus_Accepted;
  16728. }
  16729. else
  16730. {
  16731. isSuccess = ConfigurationStatus_Rejected;
  16732. }
  16733. }
  16734. if(strcmp(key, "FreeVendIdtag") == 0)
  16735. {
  16736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16737. {
  16738. strcpy(str, (const char*)value);
  16739. if(strlen(str) <= 20)
  16740. {
  16741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16742. isSuccess = ConfigurationStatus_Accepted;
  16743. }
  16744. else
  16745. {
  16746. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16747. isSuccess = ConfigurationStatus_Rejected;
  16748. }
  16749. }
  16750. else
  16751. {
  16752. isSuccess = ConfigurationStatus_Rejected;
  16753. }
  16754. }
  16755. if(strcmp(key, "OcppServer") == 0)
  16756. {
  16757. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16758. {
  16759. strcpy(str, (const char*)value);
  16760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16761. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16762. isSuccess = ConfigurationStatus_Accepted;
  16763. }
  16764. else
  16765. {
  16766. isSuccess = ConfigurationStatus_Rejected;
  16767. }
  16768. }
  16769. if(strcmp(key, "MaintainServer") == 0)
  16770. {
  16771. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16772. {
  16773. strcpy(str, (const char*)value);
  16774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16775. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16776. isSuccess = ConfigurationStatus_Accepted;
  16777. }
  16778. else
  16779. {
  16780. isSuccess = ConfigurationStatus_Rejected;
  16781. }
  16782. }
  16783. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16784. {
  16785. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16786. {
  16787. strcpy(str, (const char*)value);
  16788. for(int i = 0; str[i]; i++)
  16789. {
  16790. str[i] = tolower(str[i]);
  16791. }
  16792. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16793. isSuccess = ConfigurationStatus_Accepted;
  16794. }
  16795. else
  16796. {
  16797. isSuccess = ConfigurationStatus_Rejected;
  16798. }
  16799. }
  16800. if(strcmp(key, "StatusNotificationInterval") == 0)
  16801. {
  16802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16803. {
  16804. check_ascii = value[0];
  16805. if( (check_ascii < 48) || (check_ascii > 57) )
  16806. {
  16807. isSuccess = ConfigurationStatus_Rejected;
  16808. }
  16809. else
  16810. {
  16811. if((atoi(value) == 0) || (atoi(value) >= 10))
  16812. {
  16813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16814. isSuccess = ConfigurationStatus_Accepted;
  16815. }
  16816. else
  16817. isSuccess = ConfigurationStatus_Rejected;
  16818. }
  16819. }
  16820. else
  16821. {
  16822. isSuccess = ConfigurationStatus_Rejected;
  16823. }
  16824. }
  16825. #if 0
  16826. //For OCPP Test Case
  16827. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16828. {
  16829. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16830. {
  16831. strcpy(str, (const char*)value);
  16832. for(int i = 0; str[i]; i++)
  16833. {
  16834. str[i] = tolower(str[i]);
  16835. }
  16836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16837. isSuccess = ConfigurationStatus_Accepted;
  16838. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16839. }
  16840. else
  16841. {
  16842. isSuccess = ConfigurationStatus_Rejected;
  16843. }
  16844. }
  16845. #endif
  16846. #if 1
  16847. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16848. {
  16849. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16850. {
  16851. strcpy(str, (const char*)value);
  16852. for(int i = 0; str[i]; i++)
  16853. {
  16854. str[i] = tolower(str[i]);
  16855. }
  16856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16857. isSuccess = ConfigurationStatus_Accepted;
  16858. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16859. }
  16860. else
  16861. {
  16862. isSuccess = ConfigurationStatus_Rejected;
  16863. }
  16864. }
  16865. #endif
  16866. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16867. {
  16868. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16869. {
  16870. check_ascii = value[0];
  16871. if( (check_ascii < 48) || (check_ascii > 57) )
  16872. {
  16873. isSuccess = ConfigurationStatus_Rejected;
  16874. }
  16875. else
  16876. {
  16877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16878. isSuccess = ConfigurationStatus_Accepted;
  16879. }
  16880. }
  16881. else
  16882. {
  16883. isSuccess = ConfigurationStatus_Rejected;
  16884. }
  16885. }
  16886. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16887. {
  16888. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16889. {
  16890. check_ascii = value[0];
  16891. if( (check_ascii < 48) || (check_ascii > 57) )
  16892. {
  16893. isSuccess = ConfigurationStatus_Rejected;
  16894. }
  16895. else
  16896. {
  16897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16898. isSuccess = ConfigurationStatus_Accepted;
  16899. }
  16900. }
  16901. else
  16902. {
  16903. isSuccess = ConfigurationStatus_Rejected;
  16904. }
  16905. }
  16906. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16907. {
  16908. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16909. {
  16910. strcpy(str, (const char*)value);
  16911. for(int i = 0; str[i]; i++)
  16912. {
  16913. str[i] = tolower(str[i]);
  16914. }
  16915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16916. isSuccess = ConfigurationStatus_Accepted;
  16917. }
  16918. else
  16919. {
  16920. isSuccess = ConfigurationStatus_Rejected;
  16921. }
  16922. }
  16923. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16924. {
  16925. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16926. {
  16927. check_ascii = value[0];
  16928. if( (check_ascii < 48) || (check_ascii > 57) )
  16929. {
  16930. isSuccess = ConfigurationStatus_Rejected;
  16931. }
  16932. else
  16933. {
  16934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16935. isSuccess = ConfigurationStatus_Accepted;
  16936. }
  16937. }
  16938. else
  16939. {
  16940. isSuccess = ConfigurationStatus_Rejected;
  16941. }
  16942. }
  16943. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16944. {
  16945. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16946. {
  16947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16948. isSuccess = ConfigurationStatus_Accepted;
  16949. }
  16950. else
  16951. {
  16952. isSuccess = ConfigurationStatus_Rejected;
  16953. }
  16954. }
  16955. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16956. {
  16957. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16958. {
  16959. check_ascii = value[0];
  16960. if( (check_ascii < 48) || (check_ascii > 57) )
  16961. {
  16962. isSuccess = ConfigurationStatus_Rejected;
  16963. }
  16964. else
  16965. {
  16966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16967. isSuccess = ConfigurationStatus_Accepted;
  16968. }
  16969. }
  16970. else
  16971. {
  16972. isSuccess = ConfigurationStatus_Rejected;
  16973. }
  16974. }
  16975. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16976. {
  16977. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16978. {
  16979. strcpy(str, (const char*)value);
  16980. for(int i = 0; str[i]; i++)
  16981. {
  16982. str[i] = tolower(str[i]);
  16983. }
  16984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16985. isSuccess = ConfigurationStatus_Accepted;
  16986. }
  16987. else
  16988. {
  16989. isSuccess = ConfigurationStatus_Rejected;
  16990. }
  16991. }
  16992. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16993. {
  16994. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16995. {
  16996. check_ascii = value[0];
  16997. if( (check_ascii < 48) || (check_ascii > 57) )
  16998. {
  16999. isSuccess = ConfigurationStatus_Rejected;
  17000. }
  17001. else
  17002. {
  17003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17004. isSuccess = ConfigurationStatus_Accepted;
  17005. }
  17006. }
  17007. else
  17008. {
  17009. isSuccess = ConfigurationStatus_Rejected;
  17010. }
  17011. }
  17012. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17013. return isSuccess;
  17014. }
  17015. int TransactionMessageAttemptsGet(void)
  17016. {
  17017. return TransactionMessageAttemptsValue;
  17018. }
  17019. int FirstHeartBeatResponse(void)
  17020. {
  17021. return FirstHeartBeat;
  17022. }
  17023. int TransactionMessageRetryIntervalGet(void)
  17024. {
  17025. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17026. }
  17027. int ReadHttpStatus(int sock)
  17028. {
  17029. //char c;
  17030. char buff[1024]="",*ptr=buff+1;
  17031. int bytes_received, status;
  17032. DEBUG_INFO("Begin Response ..\n");
  17033. while((bytes_received = recv(sock, ptr, 1, 0))){
  17034. if(bytes_received==-1){
  17035. perror("ReadHttpStatus");
  17036. exit(1);
  17037. }
  17038. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17039. ptr++;
  17040. }
  17041. *ptr=0;
  17042. ptr=buff+1;
  17043. sscanf(ptr,"%*s %d ", &status);
  17044. DEBUG_INFO("%s\n",ptr);
  17045. DEBUG_INFO("status=%d\n",status);
  17046. DEBUG_INFO("End Response ..\n");
  17047. return (bytes_received>0)?status:0;
  17048. }
  17049. //the only filed that it parsed is 'Content-Length'
  17050. int ParseHeader(int sock)
  17051. {
  17052. //char c;
  17053. char buff[1024]="",*ptr=buff+4;
  17054. int bytes_received;
  17055. DEBUG_INFO("Begin HEADER ..\n");
  17056. while((bytes_received = recv(sock, ptr, 1, 0))){
  17057. if(bytes_received==-1){
  17058. perror("Parse Header");
  17059. exit(1);
  17060. }
  17061. if(
  17062. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17063. (ptr[-1]=='\r') && (*ptr=='\n' )
  17064. ) break;
  17065. ptr++;
  17066. }
  17067. *ptr=0;
  17068. ptr=buff+4;
  17069. //printf("%s",ptr);
  17070. if(bytes_received){
  17071. ptr=strstr(ptr,"Content-Length:");
  17072. if(ptr){
  17073. sscanf(ptr,"%*s %d",&bytes_received);
  17074. }else
  17075. bytes_received=-1; //unknown size
  17076. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17077. }
  17078. DEBUG_INFO("End HEADER ..\n");
  17079. return bytes_received ;
  17080. }
  17081. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17082. {
  17083. int result = TRUE;
  17084. char rmFileCmd[100]={0};
  17085. char FilePath[100]={0};
  17086. char ftpbuf[200];
  17087. int systemresult;
  17088. sprintf(FilePath,"/mnt/%s",filename);
  17089. system("ping 8.8.8.8 &");
  17090. if((access(FilePath,F_OK))!=-1)
  17091. {
  17092. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17093. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17094. system(rmFileCmd);
  17095. }
  17096. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17097. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17098. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17099. systemresult = system(ftpbuf);
  17100. if(systemresult != 0)
  17101. {
  17102. DEBUG_INFO("http DownLoad error!\n");
  17103. result = FALSE;
  17104. }
  17105. system("pkill ping");
  17106. return result;
  17107. }
  17108. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17109. {
  17110. int result = TRUE;
  17111. char rmFileCmd[100]={0};
  17112. char FilePath[100]={0};
  17113. char ftpbuf[200];
  17114. int systemresult;
  17115. sprintf(FilePath,"/mnt/%s",filename);
  17116. system("ping 8.8.8.8 &");
  17117. if((access(FilePath,F_OK))!=-1)
  17118. {
  17119. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17120. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17121. system(rmFileCmd);
  17122. }
  17123. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17124. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  17125. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17126. systemresult = system(ftpbuf);
  17127. if(systemresult != 0)
  17128. {
  17129. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17130. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17131. systemresult = system(ftpbuf);
  17132. if(systemresult != 0)
  17133. {
  17134. DEBUG_WARN("wget error!\n");
  17135. result = FALSE;
  17136. }
  17137. }
  17138. system("pkill ping");
  17139. return result;
  17140. }
  17141. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17142. {
  17143. char rmFileCmd[100]={0};
  17144. char FilePath[100]={0};
  17145. char buf[512];
  17146. int systemresult = 0;
  17147. //DEBUG_INFO("filename=%s\n",filename);
  17148. //DEBUG_INFO("url=%s\n",url);
  17149. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17150. if((access(FilePath,F_OK))!=-1)
  17151. {
  17152. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17153. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17154. system(rmFileCmd);
  17155. }
  17156. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17157. if(fp == NULL)
  17158. {
  17159. DEBUG_INFO("log is NULL\n");
  17160. return FALSE;
  17161. }
  17162. else
  17163. {
  17164. fprintf(fp, "%s\n", url);
  17165. fprintf(fp, "%s\n", filename);
  17166. fclose(fp);
  17167. }
  17168. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17169. if(phpFP == NULL)
  17170. {
  17171. DEBUG_INFO("PHP upload fail.\n");
  17172. return FALSE;
  17173. }
  17174. else
  17175. {
  17176. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17177. {
  17178. if(strstr(buf, "result") != NULL)
  17179. {
  17180. sscanf(buf, "result: %d", &systemresult);
  17181. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17182. }
  17183. }
  17184. pclose(phpFP);
  17185. }
  17186. if(systemresult != 1)
  17187. {
  17188. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17189. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17190. if(phpFP == NULL)
  17191. {
  17192. DEBUG_WARN("PHP PUT upload fail.\n");
  17193. return FALSE;
  17194. }
  17195. else
  17196. {
  17197. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17198. {
  17199. if(strstr(buf, "result") != NULL)
  17200. {
  17201. sscanf(buf, "result: %d", &systemresult);
  17202. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17203. }
  17204. }
  17205. pclose(phpFP);
  17206. }
  17207. }
  17208. return TRUE;
  17209. }
  17210. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17211. {
  17212. int result = FALSE;
  17213. char ftpbuf[200];
  17214. int systemresult;
  17215. /*
  17216. // Domaind name transfer to IP address
  17217. struct hostent* server;
  17218. char *IPbuffer;
  17219. server = gethostbyname(location);
  17220. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17221. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17222. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17223. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17224. systemresult = system(ftpbuf);
  17225. if(systemresult != 0)
  17226. {
  17227. DEBUG_INFO("ftpput error!\n");
  17228. }
  17229. else
  17230. {
  17231. result = TRUE;
  17232. DEBUG_INFO("ftpput OK!\n");
  17233. }
  17234. return result;
  17235. }
  17236. int GetOcppServerURL()
  17237. {
  17238. int result = FALSE;
  17239. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17240. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17241. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17242. struct yuarel url;
  17243. char urlStr[512];
  17244. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17245. {
  17246. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17247. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17248. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17249. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17250. if(yuarel_parse(&url, urlStr) != -1)
  17251. {
  17252. sprintf(OcppProtocol, "%s", url.scheme);
  17253. sprintf(OcppHost, "%s", url.host);
  17254. if(url.path == NULL)
  17255. OcppTempPath[0] = '\0';
  17256. else
  17257. {
  17258. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17259. {
  17260. sprintf(OcppTempPath, "%s/", url.path);
  17261. }
  17262. else
  17263. {
  17264. sprintf(OcppTempPath, "%s", url.path);
  17265. }
  17266. }
  17267. if(url.port == 0)
  17268. {
  17269. if(strcmp(OcppProtocol, "wss") == 0)
  17270. OcppPort = 443;
  17271. else
  17272. OcppPort = 80;
  17273. }
  17274. else
  17275. OcppPort = url.port;
  17276. result = TRUE;
  17277. }
  17278. }
  17279. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17280. {
  17281. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17282. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17283. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17284. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17285. if(yuarel_parse(&url, urlStr) != -1)
  17286. {
  17287. sprintf(OcppProtocol, "%s", url.scheme);
  17288. sprintf(OcppHost, "%s", url.host);
  17289. if(url.path == NULL)
  17290. OcppTempPath[0] = '\0';
  17291. else
  17292. sprintf(OcppTempPath, "%s", url.path);
  17293. if(url.port == 0)
  17294. {
  17295. if(strcmp(OcppProtocol, "wss") == 0)
  17296. OcppPort = 443;
  17297. else
  17298. OcppPort = 80;
  17299. }
  17300. else
  17301. OcppPort = url.port;
  17302. result = TRUE;
  17303. }
  17304. }
  17305. else
  17306. {
  17307. strcpy(OcppHost,"");
  17308. }
  17309. return result;
  17310. }
  17311. int GetOcppPath()
  17312. {
  17313. int result = FALSE;
  17314. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17315. {
  17316. if(OcppTempPath == NULL)
  17317. {
  17318. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17319. }
  17320. else
  17321. {
  17322. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17323. }
  17324. result = TRUE;
  17325. goto End;
  17326. }
  17327. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17328. {
  17329. if(OcppTempPath == NULL)
  17330. {
  17331. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17332. }
  17333. else
  17334. {
  17335. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17336. }
  17337. result = TRUE;
  17338. goto End;
  17339. }
  17340. else
  17341. {
  17342. strcpy(OcppPath,"");
  17343. }
  17344. End:
  17345. return result;
  17346. }
  17347. int GetOcppPort()
  17348. {
  17349. return OcppPort;
  17350. }
  17351. int GetOcppConnStatus(void)
  17352. {
  17353. return ShmOCPP16Data->OcppConnStatus;
  17354. }
  17355. void SetOcppConnStatus(uint8_t status)
  17356. {
  17357. ShmOCPP16Data->OcppConnStatus = status;
  17358. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17359. }
  17360. int GetHeartBeatWithNOResponse(void)
  17361. {
  17362. return HeartBeatWithNOResponse;
  17363. }
  17364. void SetHeartBeatWithNOResponse(void)
  17365. {
  17366. HeartBeatWithNOResponse = 0;
  17367. }
  17368. void GetStartTransactionIdTag(int gun_index)
  17369. {
  17370. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17371. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17372. }
  17373. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17374. {
  17375. char ch;
  17376. FILE *fptr1;
  17377. int temptransactionId;
  17378. char str[100]={0};
  17379. temptransactionId = 0;
  17380. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17381. {
  17382. DEBUG_INFO("IdTag is empty.\n");
  17383. return temptransactionId;
  17384. }
  17385. /*------ Read the file ----------------*/
  17386. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17387. if (!fptr1)
  17388. {
  17389. DEBUG_INFO("QueueTransactionId file open error.\n");
  17390. //printf(" File not found or unable to open the input file!!\n");
  17391. return temptransactionId;
  17392. }
  17393. ch=fgetc(fptr1);
  17394. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17395. rewind(fptr1);
  17396. if(ch!=EOF)
  17397. {
  17398. // printf("%c",ch);
  17399. while (fgets(str, 100, fptr1) != NULL)
  17400. {
  17401. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17402. if(str[0]=='\0')
  17403. {
  17404. break;
  17405. }
  17406. char *revbuf[8] = {0}; // Variable store string split
  17407. int num = 0;// Quantity after string split
  17408. DEBUG_INFO("Transaction queue data= %s\n", str);
  17409. splitstring(str,",",revbuf,&num); // String split
  17410. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17411. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17412. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17413. DEBUG_INFO("------------------------------\n");
  17414. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17415. {
  17416. if(isStopTransaction)
  17417. {
  17418. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17419. {
  17420. temptransactionId = atoi(revbuf[2]);
  17421. //break;
  17422. }
  17423. }
  17424. else
  17425. {
  17426. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17427. {
  17428. temptransactionId = atoi(revbuf[2]);
  17429. //break;
  17430. }
  17431. }
  17432. }
  17433. }
  17434. }
  17435. else
  17436. DEBUG_INFO("EOF\n");
  17437. fclose(fptr1);
  17438. /*------- End of reading ---------------*/
  17439. return temptransactionId;
  17440. }
  17441. void SetTransactionIdZero(int transactionId)
  17442. {
  17443. char ch;
  17444. FILE *fptr1, *fptr2;
  17445. int temptransactionId = 0;
  17446. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17447. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17448. if (!fptr1)
  17449. {
  17450. //printf(" File not found or unable to open the input file!!\n");
  17451. return ;
  17452. }
  17453. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17454. if (!fptr2)
  17455. {
  17456. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17457. fclose(fptr1);
  17458. return ;
  17459. }
  17460. ch=fgetc(fptr1);
  17461. rewind(fptr1);
  17462. if(ch!=EOF)
  17463. {
  17464. // copy all contents to the temporary file except the specific line
  17465. while (fgets(str, 100, fptr1) != NULL)
  17466. {
  17467. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17468. if(str[0]=='\0')
  17469. {
  17470. break;
  17471. }
  17472. char *revbuf[8] = {0};
  17473. int num = 0;
  17474. strcpy(strtemp, str);
  17475. splitstring(str,",",revbuf,&num);
  17476. if(revbuf[2][0] != '\0')
  17477. {
  17478. temptransactionId = atoi(revbuf[2]);
  17479. if(transactionId != temptransactionId)
  17480. {
  17481. fprintf(fptr2, "%s\n", strtemp);
  17482. }
  17483. }
  17484. }
  17485. }
  17486. fclose(fptr1);
  17487. fclose(fptr2);
  17488. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17489. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17490. /*------ Read the file ----------------*/
  17491. }
  17492. int InternetDisconnect(void)
  17493. {
  17494. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17495. }
  17496. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17497. void storeTempStopTransaction(int gun_index)
  17498. {
  17499. char guid[37]={0};
  17500. int tempIndex = 0;
  17501. char TempStopTransaction[256];
  17502. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17503. DEBUG_INFO("storeTempStopTransaction...\n");
  17504. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17505. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17506. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17507. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17508. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17509. {
  17510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17511. {
  17512. tempIndex = ((gun_index==2) ? 1: 0);
  17513. }
  17514. else
  17515. {
  17516. tempIndex = gun_index;
  17517. }
  17518. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17519. {
  17520. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17521. {
  17522. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17523. }
  17524. }// END OF CHAdeMO_QUANTITY
  17525. }
  17526. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17527. {
  17528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17529. {
  17530. tempIndex = ((gun_index==2) ? 1: 0);
  17531. }
  17532. else
  17533. {
  17534. tempIndex = gun_index;
  17535. }
  17536. for (int index = 0; index < CCS_QUANTITY; index++)
  17537. {
  17538. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17539. {
  17540. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17541. }
  17542. }// END OF CCS_QUANTITY
  17543. }
  17544. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17545. {
  17546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17547. {
  17548. tempIndex = ((gun_index==2) ? 1: 0);
  17549. }
  17550. else
  17551. {
  17552. tempIndex = gun_index;
  17553. }
  17554. for (int index = 0; index < GB_QUANTITY; index++)
  17555. {
  17556. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17557. {
  17558. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17559. }
  17560. }// END OF GB_QUANTITY
  17561. }
  17562. else if(gunType[gun_index] == GUN_TYPE_DO)
  17563. {
  17564. tempIndex = gun_index;
  17565. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17566. {
  17567. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17568. {
  17569. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17570. }
  17571. }
  17572. }
  17573. else
  17574. {
  17575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17576. {
  17577. tempIndex = 2;
  17578. }
  17579. else
  17580. {
  17581. tempIndex = gun_index;
  17582. }
  17583. for (int index = 0; index < AC_QUANTITY; index++)
  17584. {
  17585. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17586. {
  17587. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17588. }
  17589. }// END OF AC_QUANTITY
  17590. }
  17591. //Stop Transaction Time
  17592. struct timeval tmnow;
  17593. struct tm *tm;
  17594. char buf[28];//, usec_buf[6];
  17595. gettimeofday(&tmnow, NULL);
  17596. time_t t;
  17597. t = time(NULL);
  17598. /*UTC time and date*/
  17599. tm = gmtime(&t);
  17600. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17602. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17604. random_uuid(guid);
  17605. /***********************************transactionData******************************************************/
  17606. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17608. //=================================
  17609. //1. Transaction_Begin
  17610. //=================================
  17611. //============================== Energy.Active.Import.Interval ===========================================
  17612. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17613. {
  17614. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17617. 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*/]);
  17618. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17619. 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))
  17620. {
  17621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17622. }
  17623. else
  17624. {
  17625. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17626. }
  17627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17629. }
  17630. //=================================
  17631. //2. Transaction_End
  17632. //=================================
  17633. //2.1====================================== Current.Import L1 ==============================================
  17634. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17635. {
  17636. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17637. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17638. {
  17639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17640. {
  17641. tempIndex = ((gun_index==2) ? 1: 0);
  17642. }
  17643. else
  17644. {
  17645. tempIndex = gun_index;
  17646. }
  17647. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17648. {
  17649. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17650. {
  17651. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17652. }
  17653. }// End of for CHAdeMO_QUANTITY
  17654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17655. }
  17656. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17657. {
  17658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17659. {
  17660. tempIndex = ((gun_index==2) ? 1: 0);
  17661. }
  17662. else
  17663. {
  17664. tempIndex = gun_index;
  17665. }
  17666. for (int index = 0; index < CCS_QUANTITY; index++)
  17667. {
  17668. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17669. {
  17670. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17671. }
  17672. }// End of for CCS_QUANTITY
  17673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17674. }
  17675. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17676. {
  17677. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17678. {
  17679. tempIndex = ((gun_index==2) ? 1: 0);
  17680. }
  17681. else
  17682. {
  17683. tempIndex = gun_index;
  17684. }
  17685. for (int index = 0; index < GB_QUANTITY; index++)
  17686. {
  17687. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17688. {
  17689. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17690. }
  17691. }// End of for GB_QUANTITY
  17692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17693. }
  17694. else if(gunType[gun_index] == GUN_TYPE_DO)
  17695. {
  17696. tempIndex = gun_index;
  17697. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17698. {
  17699. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17700. {
  17701. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17702. }
  17703. }
  17704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17705. }
  17706. else
  17707. {
  17708. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17709. {
  17710. tempIndex = 2;
  17711. }
  17712. else
  17713. {
  17714. tempIndex = gun_index;
  17715. }
  17716. for (int index = 0; index < AC_QUANTITY; index++)
  17717. {
  17718. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17719. {
  17720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17721. }
  17722. }// End of for AC_QUANTITY
  17723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17724. }
  17725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17728. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17731. }
  17732. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17733. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17734. {
  17735. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17736. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17737. {
  17738. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17739. {
  17740. tempIndex = ((gun_index==2) ? 1: 0);
  17741. }
  17742. else
  17743. {
  17744. tempIndex = gun_index;
  17745. }
  17746. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17747. {
  17748. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17749. {
  17750. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17751. }
  17752. }// END OF CHAdeMO_QUANTITY
  17753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17754. }
  17755. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17756. {
  17757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17758. {
  17759. tempIndex = ((gun_index==2) ? 1: 0);
  17760. }
  17761. else
  17762. {
  17763. tempIndex = gun_index;
  17764. }
  17765. for (int index = 0; index < CCS_QUANTITY; index++)
  17766. {
  17767. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17768. {
  17769. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17770. }
  17771. }// END OF CCS_QUANTITY
  17772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17773. }
  17774. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17775. {
  17776. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17777. {
  17778. tempIndex = ((gun_index==2) ? 1: 0);
  17779. }
  17780. else
  17781. {
  17782. tempIndex = gun_index;
  17783. }
  17784. for (int index = 0; index < GB_QUANTITY; index++)
  17785. {
  17786. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17787. {
  17788. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17789. }
  17790. }// END OF GB_QUANTITY
  17791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17792. }
  17793. else if(gunType[gun_index] == GUN_TYPE_DO)
  17794. {
  17795. tempIndex = gun_index;
  17796. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17797. {
  17798. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17799. {
  17800. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17801. }
  17802. }
  17803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17804. }
  17805. else
  17806. {
  17807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17808. {
  17809. tempIndex = 2;
  17810. }
  17811. else
  17812. {
  17813. tempIndex = gun_index;
  17814. }
  17815. for (int index = 0; index < AC_QUANTITY; index++)
  17816. {
  17817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17818. {
  17819. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17820. }
  17821. }// END OF AC_QUANTITY
  17822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17823. }
  17824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17827. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17830. }
  17831. //2.3====================================== Power.Active.Import =========================================
  17832. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17833. {
  17834. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17835. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17836. {
  17837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17838. {
  17839. tempIndex = ((gun_index==2) ? 1: 0);
  17840. }
  17841. else
  17842. {
  17843. tempIndex = gun_index;
  17844. }
  17845. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17846. {
  17847. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17848. {
  17849. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17850. }
  17851. } // End for CHAdeMO_QUANTITY
  17852. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17853. }
  17854. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17855. {
  17856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17857. {
  17858. tempIndex = ((gun_index==2) ? 1: 0);
  17859. }
  17860. else
  17861. {
  17862. tempIndex = gun_index;
  17863. }
  17864. for (int index = 0; index < CCS_QUANTITY; index++)
  17865. {
  17866. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17867. {
  17868. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17869. }
  17870. } // END for CCS_QUANTITY
  17871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17872. }
  17873. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17874. {
  17875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17876. {
  17877. tempIndex = ((gun_index==2) ? 1: 0);
  17878. }
  17879. else
  17880. {
  17881. tempIndex = gun_index;
  17882. }
  17883. for (int index = 0; index < GB_QUANTITY; index++)
  17884. {
  17885. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17886. {
  17887. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17888. }
  17889. }// END for GB_QUANTITY
  17890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17891. }
  17892. else if(gunType[gun_index] == GUN_TYPE_DO)
  17893. {
  17894. tempIndex = gun_index;
  17895. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17896. {
  17897. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17898. {
  17899. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17900. }
  17901. }
  17902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17903. }
  17904. else
  17905. {
  17906. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17907. {
  17908. tempIndex = 2;
  17909. }
  17910. else
  17911. {
  17912. tempIndex = gun_index;
  17913. }
  17914. for (int index = 0; index < AC_QUANTITY; index++)
  17915. {
  17916. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17917. {
  17918. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17919. }
  17920. } // END for AC_QUANTITY
  17921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17922. }
  17923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17924. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17926. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17929. }
  17930. //2.4====================================== Voltage L1 ====================================================
  17931. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17932. {
  17933. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17934. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17935. {
  17936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17937. {
  17938. tempIndex = ((gun_index==2) ? 1: 0);
  17939. }
  17940. else
  17941. {
  17942. tempIndex = gun_index;
  17943. }
  17944. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17945. {
  17946. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17947. {
  17948. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17949. }
  17950. } // END OF FOR CHAdeMO_QUANTITY
  17951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17952. }
  17953. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17954. {
  17955. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17956. {
  17957. tempIndex = ((gun_index==2) ? 1: 0);
  17958. }
  17959. else
  17960. {
  17961. tempIndex = gun_index;
  17962. }
  17963. for (int index = 0; index < CCS_QUANTITY; index++)
  17964. {
  17965. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17966. {
  17967. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17968. }
  17969. } // END OF FOR CCS_QUANTITY
  17970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17971. }
  17972. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17973. {
  17974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17975. {
  17976. tempIndex = ((gun_index==2) ? 1: 0);
  17977. }
  17978. else
  17979. {
  17980. tempIndex = gun_index;
  17981. }
  17982. for (int index = 0; index < GB_QUANTITY; index++)
  17983. {
  17984. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17985. {
  17986. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17987. }
  17988. } // END OF FOR GB_QUANTITY
  17989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17990. }
  17991. else if(gunType[gun_index] == GUN_TYPE_DO)
  17992. {
  17993. tempIndex = gun_index;
  17994. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17995. {
  17996. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17997. {
  17998. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17999. }
  18000. }
  18001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18002. }
  18003. else
  18004. {
  18005. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18006. {
  18007. tempIndex = 2;
  18008. }
  18009. else
  18010. {
  18011. tempIndex = gun_index;
  18012. }
  18013. for (int index = 0; index < AC_QUANTITY; index++)
  18014. {
  18015. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18016. {
  18017. 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
  18018. }
  18019. } // END OF FOR AC_QUANTITY
  18020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18021. }
  18022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18025. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18028. }
  18029. //2.5============================================== End SoC =========================================================
  18030. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18031. {
  18032. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18033. 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))
  18034. {
  18035. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18036. {
  18037. tempIndex = ((gun_index==2) ? 1: 0);
  18038. }
  18039. else
  18040. {
  18041. tempIndex = gun_index;
  18042. }
  18043. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18044. {
  18045. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18046. {
  18047. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18048. {
  18049. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18050. }
  18051. }
  18052. }
  18053. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18054. {
  18055. for (int index = 0; index < CCS_QUANTITY; index++)
  18056. {
  18057. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18058. {
  18059. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18060. }
  18061. }
  18062. }
  18063. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18064. {
  18065. for (int index = 0; index < GB_QUANTITY; index++)
  18066. {
  18067. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18068. {
  18069. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18070. }
  18071. }
  18072. }
  18073. else if(gunType[gun_index] == GUN_TYPE_DO)
  18074. {
  18075. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18076. {
  18077. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18078. {
  18079. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18080. }
  18081. }
  18082. }
  18083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18089. } // END FOR DC CASE
  18090. }
  18091. //2.6====================================== Current.Import L2 ==============================================
  18092. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18093. {
  18094. // AC 3 phase L2 current
  18095. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18096. {
  18097. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18098. {
  18099. tempIndex = 2;
  18100. }
  18101. else
  18102. {
  18103. tempIndex = gun_index;
  18104. }
  18105. for (int index = 0; index < AC_QUANTITY; index++)
  18106. {
  18107. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18108. {
  18109. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18110. }
  18111. }// End of for AC_QUANTITY
  18112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18113. }
  18114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18119. }
  18120. //2.7====================================== Current.Import L3 ==============================================
  18121. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18122. {
  18123. // AC 3 phase L3 current
  18124. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18125. {
  18126. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18127. {
  18128. tempIndex = 2;
  18129. }
  18130. else
  18131. {
  18132. tempIndex = gun_index;
  18133. }
  18134. for (int index = 0; index < AC_QUANTITY; index++)
  18135. {
  18136. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18137. {
  18138. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18139. }
  18140. }// End of for AC_QUANTITY
  18141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18142. }
  18143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18148. }
  18149. //2.9====================================== Voltage L2 ====================================================
  18150. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18151. {
  18152. // AC 3 phase L2 volatge
  18153. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18154. {
  18155. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18156. {
  18157. tempIndex = 2;
  18158. }
  18159. else
  18160. {
  18161. tempIndex = gun_index;
  18162. }
  18163. for (int index = 0; index < AC_QUANTITY; index++)
  18164. {
  18165. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18166. {
  18167. 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
  18168. }
  18169. } // END OF FOR AC_QUANTITY
  18170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18171. }
  18172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18177. }
  18178. //2.10====================================== Voltage L3 ====================================================
  18179. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18180. {
  18181. // AC 3 phase L3 volatge
  18182. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18183. {
  18184. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18185. {
  18186. tempIndex = 2;
  18187. }
  18188. else
  18189. {
  18190. tempIndex = gun_index;
  18191. }
  18192. for (int index = 0; index < AC_QUANTITY; index++)
  18193. {
  18194. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18195. {
  18196. 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
  18197. }
  18198. } // END OF FOR AC_QUANTITY
  18199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18200. }
  18201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18206. }
  18207. //====================== Start SoC ================================
  18208. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18209. {
  18210. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18211. 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))
  18212. {
  18213. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18214. {
  18215. tempIndex = ((gun_index==2) ? 1: 0);
  18216. }
  18217. else
  18218. {
  18219. tempIndex = gun_index;
  18220. }
  18221. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18222. {
  18223. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18224. {
  18225. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18226. {
  18227. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18228. }
  18229. }
  18230. }
  18231. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18232. {
  18233. for (int index = 0; index < CCS_QUANTITY; index++)
  18234. {
  18235. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18236. {
  18237. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18238. }
  18239. }
  18240. }
  18241. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18242. {
  18243. for (int index = 0; index < GB_QUANTITY; index++)
  18244. {
  18245. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18246. {
  18247. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18248. }
  18249. }
  18250. }
  18251. else if(gunType[gun_index] == GUN_TYPE_DO)
  18252. {
  18253. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18254. {
  18255. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18256. {
  18257. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18258. }
  18259. }
  18260. }
  18261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18267. } // END FOR DC CASE
  18268. }
  18269. //======================================== Message create ==============================================
  18270. json_object *StopTransaction = json_object_new_object();
  18271. json_object *transactionDatas = json_object_new_array();
  18272. json_object *sampledValues = json_object_new_array();
  18273. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18274. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18275. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18276. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18277. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18278. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18279. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18280. {
  18281. json_object *transactionData = json_object_new_object();
  18282. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18283. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18284. {
  18285. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18286. {
  18287. json_object *sampledValue = json_object_new_object();
  18288. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18289. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18290. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18291. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18292. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18293. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18294. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18295. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18296. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18297. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18298. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18299. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18300. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18301. json_object_array_add(sampledValues, sampledValue);
  18302. }
  18303. }
  18304. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18305. json_object_array_add(transactionDatas, transactionData);
  18306. }
  18307. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18308. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18309. ,MESSAGE_TYPE_CALL
  18310. ,guid
  18311. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18312. json_object_put(StopTransaction);
  18313. // Check File "TempStopTransaction" Exist
  18314. if((access(TempStopTransaction,F_OK))!=-1)
  18315. {
  18316. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18317. fclose(fopen(TempStopTransaction, "w"));
  18318. }
  18319. else
  18320. {
  18321. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18322. FILE *log = fopen(TempStopTransaction, "w+");
  18323. if(log == NULL)
  18324. {
  18325. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18326. return ;
  18327. }
  18328. else
  18329. {
  18330. fclose(log);
  18331. }
  18332. }
  18333. //Add TempStopTransaction | Update TempStopTransaction
  18334. // open file for writing
  18335. FILE *outfile;
  18336. outfile = fopen (TempStopTransaction, "a");
  18337. //DEBUG_INFO("data = %s\n", queuedata);
  18338. fputs(queuedata, outfile);
  18339. fputs("\n", outfile);
  18340. fclose (outfile);
  18341. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18342. OCPP_updatePeriodEnergy(gun_index);
  18343. }
  18344. void checkTempStopTransaction(int gun_index)
  18345. {
  18346. FILE *fptr1;
  18347. char ch;
  18348. char str[QUEUE_MESSAGE_LENGTH]={0};
  18349. char guid[37]={0};
  18350. char tempdata[65]={0};
  18351. char connectorStr[2]={0};
  18352. char TempStopTransaction[256];
  18353. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18354. fptr1 = fopen(TempStopTransaction, "r");
  18355. //TempStopTransaction格式: 槍號,StopTransaction封包
  18356. if (!fptr1)
  18357. {
  18358. //printf(" File not found or unable to open the input file!!\n");
  18359. return ;
  18360. }
  18361. ch=fgetc(fptr1);
  18362. //printf(" Now the content of the file %s is : \n",fname);
  18363. rewind(fptr1);
  18364. if(ch!=EOF)
  18365. {
  18366. // copy all contents to the temporary file except the specific line
  18367. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18368. {
  18369. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18370. if(str[0]=='\0')
  18371. {
  18372. break;
  18373. }
  18374. //TempStopTransaction格式: 槍號,StopTransaction封包
  18375. strncpy(connectorStr, str, 1);
  18376. if(atoi(connectorStr) != (gun_index+1))
  18377. {
  18378. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18379. fclose(fptr1);
  18380. return ;
  18381. }
  18382. //random_uuid(guid);
  18383. strncpy(guid, str+6, 36); //copy guid
  18384. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18385. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18386. {
  18387. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18388. }
  18389. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18390. OCPP_insert_transaction_msg(NO, str);
  18391. memset(str,0,ARRAY_SIZE(str));
  18392. }
  18393. }
  18394. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18395. fclose(fptr1);
  18396. remove(TempStopTransaction); // remove the original file
  18397. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18398. }
  18399. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18400. {
  18401. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18402. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18403. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18404. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18405. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18406. }
  18407. int GetWebSocketPingInterval(void)
  18408. {
  18409. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18410. }
  18411. int GetServerSign(void)
  18412. {
  18413. return server_sign;
  18414. }
  18415. uint8_t GetOcppSecurityProfile()
  18416. {
  18417. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18418. }
  18419. void GetOcppChargerBoxId(uint8_t *data)
  18420. {
  18421. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18422. }
  18423. void GetOcppSecurityPassword(uint8_t *data)
  18424. {
  18425. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18426. }
  18427. void SetOcppVersion(uint8_t *version)
  18428. {
  18429. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18430. DEBUG_INFO("ocpp version: %s\n", version);
  18431. if(strstr((char*)version, "ocpp1.6") != NULL)
  18432. {
  18433. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18434. }
  18435. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18436. {
  18437. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18438. system("pkill OcppBackend");
  18439. }
  18440. }
  18441. void SetServerSign(int value)
  18442. {
  18443. server_sign = value;
  18444. }
  18445. int GetBootNotificationInterval(void)
  18446. {
  18447. return BootNotificationInterval;
  18448. }
  18449. int GetInternetConn(void)
  18450. {
  18451. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18452. }
  18453. int GetBackendConnectionTimeout(void)
  18454. {
  18455. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18456. }
  18457. int isConnectorInitMode(int gun_index)
  18458. {
  18459. int tempIndex = 0;
  18460. int result = TRUE;
  18461. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18462. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18463. {
  18464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18465. {
  18466. tempIndex = ((gun_index==2) ? 1: 0);
  18467. }
  18468. else
  18469. {
  18470. tempIndex = gun_index;
  18471. }
  18472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18473. {
  18474. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18475. {
  18476. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18477. } //end of the same index
  18478. }//end of for CHAdeMO_QUANTITY
  18479. }
  18480. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18481. {
  18482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18483. {
  18484. tempIndex = ((gun_index==2) ? 1: 0);
  18485. }
  18486. else
  18487. {
  18488. tempIndex = gun_index;
  18489. }
  18490. for (int index = 0; index < CCS_QUANTITY; index++)
  18491. {
  18492. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18493. {
  18494. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18495. } //end of the same index
  18496. } // end of for CCS_QUANTITY
  18497. }
  18498. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18499. {
  18500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18501. {
  18502. tempIndex = ((gun_index==2) ? 1: 0);
  18503. }
  18504. else
  18505. {
  18506. tempIndex = gun_index;
  18507. }
  18508. for (int index = 0; index < GB_QUANTITY; index++)
  18509. {
  18510. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18511. {
  18512. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18513. } //end of the same index
  18514. } // end of for GB_QUANTITY
  18515. }
  18516. else if(gunType[gun_index] == GUN_TYPE_DO)
  18517. {
  18518. tempIndex = gun_index;
  18519. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18520. {
  18521. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18522. {
  18523. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18524. } //end of the same index
  18525. }
  18526. }
  18527. else
  18528. {
  18529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18530. {
  18531. tempIndex = 2;
  18532. }
  18533. else
  18534. {
  18535. tempIndex = gun_index;
  18536. }
  18537. for (int index = 0; index < AC_QUANTITY; index++)
  18538. {
  18539. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18540. {
  18541. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18542. }//end of the same index
  18543. }//end of for AC_QUANTITY
  18544. }
  18545. return result;
  18546. }
  18547. void refreshProcDogTimer()
  18548. {
  18549. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18550. }
  18551. void InitialSystemValue(void)
  18552. {
  18553. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18554. locallistVersion=0;
  18555. BootNotificationInterval = 0;
  18556. authorizeRetryTimes = 0;
  18557. GunStatusInterval = 10;
  18558. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18559. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18560. //Hear Beat
  18561. HeartBeatWithNOResponse = 0;
  18562. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18563. FirstHeartBeat = 0;
  18564. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18565. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18566. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18567. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18568. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18569. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18570. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18571. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18572. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18573. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18574. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18575. //Status && ConnectorPlugIn Setting
  18576. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18577. {
  18578. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18579. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18580. }
  18581. for (int index = 0; index < CCS_QUANTITY; index++)
  18582. {
  18583. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18584. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18585. }
  18586. for (int index = 0; index < GB_QUANTITY; index++)
  18587. {
  18588. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18589. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18590. }
  18591. for (int index = 0; index < AC_QUANTITY; index++)
  18592. {
  18593. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18594. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18595. }
  18596. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18597. {
  18598. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18599. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18600. }
  18601. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18602. {
  18603. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18604. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18605. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18606. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18607. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18608. }
  18609. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18610. refreshStartTimer(&clientTime.Heartbeat);
  18611. sleep(1);
  18612. }
  18613. void LWS_Send(char *str)
  18614. {
  18615. //=====================================================
  18616. // Check InternetConn 0: disconnected, 1: connected
  18617. //====================================================
  18618. if(GetOcppConnStatus() == 0)
  18619. {
  18620. DEBUG_INFO("offline now !!!\n");
  18621. return;
  18622. }
  18623. // Only disable isWebsocketSendable operation initiated by charger
  18624. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18625. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18626. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18627. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18628. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18629. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18630. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18631. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18632. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18633. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18634. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18635. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18636. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18637. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18638. {
  18639. isWebsocketSendable = 0;
  18640. }
  18641. pthread_mutex_lock(&lock_send);
  18642. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18643. sprintf((char *)SendBuffer, "%s", str);
  18644. SendBufLen = strlen(str);
  18645. pthread_mutex_unlock(&lock_send);
  18646. lws_callback_on_writable(wsi_client);
  18647. //lws_service(context, 0);
  18648. //sleep(1);
  18649. }
  18650. void LWS_SendNow(char *str)
  18651. {
  18652. //=====================================================
  18653. // Check InternetConn 0: disconnected, 1: connected
  18654. //====================================================
  18655. if(GetOcppConnStatus() == 0)
  18656. {
  18657. DEBUG_INFO("offline now !!!\n");
  18658. return;
  18659. }
  18660. // Only disable isWebsocketSendable operation initiated by charger
  18661. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18662. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18663. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18664. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18665. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18666. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18667. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18668. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18669. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18670. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18671. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18672. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18673. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18674. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18675. {
  18676. isWebsocketSendable = 0;
  18677. }
  18678. pthread_mutex_lock(&lock_send);
  18679. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18680. sprintf((char *)SendBuffer, "%s", str);
  18681. SendBufLen = strlen(str);
  18682. pthread_mutex_unlock(&lock_send);
  18683. lws_callback_on_writable(wsi_client);
  18684. lws_service(context, 0);
  18685. //sleep(1);
  18686. }