MessageHandler.c 968 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  54. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //=============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. extern sqlite3 *db;
  90. int TransactionMessageAttemptsGet(void);
  91. int TransactionMessageRetryIntervalGet(void);
  92. int GetOcppConnStatus(void);
  93. void SetOcppConnStatus(uint8_t status);
  94. int setKeyValue(char *key, char *value);
  95. void OCPP_get_TableAuthlocalAllData(void);
  96. void processUnkownKey(void);
  97. struct InterLock
  98. {
  99. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  100. unsigned char isGetDiagnosticGoing:1;
  101. unsigned char isUpdateFirmwareGoing:1;
  102. }interLock;
  103. struct ClientTime
  104. {
  105. struct timespec Heartbeat;
  106. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  107. struct timespec StartTransaction;
  108. struct timespec StopTransaction;
  109. struct timespec MeterValues[CONNECTOR_QUANTITY];
  110. struct timespec RemoteStartWait;
  111. struct timespec TcciQueryDeduct;
  112. }clientTime;
  113. typedef union
  114. {
  115. //Operations Initiated by Central System
  116. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  117. struct
  118. {
  119. //CsMsgValue[0]
  120. unsigned char StatusNotificationReq:1; //bit 0,
  121. unsigned char StatusNotificationConf:1; //bit 1,
  122. unsigned char TriggerMeterValue:1; //bit 2,
  123. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  124. unsigned char isOnCharging:1; //bit 4,
  125. unsigned char :3; //bit5~7
  126. }bits[CONNECTOR_QUANTITY];
  127. }CpinitiateMsg;
  128. CpinitiateMsg cpinitateMsg;
  129. //GetConfiguration Array
  130. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  133. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  134. #if 0
  135. static char *ChargePointErrorCodeStr[] = {
  136. MACROSTR(ConnectorLockFailure),
  137. MACROSTR(EVCommunicationError),
  138. MACROSTR(GroundFailure),
  139. MACROSTR(HighTemperature),
  140. MACROSTR(InternalError),
  141. MACROSTR(LocalListConflict),
  142. MACROSTR(NoError),
  143. MACROSTR(OtherError),
  144. MACROSTR(OverCurrentFailure),
  145. MACROSTR(OverVoltage),
  146. MACROSTR(PowerMeterFailure),
  147. MACROSTR(PowerSwitchFailure),
  148. MACROSTR(ReaderFailure),
  149. MACROSTR(ResetFailure),
  150. MACROSTR(UnderVoltage),
  151. MACROSTR(WeakSignal)
  152. };
  153. #endif
  154. static char * ChargePointStatusStr[] = {
  155. MACROSTR(Available),
  156. MACROSTR(Preparing),
  157. MACROSTR(Charging),
  158. MACROSTR(SuspendedEVSE),
  159. MACROSTR(SuspendedEV),
  160. MACROSTR(Finishing),
  161. MACROSTR(Reserved),
  162. MACROSTR(Unavailable),
  163. MACROSTR(Faulted)
  164. };
  165. static char *RegistrationStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Pending),
  168. MACROSTR(Rejected)
  169. };
  170. static char *AvailabilityTypeStr[] = {
  171. MACROSTR(Inoperative),
  172. MACROSTR(Operative)
  173. };
  174. static char *AvailabilityStatusStr[] = {
  175. MACROSTR(Accepted),
  176. MACROSTR(Rejected),
  177. MACROSTR(Scheduled)
  178. };
  179. static char *ConfigurationStatusStr[] = {
  180. MACROSTR(Accepted),
  181. MACROSTR(Rejected),
  182. MACROSTR(RebootRequired),
  183. MACROSTR(NotSupported)
  184. };
  185. static char *ClearCacheStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected)
  188. };
  189. static char *ChargingProfilePurposeTypeStr[] = {
  190. MACROSTR(ChargePointMaxProfile),
  191. MACROSTR(TxDefaultProfile),
  192. MACROSTR(TxProfile)
  193. };
  194. static char *ChargingProfileStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected),
  197. MACROSTR(NotSupported)
  198. };
  199. static char *ClearChargingProfileStatusStr[] = {
  200. MACROSTR(Accepted),
  201. MACROSTR(Unknown)
  202. };
  203. static char *GetCompositeScheduleStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Rejected)
  206. };
  207. static char *UpdateTypeStr[] = {
  208. MACROSTR(Differential),
  209. MACROSTR(Full)
  210. };
  211. static char *UpdateStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Failed),
  214. MACROSTR(NotSupported),
  215. MACROSTR(VersionMismatch)
  216. };
  217. static char *RemoteStartStopStatusStr[] = {
  218. MACROSTR(Accepted),
  219. MACROSTR(Rejected)
  220. };
  221. static char *ReservationStatusStr[] = {
  222. MACROSTR(Accepted),
  223. MACROSTR(Faulted),
  224. MACROSTR(Occupied),
  225. MACROSTR(Rejected),
  226. MACROSTR(Unavailable)
  227. };
  228. static char *ResetTypeStr[] = {
  229. MACROSTR(Hard),
  230. MACROSTR(Soft)
  231. };
  232. static char *ResetStatusStr[] = {
  233. MACROSTR(Accepted),
  234. MACROSTR(Rejected)
  235. };
  236. static char * DiagnosticsStatusStr[] = {
  237. MACROSTR(Idle),
  238. MACROSTR(Uploaded),
  239. MACROSTR(UploadFailed),
  240. MACROSTR(Uploading)
  241. };
  242. static char * FirmwareStatusStr[] = {
  243. MACROSTR(Downloaded),
  244. MACROSTR(DownloadFailed),
  245. MACROSTR(Downloading),
  246. MACROSTR(Idle),
  247. MACROSTR(InstallationFailed),
  248. MACROSTR(Installing),
  249. MACROSTR(Installed)
  250. };
  251. static char * MessageTriggerStr[] = {
  252. MACROSTR(BootNotification),
  253. MACROSTR(DiagnosticsStatusNotification),
  254. MACROSTR(FirmwareStatusNotification),
  255. MACROSTR(Heartbeat),
  256. MACROSTR(MeterValues),
  257. MACROSTR(StatusNotification)
  258. };
  259. static char * TriggerMessageStatusStr[] = {
  260. MACROSTR(Accepted),
  261. MACROSTR(Rejected),
  262. MACROSTR(NotImplemented)
  263. };
  264. static char * UnlockStatusStr[] = {
  265. MACROSTR(Unlocked),
  266. MACROSTR(UnlockFailed),
  267. MACROSTR(NotSupported)
  268. };
  269. #if 0
  270. static char * StopTransactionReasonStr[] = {
  271. MACROSTR(EmergencyStop),
  272. MACROSTR(EVDisconnected),
  273. MACROSTR(HardReset),
  274. MACROSTR(Local),
  275. MACROSTR(Other),
  276. MACROSTR(PowerLoss),
  277. MACROSTR(Reboot),
  278. MACROSTR(Remote),
  279. MACROSTR(SoftReset),
  280. MACROSTR(UnlockCommand),
  281. MACROSTR(DeAuthorized)
  282. };
  283. #endif
  284. static char * CancelReservationStatusStr[] = {
  285. MACROSTR(Accepted),
  286. MACROSTR(Rejected)
  287. };
  288. static char * ReadingContextStr[] = {
  289. MACROSTR(Interruption.Begin),
  290. MACROSTR(Interruption.End),
  291. MACROSTR(Other),
  292. MACROSTR(Sample.Clock),
  293. MACROSTR(Sample.Periodic),
  294. MACROSTR(Transaction.Begin),
  295. MACROSTR(Transaction.End),
  296. MACROSTR(Trigger)
  297. };
  298. static char * ValueFormatStr[] = {
  299. MACROSTR(Raw),
  300. MACROSTR(SignedData)
  301. };
  302. static char * MeasurandStr[] = {
  303. MACROSTR(Current.Export),
  304. MACROSTR(Current.Import),
  305. MACROSTR(Current.Offered),
  306. MACROSTR(Energy.Active.Export.Register),
  307. MACROSTR(Energy.Active.Import.Register),
  308. MACROSTR(Energy.Reactive.Export.Register),
  309. MACROSTR(Energy.Reactive.Import.Register),
  310. MACROSTR(Energy.Active.Export.Interval),
  311. MACROSTR(Energy.Active.Import.Interval),
  312. MACROSTR(Energy.Reactive.Export.Interval),
  313. MACROSTR(Energy.Reactive.Import.Interval),
  314. MACROSTR(Frequency),
  315. MACROSTR(Power.Active.Export),
  316. MACROSTR(Power.Active.Import),
  317. MACROSTR(Power.Factor),
  318. MACROSTR(Power.Offered),
  319. MACROSTR(Power.Reactive.ExportMACROSTR),
  320. MACROSTR(Power.Reactive.Import),
  321. MACROSTR(RPM),
  322. MACROSTR(SoC),
  323. MACROSTR(Temperature),
  324. MACROSTR(Voltage)
  325. };
  326. static char * LocationStr[] = {
  327. MACROSTR(Body),
  328. MACROSTR(Cable),
  329. MACROSTR(EV),
  330. MACROSTR(Inlet),
  331. MACROSTR(Outlet)
  332. };
  333. static char * PhaseStr[] = {
  334. MACROSTR(L1),
  335. MACROSTR(L2),
  336. MACROSTR(L3),
  337. MACROSTR(N),
  338. MACROSTR(L1-N),
  339. MACROSTR(L2-N),
  340. MACROSTR(L3-N),
  341. MACROSTR(L1-L2),
  342. MACROSTR(L2-L3),
  343. MACROSTR(L3-L1)
  344. };
  345. static char * UnitOfMeasureStr[] = {
  346. MACROSTR(Wh),
  347. MACROSTR(kWh),
  348. MACROSTR(varh),
  349. MACROSTR(kvarh),
  350. MACROSTR(W),
  351. MACROSTR(kW),
  352. MACROSTR(VA),
  353. MACROSTR(kVA),
  354. MACROSTR(var),
  355. MACROSTR(kvar),
  356. MACROSTR(A),
  357. MACROSTR(V),
  358. MACROSTR(Celsius),
  359. MACROSTR(Fahrenheit),
  360. MACROSTR(K),
  361. MACROSTR(Percent)
  362. };
  363. //=========================================
  364. // TTIA routine
  365. //=========================================
  366. int sendTTIAInfo(uint8_t gun_index)
  367. {
  368. static int sn = 0;
  369. int result = FAIL;
  370. struct hostent *server;
  371. int udp_socket_fd;
  372. struct sockaddr_in dest_addr = {0};
  373. uint8_t tx_buf[80] = {0};
  374. uint8_t logBuf[256]= {0};
  375. uint8_t tx_len, tempIndex, socStart, socEnd;
  376. uint16_t PresentChargedEnergy;
  377. struct tm tmStart, tmEnd;
  378. DEBUG_INFO("sendTTIAInfo...\n");
  379. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  380. {
  381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  382. {
  383. tempIndex = ((gun_index==2) ? 1: 0);
  384. }
  385. else
  386. {
  387. tempIndex = gun_index;
  388. }
  389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  390. {
  391. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  392. {
  393. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  394. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  395. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  396. }
  397. }
  398. }
  399. else if(gunType[gun_index] == GUN_TYPE_CCS)
  400. {
  401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  402. {
  403. tempIndex = ((gun_index==2) ? 1: 0);
  404. }
  405. else
  406. {
  407. tempIndex = gun_index;
  408. }
  409. for (int index = 0; index < CCS_QUANTITY; index++)
  410. {
  411. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  412. {
  413. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  414. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  415. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  416. }
  417. }
  418. }
  419. else if(gunType[gun_index] == GUN_TYPE_GBT)
  420. {
  421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  422. {
  423. tempIndex = ((gun_index==2) ? 1: 0);
  424. }
  425. else
  426. {
  427. tempIndex = gun_index;
  428. }
  429. for (int index = 0; index < GB_QUANTITY; index++)
  430. {
  431. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  432. {
  433. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  434. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  435. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  436. }
  437. }
  438. }
  439. else if(gunType[gun_index] == GUN_TYPE_DO)
  440. {
  441. tempIndex = gun_index;
  442. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  443. {
  444. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  445. {
  446. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  447. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  448. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  449. }
  450. }
  451. }
  452. else
  453. {
  454. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  455. {
  456. tempIndex = 2;
  457. }
  458. else
  459. {
  460. tempIndex = gun_index;
  461. }
  462. for (int index = 0; index < AC_QUANTITY; index++)
  463. {
  464. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  465. {
  466. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  467. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  468. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  469. }
  470. }// END
  471. }
  472. // Message assembly
  473. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  474. tx_buf[4] = 0x02; // Protocol Version
  475. tx_buf[5] = 0xb0; // Message ID
  476. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  477. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  478. tx_buf[8] = 0x00; // CarID low byte
  479. tx_buf[9] = 0x00; // CarID high byte
  480. tx_buf[10] = 0x00; // ID Storage
  481. tx_buf[11] = 0x00; // Driver lowest byte
  482. tx_buf[12] = 0x00; // Driver 2nd byte
  483. tx_buf[13] = 0x00; // Driver 3rd byte
  484. tx_buf[14] = 0x00; // Driver highest byte
  485. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  486. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  487. tx_buf[17] = 0x00; // Reserve
  488. tx_buf[18] = 60 & 0xff; // Payload length low byte
  489. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  490. // EVSE provider
  491. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  492. // EVSE provider
  493. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  494. // EVSE id
  495. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  496. // Connector id
  497. tx_buf[37] = gun_index;
  498. // EVSE station
  499. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  500. // Vehicle SN
  501. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  502. // Mileage
  503. tx_buf[61] = 0x00; // lowest byte
  504. tx_buf[62] = 0x00; // 2nd byte
  505. tx_buf[63] = 0x00; // highest byte
  506. // Start date time 6 bytes
  507. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  508. {
  509. struct tm *tmTarget;
  510. struct timeb tbTarget;
  511. tmStart.tm_year -= 1900;
  512. tmStart.tm_mon -= 1;
  513. tmStart.tm_gmtoff = 0;
  514. tbTarget.time = mktime(&tmStart);
  515. tbTarget.timezone = 0;
  516. tbTarget.time += (8*3600);
  517. tmTarget = gmtime(&tbTarget.time);
  518. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  519. tx_buf[65] = (tmTarget->tm_mon+1);
  520. tx_buf[66] = tmTarget->tm_mday;
  521. tx_buf[67] = tmTarget->tm_hour;
  522. tx_buf[68] = tmTarget->tm_min;
  523. tx_buf[69] = tmTarget->tm_sec;
  524. }
  525. // Stop date time 6 bytes
  526. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  527. {
  528. struct tm *tmTarget;
  529. struct timeb tbTarget;
  530. tmEnd.tm_year -= 1900;
  531. tmEnd.tm_mon -= 1;
  532. tmEnd.tm_gmtoff = 0;
  533. tbTarget.time = mktime(&tmEnd);
  534. tbTarget.timezone = 0;
  535. tbTarget.time += (8*3600);
  536. tmTarget = gmtime(&tbTarget.time);
  537. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  538. tx_buf[71] = (tmTarget->tm_mon+1);
  539. tx_buf[72] = tmTarget->tm_mday;
  540. tx_buf[73] = tmTarget->tm_hour;
  541. tx_buf[74] = tmTarget->tm_min;
  542. tx_buf[75] = tmTarget->tm_sec;
  543. }
  544. // Session energy 2 bytes
  545. tx_buf[76] = PresentChargedEnergy & 0xff;
  546. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  547. // Start SOC 1 byte
  548. tx_buf[78] = socStart;
  549. // Stop SOC 1 byte
  550. tx_buf[79] = socEnd;
  551. // Open socket
  552. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  553. if(udp_socket_fd == -1)
  554. {
  555. DEBUG_ERROR("UDP socket create failed!\n");
  556. }
  557. else
  558. {
  559. // Get server DNS entry
  560. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  561. if (server == NULL)
  562. {
  563. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  564. }
  565. else
  566. {
  567. // Build the server's Internet address
  568. bzero((char *) &dest_addr, sizeof(dest_addr));
  569. dest_addr.sin_family = AF_INET;
  570. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  571. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  572. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  573. {
  574. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  575. {
  576. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  577. }
  578. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  579. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  580. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  581. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  582. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  583. DEBUG_TTIA_INFO("---------- Header ----------\n");
  584. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  585. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  586. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  587. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  588. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  589. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  590. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  591. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  592. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  593. DEBUG_TTIA_INFO("Len: 0x3C\n");
  594. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  595. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  596. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  597. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  598. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  599. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  600. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  601. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  602. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  603. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  604. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  605. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  606. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  607. DEBUG_TTIA_INFO("=========================================\n");
  608. sn++;
  609. result = PASS;
  610. }
  611. else
  612. {
  613. DEBUG_ERROR("UDP sent out fail.\n");
  614. }
  615. }
  616. }
  617. return result;
  618. }
  619. //=========================================
  620. // Save configuration
  621. //=========================================
  622. int runShellCmd(const char*cmd)
  623. {
  624. int result = FAIL;
  625. char buf[256];
  626. FILE *fp;
  627. fp = popen(cmd, "r");
  628. if(fp != NULL)
  629. {
  630. while(fgets(buf, sizeof(buf), fp) != NULL)
  631. {
  632. DEBUG_INFO("%s\n", buf);
  633. }
  634. result = PASS;
  635. }
  636. pclose(fp);
  637. return result;
  638. }
  639. int StoreUsrConfigData(struct SysConfigData *UsrData)
  640. {
  641. int result = PASS;
  642. int fd,wrd;
  643. unsigned int i,Chk;
  644. unsigned char *ptr, *BufTmp;
  645. int MtdBlockSize = 0x300000;
  646. Chk=0;
  647. ptr=(unsigned char *)UsrData;
  648. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  649. {
  650. memset(BufTmp,0,MtdBlockSize);
  651. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  652. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  653. Chk+=*(BufTmp+i);
  654. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  655. // Output configuration to file.
  656. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  657. if (fd < 0)
  658. {
  659. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  660. free(BufTmp);
  661. return 0;
  662. }
  663. wrd=write(fd, BufTmp, MtdBlockSize);
  664. close(fd);
  665. if(wrd<MtdBlockSize)
  666. {
  667. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  668. free(BufTmp);
  669. return 0;
  670. }
  671. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  672. DEBUG_INFO("Erase /dev/mtd10.\n");
  673. runShellCmd("flash_erase /dev/mtd10 0 0");
  674. DEBUG_INFO("Write /dev/mtd10.\n");
  675. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  676. DEBUG_INFO("Erase /dev/mtd11.\n");
  677. runShellCmd("flash_erase /dev/mtd11 0 0");
  678. DEBUG_INFO("Write /dev/mtd11.\n");
  679. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  680. system("rm -f /mnt/EvseConfig.bin");
  681. DEBUG_INFO("EvseConfig write to flash OK\n");
  682. }
  683. else
  684. {
  685. DEBUG_ERROR("alloc BlockSize NG\r\n");
  686. result = FAIL;
  687. }
  688. if(BufTmp!=NULL)
  689. free(BufTmp);
  690. return result;
  691. }
  692. //=========================================
  693. // Sqlite3 related function
  694. //=========================================
  695. static int selectSqlCount = 0;
  696. static int callback(void *data, int argc, char **argv, char **azColName){
  697. int i;
  698. //printf("%s: ", (const char*)data);
  699. selectSqlCount = argc;
  700. for(i = 0; i<argc; i++){
  701. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  702. }
  703. //printf("\n");
  704. return 0;
  705. }
  706. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  707. //int i;
  708. //printf("%s:\n", (const char*)data);
  709. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  710. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  711. return 0;
  712. }
  713. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  714. //printf("%s:\n", (const char*)data);
  715. //idTag
  716. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  717. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  718. //parentIdTag
  719. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  720. //expir_date
  721. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  722. //status
  723. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  724. //version
  725. if(columenCount > 5)
  726. idTagQuery.listVersionInt = atoi(columnValue[5]);
  727. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  728. return 0;
  729. }
  730. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  731. {
  732. // localversion = argv[5] ? atoi(argv[5]) : 0;
  733. // printf("localversion=%d\n", localversion);
  734. return 0;
  735. }
  736. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  737. {
  738. for (int i = 0; i < n_columns; i++)
  739. {
  740. DEBUG_INFO("%s\t", col_values[i]);
  741. }
  742. DEBUG_INFO("\n");
  743. return 0;
  744. }
  745. int OCPP_cleanLocalCache()
  746. {
  747. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  748. char *errMsg = 0;
  749. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  750. if (SQLITE_OK != rc)
  751. {
  752. DEBUG_INFO("SQL error: %s\n",errMsg);
  753. return FALSE;
  754. }
  755. return TRUE;
  756. }
  757. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  758. {
  759. int isSuccess = TRUE;
  760. int ret = 0;
  761. //const char* data = "Callback function called";
  762. char sql[300];
  763. char zErrMsg[200];
  764. memset(sql, 0, 300);
  765. memset(zErrMsg, 0, 200);
  766. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  767. //* Execute SQL statement */
  768. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  769. if( ret != SQLITE_OK )
  770. {
  771. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  772. isSuccess = FALSE;
  773. }
  774. return isSuccess;
  775. }
  776. void OCPP_getIdTagFromLocalCache(char idTag[])
  777. {
  778. int rc = 0;
  779. char sql[100];
  780. char zErrMsg[100];
  781. memset(sql, 0, 100);
  782. memset(zErrMsg, 0, 100);
  783. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  784. memset(&idTagQuery, 0, sizeof(idTagQuery));
  785. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  786. /* Execute SQL statement */
  787. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  788. if( rc != SQLITE_OK )
  789. {
  790. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  791. }
  792. }
  793. void OCPP_getListVerion()
  794. {
  795. int rc = 0;
  796. // const char* data = "Callback function called";
  797. char sql[100];
  798. char zErrMsg[100];
  799. memset(sql, 0, 100);
  800. memset(zErrMsg, 0, 100);
  801. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  802. /* Execute SQL statement */
  803. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  804. if( rc != SQLITE_OK )
  805. {
  806. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  807. }
  808. }
  809. void OCPP_get_TableAuthlocalAllData(void)
  810. {
  811. int rc = 0;
  812. char sql[100];
  813. char zErrMsg[100];
  814. memset(sql, 0, 100);
  815. memset(zErrMsg, 0, 100);
  816. sprintf(sql,"select * from ocpp_auth_local ");
  817. /* Execute SQL statement */
  818. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  819. if( rc != SQLITE_OK )
  820. {
  821. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  822. }
  823. //return ver;
  824. }
  825. int OCPP_cleanLocalList()
  826. {
  827. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  828. char *errMsg = 0;
  829. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  830. if (SQLITE_OK != rc)
  831. {
  832. DEBUG_INFO("%s\n",errMsg);
  833. return FALSE;
  834. }
  835. return TRUE;
  836. }
  837. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  838. {
  839. int isSuccess = FALSE;
  840. int ret = 0;
  841. //const char* data = "Callback function called";
  842. char sql[300];
  843. char zErrMsg[200];
  844. memset(sql, 0, 300);
  845. memset(zErrMsg, 0, 200);
  846. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  847. //* Execute SQL statement */
  848. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  849. if( ret != SQLITE_OK )
  850. {
  851. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  852. return isSuccess;
  853. }
  854. memset(sql, 0, 300);
  855. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  856. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  857. if( ret != SQLITE_OK )
  858. {
  859. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  860. return isSuccess;
  861. }
  862. isSuccess = TRUE;
  863. return isSuccess;
  864. }
  865. void OCPP_getIdTagFromLocalList(char idTag[])
  866. {
  867. int rc = 0;
  868. // const char* data = "Callback function called";
  869. char sql[100];
  870. char zErrMsg[100];
  871. memset(sql, 0, 100);
  872. memset(zErrMsg, 0, 100);
  873. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  874. memset(&idTagQuery, 0, sizeof(idTagQuery));
  875. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  876. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  877. /* Execute SQL statement */
  878. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  879. if( rc != SQLITE_OK )
  880. {
  881. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  882. }
  883. //return ver;
  884. }
  885. void OCPP_deleteIdTagFromLocalList(char idTag[])
  886. {
  887. //int ver = 0;
  888. //int isSuccess = FALSE;
  889. int rc = 0;
  890. char sql[100];
  891. char zErrMsg[100];
  892. memset(sql, 0, 100);
  893. memset(zErrMsg, 0, 100);
  894. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  895. //* Execute SQL statement */
  896. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  897. if( rc != SQLITE_OK )
  898. {
  899. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  900. }
  901. }
  902. int getCurrentYear()
  903. {
  904. int result = 0;
  905. time_t CurrentTime;
  906. struct tm *tm;
  907. CurrentTime = time(NULL);
  908. tm=localtime(&CurrentTime);
  909. result = (tm->tm_year + 1900);
  910. return result;
  911. }
  912. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  913. {
  914. int result = PASS;
  915. char* errMsg = NULL;
  916. char sqlStr[8192];
  917. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  918. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  919. {
  920. result = FAIL;
  921. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  922. }
  923. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  924. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  925. {
  926. result = FAIL;
  927. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  928. }
  929. return result;
  930. }
  931. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  932. {
  933. int isSuccess = TRUE;
  934. int tempIndex;
  935. json_object *EnergyDataTransfer = json_object_new_object();
  936. json_object *periodEnergys = json_object_new_object();
  937. char sql[1024];
  938. char zErrMsg[200];
  939. memset(sql, 0, ARRAY_SIZE(sql));
  940. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  941. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  942. {
  943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  944. {
  945. tempIndex = ((gun_index==2) ? 1: 0);
  946. }
  947. else
  948. {
  949. tempIndex = gun_index;
  950. }
  951. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  952. {
  953. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  954. {
  955. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  956. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  957. {
  958. uint8_t period[3];
  959. sprintf((char*)period, "%d", idxPeriod);
  960. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  961. }
  962. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  963. } //end of the same index
  964. }//end of for CHAdeMO_QUANTITY
  965. }
  966. else if(gunType[gun_index] == GUN_TYPE_CCS)
  967. {
  968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  969. {
  970. tempIndex = ((gun_index==2) ? 1: 0);
  971. }
  972. else
  973. {
  974. tempIndex = gun_index;
  975. }
  976. for (int index = 0; index < CCS_QUANTITY; index++)
  977. {
  978. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  979. {
  980. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  981. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  982. {
  983. uint8_t period[3];
  984. sprintf((char*)period, "%d", idxPeriod);
  985. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  986. }
  987. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  988. } //end of the same index
  989. } // end of for CCS_QUANTITY
  990. }
  991. else if(gunType[gun_index] == GUN_TYPE_GBT)
  992. {
  993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  994. {
  995. tempIndex = ((gun_index==2) ? 1: 0);
  996. }
  997. else
  998. {
  999. tempIndex = gun_index;
  1000. }
  1001. for (int index = 0; index < GB_QUANTITY; index++)
  1002. {
  1003. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1004. {
  1005. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1006. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1007. {
  1008. uint8_t period[3];
  1009. sprintf((char*)period, "%d", idxPeriod);
  1010. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1011. }
  1012. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1013. } //end of the same index
  1014. } // end of for GB_QUANTITY
  1015. }
  1016. else if(gunType[gun_index] == GUN_TYPE_DO)
  1017. {
  1018. tempIndex = gun_index;
  1019. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1020. {
  1021. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1022. {
  1023. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1024. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1025. {
  1026. uint8_t period[3];
  1027. sprintf((char*)period, "%d", idxPeriod);
  1028. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1029. }
  1030. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1031. } //end of the same index
  1032. }
  1033. }
  1034. else
  1035. {
  1036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1037. {
  1038. tempIndex = 2;
  1039. }
  1040. else
  1041. {
  1042. tempIndex = gun_index;
  1043. }
  1044. for (int index = 0; index < AC_QUANTITY; index++)
  1045. {
  1046. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1047. {
  1048. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1049. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1050. {
  1051. uint8_t period[3];
  1052. sprintf((char*)period, "%d", idxPeriod);
  1053. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1054. }
  1055. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1056. }//end of the same index
  1057. }//end of for AC_QUANTITY
  1058. }
  1059. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1060. json_object_put(EnergyDataTransfer);
  1061. //* Execute SQL statement */
  1062. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1063. {
  1064. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1065. isSuccess = FALSE;
  1066. }
  1067. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1068. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1069. {
  1070. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1071. isSuccess = FALSE;
  1072. }
  1073. return isSuccess;
  1074. }
  1075. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1076. {
  1077. int isSuccess = TRUE;
  1078. char sql[512];
  1079. char zErrMsg[200];
  1080. int rows, cols;
  1081. char **resultData;
  1082. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1083. /* Execute SQL statement */
  1084. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1085. {
  1086. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1087. isSuccess = FALSE;
  1088. }
  1089. else
  1090. {
  1091. if((rows > 0) && (atoi(resultData[4]) > 0))
  1092. {
  1093. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1094. }
  1095. else
  1096. {
  1097. DEBUG_WARN("There is not match transaction data.\n");
  1098. isSuccess = FALSE;
  1099. }
  1100. }
  1101. return isSuccess;
  1102. }
  1103. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1104. {
  1105. int result = PASS;
  1106. char* errMsg = NULL;
  1107. char sqlStr[8192];
  1108. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1109. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1110. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1111. {
  1112. result = FAIL;
  1113. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1114. }
  1115. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1116. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1117. {
  1118. result = FAIL;
  1119. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1120. }
  1121. return result;
  1122. }
  1123. int OCPP_update_deduct_info(int txId, char *creditNo)
  1124. {
  1125. int result = PASS;
  1126. char* errMsg = NULL;
  1127. char sqlStr[8192];
  1128. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1129. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1130. {
  1131. result = FAIL;
  1132. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1133. }
  1134. return result;
  1135. }
  1136. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1137. {
  1138. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1139. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1140. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1141. atoi(columnValue[1]),
  1142. columnValue[2],
  1143. atoi(columnValue[3])==1?"true":"false",
  1144. atoi(columnValue[4])==1?"true":"false",
  1145. columnValue[5],
  1146. columnValue[9]);
  1147. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1148. return 0;
  1149. }
  1150. void OCPP_query_deduct_info()
  1151. {
  1152. int rc = 0;
  1153. char sql[100];
  1154. char zErrMsg[100];
  1155. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1156. /* Execute SQL statement */
  1157. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1158. if( rc != SQLITE_OK )
  1159. {
  1160. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1161. }
  1162. }
  1163. void reportReaderStatus(int gun_index)
  1164. {
  1165. struct timeval tmnow;
  1166. struct tm *tm;
  1167. char buf[28];//, usec_buf[6];
  1168. gettimeofday(&tmnow, NULL);
  1169. time_t t;
  1170. t = time(NULL);
  1171. /*UTC time and date*/
  1172. tm = gmtime(&t);
  1173. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1174. #if 0 // remove temporally
  1175. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1176. strcat(buf,".");
  1177. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1178. strcat(buf,usec_buf);
  1179. #endif
  1180. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1181. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1182. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1183. (gun_index+1),
  1184. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1185. buf,
  1186. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1187. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1188. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1189. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1190. }
  1191. //==========================================
  1192. // Check time passed since today
  1193. //==========================================
  1194. long long DiffTimebWithNow(struct timeb ST)
  1195. {
  1196. //return milli-second
  1197. struct timeb ET;
  1198. long long StartTime,StopTime;
  1199. ftime(&ET);
  1200. StartTime=(long long)ST.time;
  1201. StopTime=(long long)ET.time;
  1202. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1203. }
  1204. int getTimePassSinceToday(uint8_t gun_index)
  1205. {
  1206. int result = -1;
  1207. static time_t lastTime[4];
  1208. time_t t;
  1209. struct tm *tmStartToday;
  1210. struct timeb tbStartToday;
  1211. t=time(NULL);
  1212. if(difftime(t, lastTime[gun_index])>0)
  1213. {
  1214. tmStartToday=localtime(&t);
  1215. tmStartToday->tm_hour = 0;
  1216. tmStartToday->tm_min = 0;
  1217. tmStartToday->tm_sec = 0;
  1218. tbStartToday.time = mktime(tmStartToday);
  1219. tbStartToday.millitm = 0;
  1220. result = DiffTimebWithNow(tbStartToday)/1000;
  1221. lastTime[gun_index] = t;
  1222. }
  1223. return result;
  1224. }
  1225. void getNowDatetime(uint8_t *data)
  1226. {
  1227. time_t t = time(NULL);
  1228. struct tm tm = *localtime(&t);
  1229. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  1230. }
  1231. int syncDateTimeRTC(uint8_t *data)
  1232. {
  1233. struct ParsingResult
  1234. {
  1235. int result;
  1236. int scanedElement;
  1237. int year;
  1238. int month;
  1239. int mday;
  1240. int hour;
  1241. int min;
  1242. int sec;
  1243. int tz_hour;
  1244. int tz_min;
  1245. float minSec;
  1246. }result;
  1247. struct tm tmOrg;
  1248. struct tm *tmTarget;
  1249. struct timeb tbTarget;
  1250. char buf[128];
  1251. memset(&result, 0x00, sizeof(struct ParsingResult));
  1252. result.result = PASS;
  1253. if(strstr((char*)data, ".") != NULL)
  1254. {
  1255. // Original data with mini second
  1256. if(strstr((char*)data, "Z") != NULL)
  1257. {
  1258. // Original data with Z
  1259. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1260. &result.year,
  1261. &result.month,
  1262. &result.mday,
  1263. &result.hour,
  1264. &result.min,
  1265. &result.sec,
  1266. &result.minSec);
  1267. }
  1268. else
  1269. {
  1270. // Original data without Z
  1271. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1272. &result.year,
  1273. &result.month,
  1274. &result.mday,
  1275. &result.hour,
  1276. &result.min,
  1277. &result.sec,
  1278. &result.minSec,
  1279. &result.tz_hour,
  1280. &result.tz_min);
  1281. }
  1282. }
  1283. else
  1284. {
  1285. // Original data without mini second
  1286. if(strstr((char*)data, "Z") != NULL)
  1287. {
  1288. // Original data with Z
  1289. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1290. &result.year,
  1291. &result.month,
  1292. &result.mday,
  1293. &result.hour,
  1294. &result.min,
  1295. &result.sec);
  1296. }
  1297. else
  1298. {
  1299. // Original data without Z
  1300. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1301. &result.year,
  1302. &result.month,
  1303. &result.mday,
  1304. &result.hour,
  1305. &result.min,
  1306. &result.sec,
  1307. &result.tz_hour,
  1308. &result.tz_min);
  1309. }
  1310. }
  1311. tmOrg.tm_year = result.year - 1900;
  1312. tmOrg.tm_mon = result.month - 1;
  1313. tmOrg.tm_mday = result.mday;
  1314. tmOrg.tm_hour = result.hour;
  1315. tmOrg.tm_min = result.min;
  1316. tmOrg.tm_sec = result.sec;
  1317. tmOrg.tm_gmtoff = 0;
  1318. tbTarget.time = mktime(&tmOrg);
  1319. tbTarget.timezone = 0;
  1320. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1321. tmTarget = gmtime(&tbTarget.time);
  1322. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  1323. //DEBUG_INFO(" org date time: %s\n", data);
  1324. //DEBUG_INFO("parse date time: %s\n", buf);
  1325. system(buf);
  1326. system("/sbin/hwclock -w --systohc");
  1327. if(result.scanedElement < 6)
  1328. result.result = FAIL;
  1329. return result.result;
  1330. }
  1331. //==========================================
  1332. // GetCompositeSchedule logic related function
  1333. //==========================================
  1334. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1335. {
  1336. //return milli-second
  1337. unsigned int StartTime,StopTime;
  1338. StartTime=(unsigned int)ST.time;
  1339. StopTime=(unsigned int)ET.time;
  1340. return (StopTime-StartTime);
  1341. }
  1342. int DiffTimebWithNowSec(struct timeb ST)
  1343. {
  1344. //return milli-second
  1345. struct timeb ET;
  1346. unsigned int StartTime,StopTime;
  1347. ftime(&ET);
  1348. StartTime=(unsigned int)ST.time;
  1349. StopTime=(unsigned int)ET.time;
  1350. return (StopTime-StartTime);
  1351. }
  1352. int getStartStop(uint8_t *start, uint8_t *stop)
  1353. {
  1354. struct ParsingResult
  1355. {
  1356. int result;
  1357. int scanedElement;
  1358. int year;
  1359. int month;
  1360. int mday;
  1361. int hour;
  1362. int min;
  1363. int sec;
  1364. int tz_hour;
  1365. int tz_min;
  1366. float minSec;
  1367. };
  1368. struct ParsingResult parseStart;
  1369. struct ParsingResult parseStop;
  1370. int result = -1;
  1371. struct tm tmStart;
  1372. struct timeb tbStart;
  1373. struct tm tmStop;
  1374. struct timeb tbStop;
  1375. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1376. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1377. // Scan start & stop date time
  1378. if(strstr((char*)start, ".") != NULL)
  1379. {
  1380. // Original data with mini second
  1381. if(strstr((char*)start, "Z") != NULL)
  1382. {
  1383. // Original data with Z
  1384. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1385. &parseStart.year,
  1386. &parseStart.month,
  1387. &parseStart.mday,
  1388. &parseStart.hour,
  1389. &parseStart.min,
  1390. &parseStart.sec,
  1391. &parseStart.minSec);
  1392. }
  1393. else
  1394. {
  1395. // Original data without Z
  1396. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1397. &parseStart.year,
  1398. &parseStart.month,
  1399. &parseStart.mday,
  1400. &parseStart.hour,
  1401. &parseStart.min,
  1402. &parseStart.sec,
  1403. &parseStart.minSec,
  1404. &parseStart.tz_hour,
  1405. &parseStart.tz_min);
  1406. }
  1407. }
  1408. else
  1409. {
  1410. // Original data without mini second
  1411. if(strstr((char*)start, "Z") != NULL)
  1412. {
  1413. // Original data with Z
  1414. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1415. &parseStart.year,
  1416. &parseStart.month,
  1417. &parseStart.mday,
  1418. &parseStart.hour,
  1419. &parseStart.min,
  1420. &parseStart.sec);
  1421. }
  1422. else
  1423. {
  1424. // Original data without Z
  1425. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1426. &parseStart.year,
  1427. &parseStart.month,
  1428. &parseStart.mday,
  1429. &parseStart.hour,
  1430. &parseStart.min,
  1431. &parseStart.sec,
  1432. &parseStart.tz_hour,
  1433. &parseStart.tz_min);
  1434. }
  1435. }
  1436. if(strstr((char*)stop, ".") != NULL)
  1437. {
  1438. // Original data with mini second
  1439. if(strstr((char*)stop, "Z") != NULL)
  1440. {
  1441. // Original data with Z
  1442. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1443. &parseStop.year,
  1444. &parseStop.month,
  1445. &parseStop.mday,
  1446. &parseStop.hour,
  1447. &parseStop.min,
  1448. &parseStop.sec,
  1449. &parseStop.minSec);
  1450. }
  1451. else
  1452. {
  1453. // Original data without Z
  1454. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1455. &parseStop.year,
  1456. &parseStop.month,
  1457. &parseStop.mday,
  1458. &parseStop.hour,
  1459. &parseStop.min,
  1460. &parseStop.sec,
  1461. &parseStop.minSec,
  1462. &parseStop.tz_hour,
  1463. &parseStop.tz_min);
  1464. }
  1465. }
  1466. else
  1467. {
  1468. // Original data without mini second
  1469. if(strstr((char*)stop, "Z") != NULL)
  1470. {
  1471. // Original data with Z
  1472. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1473. &parseStop.year,
  1474. &parseStop.month,
  1475. &parseStop.mday,
  1476. &parseStop.hour,
  1477. &parseStop.min,
  1478. &parseStop.sec);
  1479. }
  1480. else
  1481. {
  1482. // Original data without Z
  1483. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1484. &parseStop.year,
  1485. &parseStop.month,
  1486. &parseStop.mday,
  1487. &parseStop.hour,
  1488. &parseStop.min,
  1489. &parseStop.sec,
  1490. &parseStop.tz_hour,
  1491. &parseStop.tz_min);
  1492. }
  1493. }
  1494. // Calculate date time difference
  1495. if((parseStart.scanedElement >=6) &&
  1496. (parseStop.scanedElement >=6))
  1497. {
  1498. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1499. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1500. tmStart.tm_year = parseStart.year - 1900;
  1501. tmStart.tm_mon = parseStart.month - 1;
  1502. tmStart.tm_mday = parseStart.mday;
  1503. tmStart.tm_hour = parseStart.hour;
  1504. tmStart.tm_min = parseStart.min;
  1505. tmStart.tm_sec = parseStart.sec;
  1506. tmStart.tm_gmtoff = 0;
  1507. tbStart.time = mktime(&tmStart);
  1508. tbStart.timezone = 0;
  1509. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1510. tmStop.tm_year = parseStop.year - 1900;
  1511. tmStop.tm_mon = parseStop.month - 1;
  1512. tmStop.tm_mday = parseStop.mday;
  1513. tmStop.tm_hour = parseStop.hour;
  1514. tmStop.tm_min = parseStop.min;
  1515. tmStop.tm_sec = parseStop.sec;
  1516. tmStop.tm_gmtoff = 0;
  1517. tbStop.time = mktime(&tmStop);
  1518. tbStop.timezone = 0;
  1519. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1520. result = DiffTimebSec(tbStart, tbStop);
  1521. //DEBUG_INFO("getStartStop(): %d\n", result);
  1522. }
  1523. else
  1524. {
  1525. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1526. }
  1527. return result;
  1528. }
  1529. int isOvertNow(uint8_t *start)
  1530. {
  1531. int result = NO;
  1532. struct ParsingResult
  1533. {
  1534. int result;
  1535. int scanedElement;
  1536. int year;
  1537. int month;
  1538. int mday;
  1539. int hour;
  1540. int min;
  1541. int sec;
  1542. int tz_hour;
  1543. int tz_min;
  1544. float minSec;
  1545. }parsingResult;
  1546. struct tm tmStart;
  1547. struct timeb tbStart;
  1548. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1549. if(strstr((char*)start, ".") != NULL)
  1550. {
  1551. // Original data with mini second
  1552. if(strstr((char*)start, "Z") != NULL)
  1553. {
  1554. // Original data with Z
  1555. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1556. &parsingResult.year,
  1557. &parsingResult.month,
  1558. &parsingResult.mday,
  1559. &parsingResult.hour,
  1560. &parsingResult.min,
  1561. &parsingResult.sec,
  1562. &parsingResult.minSec);
  1563. }
  1564. else
  1565. {
  1566. // Original data without Z
  1567. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1568. &parsingResult.year,
  1569. &parsingResult.month,
  1570. &parsingResult.mday,
  1571. &parsingResult.hour,
  1572. &parsingResult.min,
  1573. &parsingResult.sec,
  1574. &parsingResult.minSec,
  1575. &parsingResult.tz_hour,
  1576. &parsingResult.tz_min);
  1577. }
  1578. }
  1579. else
  1580. {
  1581. // Original data without mini second
  1582. if(strstr((char*)start, "Z") != NULL)
  1583. {
  1584. // Original data with Z
  1585. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1586. &parsingResult.year,
  1587. &parsingResult.month,
  1588. &parsingResult.mday,
  1589. &parsingResult.hour,
  1590. &parsingResult.min,
  1591. &parsingResult.sec);
  1592. }
  1593. else
  1594. {
  1595. // Original data without Z
  1596. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1597. &parsingResult.year,
  1598. &parsingResult.month,
  1599. &parsingResult.mday,
  1600. &parsingResult.hour,
  1601. &parsingResult.min,
  1602. &parsingResult.sec,
  1603. &parsingResult.tz_hour,
  1604. &parsingResult.tz_min);
  1605. }
  1606. }
  1607. if(parsingResult.scanedElement >= 6)
  1608. {
  1609. tmStart.tm_year = parsingResult.year - 1900;
  1610. tmStart.tm_mon = parsingResult.month - 1;
  1611. tmStart.tm_mday = parsingResult.mday;
  1612. tmStart.tm_hour = parsingResult.hour;
  1613. tmStart.tm_min = parsingResult.min;
  1614. tmStart.tm_sec = parsingResult.sec;
  1615. tmStart.tm_gmtoff = 0;
  1616. tbStart.time = mktime(&tmStart);
  1617. tbStart.timezone = 0;
  1618. tbStart.millitm = 0;
  1619. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1620. if(DiffTimebWithNowSec(tbStart) <= 0)
  1621. result = NO;
  1622. else
  1623. result = YES;
  1624. }
  1625. else
  1626. {
  1627. DEBUG_WARN("Start date parsing error.\n");
  1628. }
  1629. return result;
  1630. }
  1631. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1632. {
  1633. struct ParsingResult
  1634. {
  1635. int result;
  1636. int scanedElement;
  1637. int year;
  1638. int month;
  1639. int mday;
  1640. int hour;
  1641. int min;
  1642. int sec;
  1643. int tz_hour;
  1644. int tz_min;
  1645. float minSec;
  1646. };
  1647. struct ParsingResult parseStart;
  1648. struct ParsingResult parseStop;
  1649. int result = -1;
  1650. struct tm tmStart;
  1651. struct timeb tbStart;
  1652. struct tm tmStop;
  1653. struct timeb tbStop;
  1654. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1655. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1656. // Scan start & stop date time
  1657. if(strstr((char*)start, ".") != NULL)
  1658. {
  1659. // Original data with mini second
  1660. if(strstr((char*)start, "Z") != NULL)
  1661. {
  1662. // Original data with Z
  1663. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1664. &parseStart.year,
  1665. &parseStart.month,
  1666. &parseStart.mday,
  1667. &parseStart.hour,
  1668. &parseStart.min,
  1669. &parseStart.sec,
  1670. &parseStart.minSec);
  1671. }
  1672. else
  1673. {
  1674. // Original data without Z
  1675. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1676. &parseStart.year,
  1677. &parseStart.month,
  1678. &parseStart.mday,
  1679. &parseStart.hour,
  1680. &parseStart.min,
  1681. &parseStart.sec,
  1682. &parseStart.minSec,
  1683. &parseStart.tz_hour,
  1684. &parseStart.tz_min);
  1685. }
  1686. }
  1687. else
  1688. {
  1689. // Original data without mini second
  1690. if(strstr((char*)start, "Z") != NULL)
  1691. {
  1692. // Original data with Z
  1693. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1694. &parseStart.year,
  1695. &parseStart.month,
  1696. &parseStart.mday,
  1697. &parseStart.hour,
  1698. &parseStart.min,
  1699. &parseStart.sec);
  1700. }
  1701. else
  1702. {
  1703. // Original data without Z
  1704. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1705. &parseStart.year,
  1706. &parseStart.month,
  1707. &parseStart.mday,
  1708. &parseStart.hour,
  1709. &parseStart.min,
  1710. &parseStart.sec,
  1711. &parseStart.tz_hour,
  1712. &parseStart.tz_min);
  1713. }
  1714. }
  1715. if(strstr((char*)stop, ".") != NULL)
  1716. {
  1717. // Original data with mini second
  1718. if(strstr((char*)stop, "Z") != NULL)
  1719. {
  1720. // Original data with Z
  1721. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1722. &parseStop.year,
  1723. &parseStop.month,
  1724. &parseStop.mday,
  1725. &parseStop.hour,
  1726. &parseStop.min,
  1727. &parseStop.sec,
  1728. &parseStop.minSec);
  1729. }
  1730. else
  1731. {
  1732. // Original data without Z
  1733. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1734. &parseStop.year,
  1735. &parseStop.month,
  1736. &parseStop.mday,
  1737. &parseStop.hour,
  1738. &parseStop.min,
  1739. &parseStop.sec,
  1740. &parseStop.minSec,
  1741. &parseStop.tz_hour,
  1742. &parseStop.tz_min);
  1743. }
  1744. }
  1745. else
  1746. {
  1747. // Original data without mini second
  1748. if(strstr((char*)stop, "Z") != NULL)
  1749. {
  1750. // Original data with Z
  1751. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1752. &parseStop.year,
  1753. &parseStop.month,
  1754. &parseStop.mday,
  1755. &parseStop.hour,
  1756. &parseStop.min,
  1757. &parseStop.sec);
  1758. }
  1759. else
  1760. {
  1761. // Original data without Z
  1762. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1763. &parseStop.year,
  1764. &parseStop.month,
  1765. &parseStop.mday,
  1766. &parseStop.hour,
  1767. &parseStop.min,
  1768. &parseStop.sec,
  1769. &parseStop.tz_hour,
  1770. &parseStop.tz_min);
  1771. }
  1772. }
  1773. // Calculate date time difference
  1774. if((parseStart.scanedElement >=6) &&
  1775. (parseStop.scanedElement >=6))
  1776. {
  1777. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1778. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1779. tmStart.tm_year = parseStart.year - 1900;
  1780. tmStart.tm_mon = parseStart.month - 1;
  1781. tmStart.tm_mday = parseStart.mday;
  1782. tmStart.tm_hour = parseStart.hour;
  1783. tmStart.tm_min = parseStart.min;
  1784. tmStart.tm_sec = parseStart.sec;
  1785. tmStart.tm_gmtoff = 0;
  1786. tbStart.time = mktime(&tmStart);
  1787. tbStart.timezone = 0;
  1788. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1789. tmStop.tm_year = parseStop.year - 1900;
  1790. tmStop.tm_mon = parseStop.month - 1;
  1791. tmStop.tm_mday = parseStop.mday;
  1792. tmStop.tm_hour = parseStop.hour;
  1793. tmStop.tm_min = parseStop.min;
  1794. tmStop.tm_sec = parseStop.sec;
  1795. tmStop.tm_gmtoff = 0;
  1796. tbStop.time = mktime(&tmStop);
  1797. tbStop.timezone = 0;
  1798. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1799. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1800. //DEBUG_INFO("getStartStop(): %d\n", result);
  1801. }
  1802. else
  1803. {
  1804. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1805. }
  1806. return result;
  1807. }
  1808. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1809. {
  1810. FILE *fp;
  1811. char profileFileName[128];
  1812. char *line = NULL;
  1813. size_t len = 0;
  1814. time_t CurrentTime;
  1815. struct tm *tmComposite;
  1816. struct StructChargingProfile maxProfile;
  1817. struct StructChargingProfile compositeProfile;
  1818. uint8_t limitMax=0;
  1819. int compositePeriodIdx = 0;
  1820. CurrentTime = time(NULL);
  1821. tmComposite=localtime(&CurrentTime);
  1822. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1823. if(isUnitA)
  1824. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1825. else
  1826. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1827. compositeProfile.ChargingSchedule.Duration = durationReq;
  1828. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1829. {
  1830. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1831. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1832. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1833. }
  1834. compositeProfile.ChargingProfileId = 0;
  1835. compositeProfile.StackLevel = 99 ;
  1836. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1837. maxProfile.ChargingProfileId = -1;
  1838. maxProfile.ChargingSchedule.Duration = -1;
  1839. system("rm -f /tmp/*.json");
  1840. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1841. // Search max profile
  1842. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1843. if((access(profileFileName, F_OK))!=-1)
  1844. {
  1845. fp = fopen(profileFileName, "r");
  1846. while(getline(&line, &len, fp) != -1)
  1847. {
  1848. json_object *obj = NULL;
  1849. obj = json_tokener_parse(line);
  1850. if(is_error(obj))
  1851. {
  1852. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1853. }
  1854. else
  1855. {
  1856. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1857. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1858. )
  1859. {
  1860. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1861. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1862. )
  1863. {
  1864. struct tm tmFrom, tmTo;
  1865. struct timeb tbFrom, tbTo;
  1866. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1867. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1868. {
  1869. tmFrom.tm_year -= 1900;
  1870. tmFrom.tm_mon -= 1;
  1871. tbFrom.time = mktime(&tmFrom);
  1872. tmTo.tm_year -= 1900;
  1873. tmTo.tm_mon -= 1;
  1874. tbTo.time = mktime(&tmTo);
  1875. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1876. {
  1877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1878. {
  1879. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1880. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1881. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1882. }
  1883. if(maxProfile.ChargingProfileId == -1)
  1884. DEBUG_INFO("MaxProfile found.\n");
  1885. else
  1886. DEBUG_INFO("MaxProfile updated.\n");
  1887. // Required item
  1888. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1889. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1890. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1891. if(isUnitA)
  1892. {
  1893. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1894. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1895. {
  1896. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1897. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1898. 3:
  1899. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1900. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1901. }
  1902. }
  1903. else
  1904. {
  1905. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1906. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1907. {
  1908. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1909. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1910. 3:
  1911. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1912. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1913. }
  1914. }
  1915. // Optional item
  1916. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1917. {
  1918. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1919. }
  1920. else
  1921. {
  1922. sprintf((char*)maxProfile.ValidFrom, " ");
  1923. }
  1924. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1925. {
  1926. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1927. }
  1928. else
  1929. {
  1930. sprintf((char*)maxProfile.ValidTo, " ");
  1931. }
  1932. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1933. {
  1934. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1935. }
  1936. else
  1937. {
  1938. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1939. }
  1940. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1941. {
  1942. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1943. }
  1944. else
  1945. {
  1946. maxProfile.TransactionId = -1;
  1947. }
  1948. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1949. {
  1950. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1951. }
  1952. else
  1953. {
  1954. maxProfile.ChargingSchedule.Duration = 86400;
  1955. }
  1956. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1957. {
  1958. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1959. }
  1960. else
  1961. {
  1962. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1963. }
  1964. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1965. {
  1966. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1967. }
  1968. else
  1969. {
  1970. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1971. }
  1972. }
  1973. }
  1974. }
  1975. else
  1976. {
  1977. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1978. {
  1979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1980. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1981. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1982. }
  1983. if(maxProfile.ChargingProfileId == -1)
  1984. DEBUG_INFO("MaxProfile found.\n");
  1985. else
  1986. DEBUG_INFO("MaxProfile updated.\n");
  1987. // Required item
  1988. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1989. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1990. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1991. if(isUnitA)
  1992. {
  1993. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1994. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1995. {
  1996. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1997. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1998. 3:
  1999. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2001. }
  2002. }
  2003. else
  2004. {
  2005. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2006. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2007. {
  2008. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2009. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2010. 3:
  2011. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2012. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2013. }
  2014. }
  2015. // Optional item
  2016. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2017. {
  2018. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2019. }
  2020. else
  2021. {
  2022. sprintf((char*)maxProfile.ValidFrom, " ");
  2023. }
  2024. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2025. {
  2026. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2027. }
  2028. else
  2029. {
  2030. sprintf((char*)maxProfile.ValidTo, " ");
  2031. }
  2032. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2033. {
  2034. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2035. }
  2036. else
  2037. {
  2038. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2039. }
  2040. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2041. {
  2042. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2043. }
  2044. else
  2045. {
  2046. maxProfile.TransactionId = -1;
  2047. }
  2048. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2049. {
  2050. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2051. }
  2052. else
  2053. {
  2054. maxProfile.ChargingSchedule.Duration = 86400;
  2055. }
  2056. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2057. {
  2058. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2059. }
  2060. else
  2061. {
  2062. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2063. }
  2064. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2065. {
  2066. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2067. }
  2068. else
  2069. {
  2070. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2071. }
  2072. }
  2073. }
  2074. }
  2075. json_object_put(obj);
  2076. }
  2077. fclose(fp);
  2078. /*
  2079. if(maxProfile.ChargingProfileId !=-1)
  2080. {
  2081. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2082. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2083. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2084. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2085. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2086. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2087. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2088. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2089. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2090. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2091. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2092. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2093. {
  2094. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2095. {
  2096. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2097. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2098. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2099. }
  2100. }
  2101. }
  2102. else
  2103. DEBUG_INFO("MaxProfile not found.\n");
  2104. DEBUG_INFO("------------------------------------\n");*/
  2105. }
  2106. if(maxProfile.ChargingProfileId != -1)
  2107. {
  2108. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2109. {
  2110. if(maxProfile.ChargingSchedule.Duration != -1)
  2111. {
  2112. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2113. 0:
  2114. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2115. }
  2116. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2117. {
  2118. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2119. {
  2120. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2121. 0:
  2122. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2123. if(idxPeriod > 0)
  2124. {
  2125. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2126. {
  2127. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2128. }
  2129. }
  2130. }
  2131. }
  2132. }
  2133. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2134. {
  2135. if(maxProfile.ChargingSchedule.Duration != -1)
  2136. {
  2137. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2138. }
  2139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2140. {
  2141. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2142. {
  2143. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2144. if(idxPeriod > 0)
  2145. {
  2146. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2147. {
  2148. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2149. }
  2150. }
  2151. }
  2152. }
  2153. }
  2154. else
  2155. {
  2156. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2157. {
  2158. if(maxProfile.ChargingSchedule.Duration != -1)
  2159. {
  2160. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2161. 0:
  2162. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2163. }
  2164. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2165. {
  2166. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2167. {
  2168. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2169. 0:
  2170. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2171. if(idxPeriod > 0)
  2172. {
  2173. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2174. {
  2175. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2176. }
  2177. }
  2178. }
  2179. }
  2180. }
  2181. else
  2182. {
  2183. if(maxProfile.ChargingSchedule.Duration != -1)
  2184. {
  2185. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2186. 0:
  2187. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2188. }
  2189. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2190. {
  2191. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2192. {
  2193. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2194. 0:
  2195. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2196. if(idxPeriod > 0)
  2197. {
  2198. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2199. {
  2200. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. /*
  2208. DEBUG_INFO("MaxProfile after align.\n");
  2209. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2210. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2211. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2212. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2213. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2214. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2215. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2216. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2217. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2218. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2219. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2220. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2221. {
  2222. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2223. {
  2224. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2225. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2226. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2227. }
  2228. }
  2229. DEBUG_INFO("------------------------------------\n");*/
  2230. }
  2231. // Find each profile period quantity
  2232. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2233. {
  2234. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2235. limitMax = idx+1;
  2236. }
  2237. if(maxProfile.ChargingProfileId != -1)
  2238. {
  2239. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2240. {
  2241. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2242. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2243. (maxProfile.ChargingSchedule.Duration > 0))
  2244. {
  2245. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2246. {
  2247. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2248. compositePeriodIdx++;
  2249. }
  2250. else
  2251. {
  2252. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2253. }
  2254. }
  2255. }
  2256. }
  2257. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2258. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2259. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2260. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2261. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2262. {
  2263. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2264. {
  2265. compositeProfile.ChargingProfileId = 1;
  2266. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2267. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2268. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2269. }
  2270. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2271. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2272. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2273. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2274. }
  2275. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2276. if(line)
  2277. free(line);
  2278. }
  2279. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2280. {
  2281. FILE *fp;
  2282. char profileFileName[128];
  2283. char *line = NULL;
  2284. size_t len = 0;
  2285. time_t CurrentTime;
  2286. struct tm *tmComposite;
  2287. struct StructChargingProfile maxProfile;
  2288. struct StructChargingProfile defaultTxProfile;
  2289. struct StructChargingProfile txProfile;
  2290. struct StructChargingProfile compositeProfile;
  2291. struct StructChargingSchedulePeriod tmpPeriod;
  2292. uint8_t limitMax=0;
  2293. uint8_t limitDef=0;
  2294. uint8_t limitTx=0;
  2295. int compositePeriodIdx = 0;
  2296. CurrentTime = time(NULL);
  2297. tmComposite=localtime(&CurrentTime);
  2298. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  2299. if(isUnitA)
  2300. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2301. else
  2302. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2303. compositeProfile.ChargingSchedule.Duration = durationReq;
  2304. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2305. {
  2306. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2307. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2308. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2309. }
  2310. compositeProfile.ChargingProfileId = 0;
  2311. compositeProfile.StackLevel = 99 ;
  2312. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2313. maxProfile.ChargingProfileId = -1;
  2314. defaultTxProfile.ChargingProfileId = -1;
  2315. txProfile.ChargingProfileId = -1;
  2316. maxProfile.ChargingSchedule.Duration = -1;
  2317. defaultTxProfile.ChargingSchedule.Duration = -1;
  2318. txProfile.ChargingSchedule.Duration = -1;
  2319. system("rm -f /tmp/*.json");
  2320. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2321. /*
  2322. * Search valid charging profile
  2323. */
  2324. //DEBUG_INFO("====================================\n");
  2325. // Search tx profile
  2326. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2327. if((access(profileFileName, F_OK))!=-1)
  2328. {
  2329. fp = fopen(profileFileName, "r");
  2330. while(getline(&line, &len, fp) != -1)
  2331. {
  2332. json_object *obj = NULL;
  2333. obj = json_tokener_parse(line);
  2334. if(is_error(obj))
  2335. {
  2336. DEBUG_ERROR("Parse txProfile from file error.\n");
  2337. }
  2338. else
  2339. {
  2340. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2341. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2342. )
  2343. {
  2344. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2345. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2346. )
  2347. {
  2348. struct tm tmFrom, tmTo;
  2349. struct timeb tbFrom, tbTo;
  2350. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2351. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2352. {
  2353. tmFrom.tm_year -= 1900;
  2354. tmFrom.tm_mon -= 1;
  2355. tbFrom.time = mktime(&tmFrom);
  2356. tmTo.tm_year -= 1900;
  2357. tmTo.tm_mon -= 1;
  2358. tbTo.time = mktime(&tmTo);
  2359. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2360. {
  2361. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2362. {
  2363. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2364. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2365. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2366. }
  2367. if(txProfile.ChargingProfileId == -1)
  2368. DEBUG_INFO("TxProfile found.\n");
  2369. else
  2370. DEBUG_INFO("TxProfile updated.\n");
  2371. // Required item
  2372. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2373. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2374. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2375. if(isUnitA)
  2376. {
  2377. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2378. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2379. {
  2380. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2381. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2382. 3:
  2383. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2384. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2385. }
  2386. }
  2387. else
  2388. {
  2389. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2390. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2391. {
  2392. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2393. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2394. 3:
  2395. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2396. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2397. }
  2398. }
  2399. // Optional item
  2400. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2401. {
  2402. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2403. }
  2404. else
  2405. {
  2406. sprintf((char*)txProfile.ValidFrom, " ");
  2407. }
  2408. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2409. {
  2410. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2411. }
  2412. else
  2413. {
  2414. sprintf((char*)txProfile.ValidTo, " ");
  2415. }
  2416. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2417. {
  2418. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2419. }
  2420. else
  2421. {
  2422. sprintf((char*)txProfile.RecurrencyKind, " ");
  2423. }
  2424. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2425. {
  2426. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2427. }
  2428. else
  2429. {
  2430. txProfile.TransactionId = -1;
  2431. }
  2432. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2433. {
  2434. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2435. }
  2436. else
  2437. {
  2438. txProfile.ChargingSchedule.Duration = 86400;
  2439. }
  2440. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2441. {
  2442. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2443. }
  2444. else
  2445. {
  2446. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2447. }
  2448. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2449. {
  2450. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2451. }
  2452. else
  2453. {
  2454. txProfile.ChargingSchedule.MinChargingRate = -1;
  2455. }
  2456. }
  2457. }
  2458. }
  2459. else
  2460. {
  2461. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2462. {
  2463. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2464. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2465. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2466. }
  2467. if(txProfile.ChargingProfileId == -1)
  2468. DEBUG_INFO("TxProfile found.\n");
  2469. else
  2470. DEBUG_INFO("TxProfile updated.\n");
  2471. // Required item
  2472. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2473. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2474. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2475. if(isUnitA)
  2476. {
  2477. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2478. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2479. {
  2480. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2481. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2482. 3:
  2483. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2484. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2485. }
  2486. }
  2487. else
  2488. {
  2489. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2490. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2491. {
  2492. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2493. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2494. 3:
  2495. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2496. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2497. }
  2498. }
  2499. // Optional item
  2500. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2501. {
  2502. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2503. }
  2504. else
  2505. {
  2506. sprintf((char*)txProfile.ValidFrom, " ");
  2507. }
  2508. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2509. {
  2510. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2511. }
  2512. else
  2513. {
  2514. sprintf((char*)txProfile.ValidTo, " ");
  2515. }
  2516. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2517. {
  2518. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2519. }
  2520. else
  2521. {
  2522. sprintf((char*)txProfile.RecurrencyKind, " ");
  2523. }
  2524. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2525. {
  2526. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2527. }
  2528. else
  2529. {
  2530. txProfile.TransactionId = -1;
  2531. }
  2532. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2533. {
  2534. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2535. }
  2536. else
  2537. {
  2538. txProfile.ChargingSchedule.Duration = 86400;
  2539. }
  2540. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2541. {
  2542. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2543. }
  2544. else
  2545. {
  2546. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2547. }
  2548. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2549. {
  2550. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2551. }
  2552. else
  2553. {
  2554. txProfile.ChargingSchedule.MinChargingRate = -1;
  2555. }
  2556. }
  2557. }
  2558. }
  2559. json_object_put(obj);
  2560. }
  2561. fclose(fp);
  2562. /*
  2563. if(txProfile.ChargingProfileId != -1)
  2564. {
  2565. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2566. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2567. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2568. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2569. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2570. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2571. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2572. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2573. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2574. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2575. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2576. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2577. {
  2578. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2579. {
  2580. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2581. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2582. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2583. }
  2584. }
  2585. }
  2586. else
  2587. DEBUG_INFO("TxProfile not found.\n");*/
  2588. }
  2589. // Search default tx profile
  2590. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2591. if((access(profileFileName, F_OK))==-1)
  2592. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2593. if((access(profileFileName, F_OK))!=-1)
  2594. {
  2595. fp = fopen(profileFileName, "r");
  2596. while(getline(&line, &len, fp) != -1)
  2597. {
  2598. json_object *obj = NULL;
  2599. obj = json_tokener_parse(line);
  2600. if(is_error(obj))
  2601. {
  2602. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2603. }
  2604. else
  2605. {
  2606. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2607. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2608. )
  2609. {
  2610. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2611. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2612. )
  2613. {
  2614. struct tm tmFrom, tmTo;
  2615. struct timeb tbFrom, tbTo;
  2616. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2617. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2618. {
  2619. tmFrom.tm_year -= 1900;
  2620. tmFrom.tm_mon -= 1;
  2621. tbFrom.time = mktime(&tmFrom);
  2622. tmTo.tm_year -= 1900;
  2623. tmTo.tm_mon -= 1;
  2624. tbTo.time = mktime(&tmTo);
  2625. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2626. {
  2627. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2628. {
  2629. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2630. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2631. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2632. }
  2633. if(defaultTxProfile.ChargingProfileId == -1)
  2634. DEBUG_INFO("TxDefaultProfile found.\n");
  2635. else
  2636. DEBUG_INFO("TxDefaultProfile updated.\n");
  2637. // Required item
  2638. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2639. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2640. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2641. if(isUnitA)
  2642. {
  2643. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2644. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2645. {
  2646. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2647. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2648. 3:
  2649. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2650. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2651. }
  2652. }
  2653. else
  2654. {
  2655. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2656. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2657. {
  2658. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2659. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2660. 3:
  2661. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2662. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2663. }
  2664. }
  2665. // Optional item
  2666. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2667. {
  2668. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2669. }
  2670. else
  2671. {
  2672. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2673. }
  2674. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2675. {
  2676. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2677. }
  2678. else
  2679. {
  2680. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2681. }
  2682. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2683. {
  2684. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2685. }
  2686. else
  2687. {
  2688. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2689. }
  2690. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2691. {
  2692. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2693. }
  2694. else
  2695. {
  2696. defaultTxProfile.TransactionId = -1;
  2697. }
  2698. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2699. {
  2700. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2701. }
  2702. else
  2703. {
  2704. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2705. }
  2706. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2707. {
  2708. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2709. }
  2710. else
  2711. {
  2712. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2713. }
  2714. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2715. {
  2716. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2717. }
  2718. else
  2719. {
  2720. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2721. }
  2722. }
  2723. }
  2724. }
  2725. else
  2726. {
  2727. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2728. {
  2729. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2730. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2731. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2732. }
  2733. if(defaultTxProfile.ChargingProfileId == -1)
  2734. DEBUG_INFO("TxDefaultProfile found.\n");
  2735. else
  2736. DEBUG_INFO("TxDefaultProfile updated.\n");
  2737. // Required item
  2738. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2739. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2740. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2741. if(isUnitA)
  2742. {
  2743. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2744. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2745. {
  2746. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2747. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2748. 3:
  2749. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2750. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2751. }
  2752. }
  2753. else
  2754. {
  2755. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2756. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2757. {
  2758. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2759. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2760. 3:
  2761. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2762. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2763. }
  2764. }
  2765. // Optional item
  2766. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2767. {
  2768. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2769. }
  2770. else
  2771. {
  2772. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2773. }
  2774. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2775. {
  2776. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2777. }
  2778. else
  2779. {
  2780. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2781. }
  2782. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2783. {
  2784. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2785. }
  2786. else
  2787. {
  2788. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2789. }
  2790. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2791. {
  2792. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2793. }
  2794. else
  2795. {
  2796. defaultTxProfile.TransactionId = -1;
  2797. }
  2798. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2799. {
  2800. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2801. }
  2802. else
  2803. {
  2804. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2805. }
  2806. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2807. {
  2808. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2809. }
  2810. else
  2811. {
  2812. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2813. }
  2814. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2815. {
  2816. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2817. }
  2818. else
  2819. {
  2820. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2821. }
  2822. }
  2823. }
  2824. }
  2825. json_object_put(obj);
  2826. }
  2827. fclose(fp);
  2828. /*
  2829. if(defaultTxProfile.ChargingProfileId != -1)
  2830. {
  2831. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2832. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2833. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2834. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2835. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2836. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2837. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2838. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2839. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2840. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2841. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2842. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2843. {
  2844. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2845. {
  2846. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2847. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2848. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2849. }
  2850. }
  2851. }
  2852. else
  2853. DEBUG_INFO("TxDefaultProfile not found.\n");
  2854. DEBUG_INFO("------------------------------------\n");*/
  2855. }
  2856. // Search max profile
  2857. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2858. if((access(profileFileName, F_OK))!=-1)
  2859. {
  2860. fp = fopen(profileFileName, "r");
  2861. while(getline(&line, &len, fp) != -1)
  2862. {
  2863. json_object *obj = NULL;
  2864. obj = json_tokener_parse(line);
  2865. if(is_error(obj))
  2866. {
  2867. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2868. }
  2869. else
  2870. {
  2871. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2872. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2873. )
  2874. {
  2875. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2876. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2877. )
  2878. {
  2879. struct tm tmFrom, tmTo;
  2880. struct timeb tbFrom, tbTo;
  2881. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2882. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2883. {
  2884. tmFrom.tm_year -= 1900;
  2885. tmFrom.tm_mon -= 1;
  2886. tbFrom.time = mktime(&tmFrom);
  2887. tmTo.tm_year -= 1900;
  2888. tmTo.tm_mon -= 1;
  2889. tbTo.time = mktime(&tmTo);
  2890. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2891. {
  2892. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2893. {
  2894. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2895. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2896. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2897. }
  2898. if(maxProfile.ChargingProfileId == -1)
  2899. DEBUG_INFO("MaxProfile found.\n");
  2900. else
  2901. DEBUG_INFO("MaxProfile updated.\n");
  2902. // Required item
  2903. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2904. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2905. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2906. if(isUnitA)
  2907. {
  2908. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2909. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2910. {
  2911. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2912. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2913. 3:
  2914. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2915. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2916. }
  2917. }
  2918. else
  2919. {
  2920. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2921. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2922. {
  2923. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2924. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2925. 3:
  2926. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2927. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2928. }
  2929. }
  2930. // Optional item
  2931. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2932. {
  2933. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2934. }
  2935. else
  2936. {
  2937. sprintf((char*)maxProfile.ValidFrom, " ");
  2938. }
  2939. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2940. {
  2941. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2942. }
  2943. else
  2944. {
  2945. sprintf((char*)maxProfile.ValidTo, " ");
  2946. }
  2947. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2948. {
  2949. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2950. }
  2951. else
  2952. {
  2953. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2954. }
  2955. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2956. {
  2957. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2958. }
  2959. else
  2960. {
  2961. maxProfile.TransactionId = -1;
  2962. }
  2963. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2964. {
  2965. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2966. }
  2967. else
  2968. {
  2969. maxProfile.ChargingSchedule.Duration = 86400;
  2970. }
  2971. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2972. {
  2973. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2974. }
  2975. else
  2976. {
  2977. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2978. }
  2979. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2980. {
  2981. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2982. }
  2983. else
  2984. {
  2985. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2986. }
  2987. }
  2988. }
  2989. }
  2990. else
  2991. {
  2992. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2993. {
  2994. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2995. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2996. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2997. }
  2998. if(maxProfile.ChargingProfileId == -1)
  2999. DEBUG_INFO("MaxProfile found.\n");
  3000. else
  3001. DEBUG_INFO("MaxProfile updated.\n");
  3002. // Required item
  3003. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3004. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3005. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3006. if(isUnitA)
  3007. {
  3008. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3009. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3010. {
  3011. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3012. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3013. 3:
  3014. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3015. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3016. }
  3017. }
  3018. else
  3019. {
  3020. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3021. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3022. {
  3023. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3024. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3025. 3:
  3026. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3027. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  3028. }
  3029. }
  3030. // Optional item
  3031. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3032. {
  3033. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3034. }
  3035. else
  3036. {
  3037. sprintf((char*)maxProfile.ValidFrom, " ");
  3038. }
  3039. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3040. {
  3041. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3042. }
  3043. else
  3044. {
  3045. sprintf((char*)maxProfile.ValidTo, " ");
  3046. }
  3047. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3048. {
  3049. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3050. }
  3051. else
  3052. {
  3053. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3054. }
  3055. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3056. {
  3057. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3058. }
  3059. else
  3060. {
  3061. maxProfile.TransactionId = -1;
  3062. }
  3063. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3064. {
  3065. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3066. }
  3067. else
  3068. {
  3069. maxProfile.ChargingSchedule.Duration = 86400;
  3070. }
  3071. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3072. {
  3073. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3074. }
  3075. else
  3076. {
  3077. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3078. }
  3079. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3080. {
  3081. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3082. }
  3083. else
  3084. {
  3085. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3086. }
  3087. }
  3088. }
  3089. }
  3090. json_object_put(obj);
  3091. }
  3092. fclose(fp);
  3093. /*
  3094. if(maxProfile.ChargingProfileId !=-1)
  3095. {
  3096. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3097. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3098. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3099. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3100. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3101. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3102. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3103. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3104. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3105. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3106. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3107. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3108. {
  3109. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3110. {
  3111. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3112. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3113. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3114. }
  3115. }
  3116. }
  3117. else
  3118. DEBUG_INFO("MaxProfile not found.\n");
  3119. DEBUG_INFO("------------------------------------\n");*/
  3120. }
  3121. /*
  3122. * Align found profile start schedule & periods
  3123. */
  3124. //DEBUG_INFO("====================================\n");
  3125. /*
  3126. // For local test usage, force modify found profile start schedule info
  3127. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  3128. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  3129. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  3130. */
  3131. if(txProfile.ChargingProfileId != -1)
  3132. {
  3133. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3134. {
  3135. if(txProfile.ChargingSchedule.Duration != -1)
  3136. {
  3137. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3138. 0:
  3139. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3140. }
  3141. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3142. {
  3143. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3144. {
  3145. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3146. 0:
  3147. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3148. if(idxPeriod > 0)
  3149. {
  3150. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3151. {
  3152. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3153. }
  3154. }
  3155. }
  3156. }
  3157. }
  3158. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3159. {
  3160. if(txProfile.ChargingSchedule.Duration != -1)
  3161. {
  3162. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3163. 0:
  3164. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3165. }
  3166. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3167. {
  3168. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3169. {
  3170. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3171. 0:
  3172. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3173. if(idxPeriod > 0)
  3174. {
  3175. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3176. {
  3177. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3178. }
  3179. }
  3180. }
  3181. }
  3182. }
  3183. else
  3184. {
  3185. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3186. {
  3187. if(txProfile.ChargingSchedule.Duration != -1)
  3188. {
  3189. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3190. 0:
  3191. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3192. }
  3193. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3194. {
  3195. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3196. {
  3197. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3198. 0:
  3199. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3200. if(idxPeriod > 0)
  3201. {
  3202. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3203. {
  3204. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3205. }
  3206. }
  3207. }
  3208. }
  3209. }
  3210. else
  3211. {
  3212. if(txProfile.ChargingSchedule.Duration != -1)
  3213. {
  3214. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3215. 0:
  3216. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3217. }
  3218. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3219. {
  3220. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3221. {
  3222. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3223. 0:
  3224. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3225. if(idxPeriod > 0)
  3226. {
  3227. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3228. {
  3229. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3230. }
  3231. }
  3232. }
  3233. }
  3234. }
  3235. }
  3236. /*
  3237. DEBUG_INFO("txProfile after align.\n");
  3238. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3239. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3240. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3241. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3242. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3243. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3244. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3245. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3246. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3247. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3248. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3249. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3250. {
  3251. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3252. {
  3253. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3254. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3255. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3256. }
  3257. }*/
  3258. }
  3259. if(defaultTxProfile.ChargingProfileId != -1)
  3260. {
  3261. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3262. {
  3263. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3264. {
  3265. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3266. 0:
  3267. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3268. }
  3269. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3270. {
  3271. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3272. {
  3273. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3274. 0:
  3275. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3276. if(idxPeriod > 0)
  3277. {
  3278. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3279. {
  3280. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3281. }
  3282. }
  3283. }
  3284. }
  3285. }
  3286. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3287. {
  3288. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3289. {
  3290. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3291. 0:
  3292. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3293. }
  3294. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3295. {
  3296. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3297. {
  3298. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3299. 0:
  3300. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3301. if(idxPeriod > 0)
  3302. {
  3303. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3304. {
  3305. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3306. }
  3307. }
  3308. }
  3309. }
  3310. }
  3311. else
  3312. {
  3313. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3314. {
  3315. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3316. {
  3317. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3318. 0:
  3319. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3320. }
  3321. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3322. {
  3323. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3324. {
  3325. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3326. 0:
  3327. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3328. if(idxPeriod > 0)
  3329. {
  3330. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3331. {
  3332. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3333. }
  3334. }
  3335. }
  3336. }
  3337. }
  3338. else
  3339. {
  3340. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3341. {
  3342. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3343. 0:
  3344. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3345. }
  3346. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3347. {
  3348. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3349. {
  3350. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3351. 0:
  3352. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3353. if(idxPeriod > 0)
  3354. {
  3355. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3356. {
  3357. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3358. }
  3359. }
  3360. }
  3361. }
  3362. }
  3363. }
  3364. /*
  3365. DEBUG_INFO("defaultTxProfile after align.\n");
  3366. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3367. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3368. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3369. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3370. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3371. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3372. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3373. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3374. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3375. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3376. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3377. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3378. {
  3379. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3380. {
  3381. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3382. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3383. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3384. }
  3385. }
  3386. DEBUG_INFO("------------------------------------\n");*/
  3387. }
  3388. if(maxProfile.ChargingProfileId != -1)
  3389. {
  3390. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3391. {
  3392. if(maxProfile.ChargingSchedule.Duration != -1)
  3393. {
  3394. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3395. 0:
  3396. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3397. }
  3398. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3399. {
  3400. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3401. {
  3402. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3403. 0:
  3404. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3405. if(idxPeriod > 0)
  3406. {
  3407. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3408. {
  3409. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3410. }
  3411. }
  3412. }
  3413. }
  3414. }
  3415. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3416. {
  3417. if(maxProfile.ChargingSchedule.Duration != -1)
  3418. {
  3419. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3420. 0:
  3421. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3422. }
  3423. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3424. {
  3425. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3426. {
  3427. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3428. 0:
  3429. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3430. if(idxPeriod > 0)
  3431. {
  3432. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3433. {
  3434. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3435. }
  3436. }
  3437. }
  3438. }
  3439. }
  3440. else
  3441. {
  3442. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3443. {
  3444. if(maxProfile.ChargingSchedule.Duration != -1)
  3445. {
  3446. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3447. 0:
  3448. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3449. }
  3450. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3451. {
  3452. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3453. {
  3454. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3455. 0:
  3456. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3457. if(idxPeriod > 0)
  3458. {
  3459. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3460. {
  3461. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3462. }
  3463. }
  3464. }
  3465. }
  3466. }
  3467. else
  3468. {
  3469. if(maxProfile.ChargingSchedule.Duration != -1)
  3470. {
  3471. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3472. 0:
  3473. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3474. }
  3475. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3476. {
  3477. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3478. {
  3479. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3480. 0:
  3481. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3482. if(idxPeriod > 0)
  3483. {
  3484. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3485. {
  3486. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3487. }
  3488. }
  3489. }
  3490. }
  3491. }
  3492. }
  3493. /*
  3494. DEBUG_INFO("MaxProfile after align.\n");
  3495. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3496. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3497. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3498. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3499. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3500. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3501. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3502. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3503. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3504. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3505. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3506. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3507. {
  3508. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3509. {
  3510. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3511. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3512. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3513. }
  3514. }
  3515. DEBUG_INFO("------------------------------------\n");*/
  3516. }
  3517. /*
  3518. * Merge to conposite schedule
  3519. */
  3520. //DEBUG_INFO("====================================\n");
  3521. // Find each profile period quantity
  3522. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3523. {
  3524. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3525. limitMax = idx+1;
  3526. }
  3527. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3528. {
  3529. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3530. limitDef = idx+1;
  3531. }
  3532. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3533. {
  3534. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3535. limitTx = idx+1;
  3536. }
  3537. // TxProfile found, composite schedule based on it
  3538. if(txProfile.ChargingProfileId != -1)
  3539. {
  3540. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3541. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3542. {
  3543. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3544. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3545. (txProfile.ChargingSchedule.Duration > 0))
  3546. {
  3547. if(maxProfile.ChargingProfileId != -1)
  3548. {
  3549. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3550. {
  3551. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3552. {
  3553. if((maxProfile.ChargingSchedule.Duration > 0))
  3554. {
  3555. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3556. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3557. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3558. }
  3559. else
  3560. {
  3561. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3562. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3563. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3564. }
  3565. }
  3566. if(idxMaxPeriod == (limitMax-1))
  3567. {
  3568. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3569. {
  3570. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3571. {
  3572. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3573. compositePeriodIdx++;
  3574. }
  3575. else
  3576. {
  3577. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3578. }
  3579. }
  3580. }
  3581. }
  3582. }
  3583. else
  3584. {
  3585. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3586. {
  3587. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3588. compositePeriodIdx++;
  3589. }
  3590. else
  3591. {
  3592. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3593. }
  3594. }
  3595. }
  3596. if(idxTxPeriod == (limitTx-1))
  3597. {
  3598. if(defaultTxProfile.ChargingProfileId != -1)
  3599. {
  3600. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3601. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3602. {
  3603. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3604. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3605. (defaultTxProfile.ChargingSchedule.Duration>0))
  3606. {
  3607. if(maxProfile.ChargingProfileId != -1)
  3608. {
  3609. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3610. {
  3611. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3612. {
  3613. if((maxProfile.ChargingSchedule.Duration > 0))
  3614. {
  3615. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3616. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3617. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3618. }
  3619. else
  3620. {
  3621. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3622. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3623. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3624. }
  3625. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3626. {
  3627. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3628. {
  3629. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3630. compositePeriodIdx++;
  3631. }
  3632. else
  3633. {
  3634. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3635. }
  3636. }
  3637. // Delete duplicate period
  3638. if(compositePeriodIdx > 1)
  3639. {
  3640. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3641. {
  3642. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3643. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3644. compositePeriodIdx -= 1;
  3645. }
  3646. }
  3647. }
  3648. else
  3649. {
  3650. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3651. {
  3652. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3653. compositePeriodIdx++;
  3654. }
  3655. else
  3656. {
  3657. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3658. }
  3659. break;
  3660. }
  3661. }
  3662. }
  3663. else
  3664. {
  3665. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3666. {
  3667. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3668. compositePeriodIdx++;
  3669. }
  3670. else
  3671. {
  3672. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3673. }
  3674. }
  3675. }
  3676. }
  3677. }
  3678. }
  3679. }
  3680. }
  3681. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3682. else if(defaultTxProfile.ChargingProfileId != -1)
  3683. {
  3684. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3685. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3686. {
  3687. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3688. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3689. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3690. {
  3691. if(maxProfile.ChargingProfileId != -1)
  3692. {
  3693. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3694. {
  3695. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3696. {
  3697. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3698. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3699. if((maxProfile.ChargingSchedule.Duration > 0))
  3700. {
  3701. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3702. }
  3703. else
  3704. {
  3705. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3706. }
  3707. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3708. {
  3709. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3710. {
  3711. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3712. compositePeriodIdx++;
  3713. }
  3714. else
  3715. {
  3716. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3717. }
  3718. }
  3719. // Delete duplicate period
  3720. if(compositePeriodIdx > 1)
  3721. {
  3722. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3723. {
  3724. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3725. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3726. compositePeriodIdx -= 1;
  3727. }
  3728. }
  3729. }
  3730. else
  3731. {
  3732. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3733. {
  3734. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3735. compositePeriodIdx++;
  3736. }
  3737. else
  3738. {
  3739. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3740. }
  3741. break;
  3742. }
  3743. }
  3744. }
  3745. else
  3746. {
  3747. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3748. {
  3749. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3750. compositePeriodIdx++;
  3751. }
  3752. else
  3753. {
  3754. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3755. }
  3756. }
  3757. }
  3758. }
  3759. }
  3760. // Fill other period by MaxProfile
  3761. if(maxProfile.ChargingProfileId != -1)
  3762. {
  3763. if(compositePeriodIdx==0)
  3764. {
  3765. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3766. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3767. {
  3768. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3769. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3770. (maxProfile.ChargingSchedule.Duration > 0))
  3771. {
  3772. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3773. {
  3774. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3775. compositePeriodIdx++;
  3776. }
  3777. else
  3778. {
  3779. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3780. }
  3781. }
  3782. }
  3783. }
  3784. else
  3785. {
  3786. int lastCompositePeriodIdx = compositePeriodIdx;
  3787. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3788. {
  3789. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3790. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3791. (maxProfile.ChargingSchedule.Duration > 0))
  3792. {
  3793. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3794. {
  3795. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3796. {
  3797. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3798. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3799. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3800. }
  3801. else
  3802. {
  3803. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3804. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3805. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3806. }
  3807. }
  3808. if(tmpPeriod.Limit != -1)
  3809. {
  3810. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3811. {
  3812. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3813. {
  3814. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3815. compositePeriodIdx++;
  3816. }
  3817. else
  3818. {
  3819. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3820. }
  3821. }
  3822. // Delete duplicate period
  3823. if(compositePeriodIdx > 1)
  3824. {
  3825. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3826. {
  3827. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3828. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3829. compositePeriodIdx -= 1;
  3830. }
  3831. }
  3832. }
  3833. }
  3834. }
  3835. }
  3836. }
  3837. compositeProfile.ChargingSchedule.Duration = durationReq;
  3838. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3839. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3840. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3841. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3842. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3843. {
  3844. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3845. {
  3846. compositeProfile.ChargingProfileId = 1;
  3847. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3848. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3849. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3850. }
  3851. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3852. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3853. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3854. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3855. }
  3856. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3857. if(line)
  3858. free(line);
  3859. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3860. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3861. }
  3862. //==========================================
  3863. // Init all share memory
  3864. //==========================================
  3865. int InitShareMemory()
  3866. {
  3867. int result = PASS;
  3868. int MeterSMId;
  3869. //creat ShmSysConfigAndInfo
  3870. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3871. {
  3872. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3873. result = FAIL;
  3874. }
  3875. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3876. {
  3877. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3878. result = FAIL;
  3879. }
  3880. else
  3881. {}
  3882. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3883. {
  3884. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3885. result = FAIL;
  3886. }
  3887. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3888. {
  3889. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3890. result = FAIL;
  3891. }
  3892. else
  3893. {}
  3894. //creat ShmPsuData
  3895. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3896. {
  3897. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3898. result = FAIL;
  3899. }
  3900. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3901. {
  3902. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3903. result = FAIL;
  3904. }
  3905. else
  3906. {}
  3907. //creat ShmOCPP16Data
  3908. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3909. {
  3910. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3911. result = FAIL;
  3912. }
  3913. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3914. {
  3915. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3916. result = FAIL;
  3917. }
  3918. else
  3919. {}
  3920. /****************************** For Initial Settings************************************************/
  3921. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3922. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3923. // allocate Configuration memory address
  3924. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3925. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3926. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3927. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3928. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3929. //offline MeterValue Interval
  3930. TempMeterValueInterval = 0;
  3931. return result;
  3932. }
  3933. int ProcessShareMemory()
  3934. {
  3935. int result = PASS;
  3936. if(InitShareMemory() == FAIL)
  3937. {
  3938. DEBUG_ERROR("InitShareMemory NG\n");
  3939. if(ShmStatusCodeData!=NULL)
  3940. {
  3941. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3942. }
  3943. result = FAIL;
  3944. }
  3945. // Model name parsing
  3946. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3947. {
  3948. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3949. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3950. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3951. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3952. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3953. ) // 'D' means DC
  3954. {
  3955. // DO series
  3956. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3957. {
  3958. gunTotalNumber += 1;
  3959. gunType[gun_index] = GUN_TYPE_DO;
  3960. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3961. {
  3962. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3963. {
  3964. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3965. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3966. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3967. }
  3968. }
  3969. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3970. {
  3971. case Gun_Type_Chademo:
  3972. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3973. break;
  3974. case Gun_Type_CCS_2:
  3975. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3976. break;
  3977. case Gun_Type_GB:
  3978. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3979. break;
  3980. case Gun_Type_AC:
  3981. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3982. break;
  3983. default:
  3984. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3985. break;
  3986. }
  3987. }
  3988. }
  3989. else
  3990. {
  3991. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3992. {
  3993. gunTotalNumber += 1;
  3994. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3995. {
  3996. case Gun_Type_Chademo:
  3997. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3998. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3999. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4000. {
  4001. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4002. {
  4003. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4004. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4005. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4006. }
  4007. }
  4008. break;
  4009. case Gun_Type_CCS_2:
  4010. gunType[gun_index] = GUN_TYPE_CCS;
  4011. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4012. for (int index = 0; index < CCS_QUANTITY; index++)
  4013. {
  4014. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4015. {
  4016. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4017. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4018. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4019. }
  4020. }
  4021. break;
  4022. case Gun_Type_GB:
  4023. gunType[gun_index] = GUN_TYPE_GBT;
  4024. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4025. for (int index = 0; index < GB_QUANTITY; index++)
  4026. {
  4027. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4028. {
  4029. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4030. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4031. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4032. }
  4033. }
  4034. break;
  4035. case Gun_Type_AC:
  4036. gunType[gun_index] = GUN_TYPE_AC;
  4037. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4038. for (int index = 0; index < AC_QUANTITY; index++)
  4039. {
  4040. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4041. {
  4042. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4043. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4044. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4045. }
  4046. }
  4047. break;
  4048. default:
  4049. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4050. break;
  4051. }
  4052. }
  4053. }
  4054. }
  4055. else
  4056. {
  4057. DEBUG_ERROR("Model name parsing fail.\n");
  4058. result = FAIL;
  4059. }
  4060. if(result != PASS)sleep(5);
  4061. return result;
  4062. }
  4063. void checkRemoteStart(uint8_t connectorIdInt)
  4064. {
  4065. uint8_t tempIndex;
  4066. int result = PASS;
  4067. char cmdBuf[512];
  4068. //check Transaction active
  4069. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4070. {
  4071. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4072. {
  4073. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4074. }
  4075. else
  4076. {
  4077. tempIndex = connectorIdInt -1;
  4078. }
  4079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4080. {
  4081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4082. {
  4083. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4084. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4085. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4086. {
  4087. //Reserved
  4088. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4089. }
  4090. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4091. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4092. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4093. {
  4094. //Reserved
  4095. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4096. result = FAIL;
  4097. goto end;
  4098. }
  4099. else
  4100. {
  4101. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4102. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4103. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4104. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4105. {
  4106. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4107. result = FAIL;
  4108. goto end;
  4109. }
  4110. }//END FOR ELSE
  4111. }
  4112. }// END FOR CHAdeMO_QUANTITY
  4113. }
  4114. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4115. {
  4116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4117. {
  4118. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4119. }
  4120. else
  4121. {
  4122. tempIndex = connectorIdInt -1;
  4123. }
  4124. for (int index = 0; index < CCS_QUANTITY; index++)
  4125. {
  4126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4127. {
  4128. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4129. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4130. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4131. {
  4132. //Reserved
  4133. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4134. }
  4135. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4136. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4137. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4138. {
  4139. //Reserved
  4140. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4141. result = FAIL;
  4142. goto end;
  4143. }
  4144. else
  4145. {
  4146. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4147. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4148. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4149. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4150. {
  4151. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4152. result = FAIL;
  4153. goto end;
  4154. }
  4155. }// END FOR ELSE
  4156. }
  4157. }// END FOR CCS_QUANTITY
  4158. }
  4159. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4160. {
  4161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4162. {
  4163. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4164. }
  4165. else
  4166. {
  4167. tempIndex = connectorIdInt -1;
  4168. }
  4169. for (int index = 0; index < GB_QUANTITY; index++)
  4170. {
  4171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4172. {
  4173. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4174. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4175. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4176. {
  4177. //Reserved
  4178. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4179. }
  4180. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4181. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4182. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4183. {
  4184. //Reserved
  4185. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4186. result = FAIL;
  4187. goto end;
  4188. }
  4189. else
  4190. {
  4191. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4192. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4193. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4194. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4195. {
  4196. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4197. result = FAIL;
  4198. goto end;
  4199. }
  4200. }// END FOR ELSE
  4201. }
  4202. } // END FOR GB_QUANTITY
  4203. }
  4204. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4205. {
  4206. tempIndex = connectorIdInt -1;
  4207. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4208. {
  4209. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4210. {
  4211. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4212. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4213. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4214. {
  4215. //Reserved
  4216. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4217. }
  4218. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4219. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4220. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4221. {
  4222. //Reserved
  4223. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4224. result = FAIL;
  4225. goto end;
  4226. }
  4227. else
  4228. {
  4229. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4230. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4231. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4232. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4233. {
  4234. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4235. result = FAIL;
  4236. goto end;
  4237. }
  4238. }// END FOR ELSE
  4239. }
  4240. } // END FOR GB_QUANTITY
  4241. }
  4242. else
  4243. {
  4244. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4245. {
  4246. tempIndex = 2;
  4247. }
  4248. else
  4249. {
  4250. tempIndex = connectorIdInt -1;
  4251. }
  4252. for (int index = 0; index < AC_QUANTITY; index++)
  4253. {
  4254. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4255. {
  4256. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4257. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4258. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4259. {
  4260. //Reserved
  4261. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4262. }
  4263. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4264. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4265. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4266. {
  4267. //Reserved
  4268. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4269. result = FAIL;
  4270. goto end;
  4271. }
  4272. else
  4273. {
  4274. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4275. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4276. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4277. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4278. {
  4279. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4280. result = FAIL;
  4281. goto end;
  4282. }
  4283. }//END FOR ELSE
  4284. }
  4285. }// END FOR AC_QUANTITY
  4286. }
  4287. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4288. {
  4289. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4290. {
  4291. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4292. {
  4293. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4294. system(cmdBuf);
  4295. }
  4296. }
  4297. else
  4298. {
  4299. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4300. result = FAIL;
  4301. }
  4302. }
  4303. end:
  4304. if(result == PASS)
  4305. {
  4306. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4307. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4308. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4309. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4310. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4311. }
  4312. }
  4313. void CheckSystemValue(void)
  4314. {
  4315. char filenmae[100]={0};
  4316. char str[100]={0};
  4317. int tempIndex = 0;
  4318. //===============================
  4319. // send Heartbeat
  4320. //===============================
  4321. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4322. {
  4323. //parameter for test
  4324. sendHeartbeatRequest(0);
  4325. //===========================
  4326. // Reset Waiting Time
  4327. //===========================
  4328. HeartBeatWithNOResponse += 1;
  4329. }
  4330. //===============================
  4331. // Credit deduct report
  4332. //===============================
  4333. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4334. {
  4335. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4336. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4337. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4338. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4339. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4340. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4341. }
  4342. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4343. {
  4344. OCPP_query_deduct_info();
  4345. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4346. }
  4347. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4348. {
  4349. // ClockAlign MeterValue
  4350. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4351. {
  4352. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4353. {
  4354. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4355. {
  4356. tempIndex = ((gun_index==2) ? 1: 0);
  4357. }
  4358. else
  4359. {
  4360. tempIndex = gun_index;
  4361. }
  4362. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4363. {
  4364. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4365. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4366. {
  4367. reqClockAlignMeter[gun_index] = 1;
  4368. }
  4369. }// End for CHAdeMO
  4370. }
  4371. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4372. {
  4373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4374. {
  4375. tempIndex = ((gun_index==2) ? 1: 0);
  4376. }
  4377. else
  4378. {
  4379. tempIndex = gun_index;
  4380. }
  4381. for (int index = 0; index < CCS_QUANTITY; index++)
  4382. {
  4383. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4384. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4385. {
  4386. reqClockAlignMeter[gun_index] = 1;
  4387. }
  4388. } // End for CCS
  4389. }
  4390. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4391. {
  4392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4393. {
  4394. tempIndex = ((gun_index==2) ? 1: 0);
  4395. }
  4396. else
  4397. {
  4398. tempIndex = gun_index;
  4399. }
  4400. for (int index = 0; index < GB_QUANTITY; index++)
  4401. {
  4402. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4403. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4404. {
  4405. reqClockAlignMeter[gun_index] = 1;
  4406. }
  4407. }// End for GB
  4408. }
  4409. else if(gunType[gun_index] == GUN_TYPE_DO)
  4410. {
  4411. tempIndex = gun_index;
  4412. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4413. {
  4414. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4415. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4416. {
  4417. reqClockAlignMeter[gun_index] = 1;
  4418. }
  4419. }
  4420. }
  4421. else
  4422. {
  4423. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4424. {
  4425. tempIndex = 2;
  4426. }
  4427. else
  4428. {
  4429. tempIndex = gun_index;
  4430. }
  4431. for (int index = 0; index < AC_QUANTITY; index++)
  4432. {
  4433. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4434. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4435. {
  4436. reqClockAlignMeter[gun_index] = 1;
  4437. }
  4438. }//End for AC
  4439. }
  4440. }
  4441. }
  4442. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4443. {
  4444. //==========================================
  4445. // Check remote start without connector id
  4446. //==========================================
  4447. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4448. {
  4449. int connectorIdInt = -1;
  4450. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4451. {
  4452. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4453. {
  4454. connectorIdInt = (gun_index+1);
  4455. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4456. checkRemoteStart(connectorIdInt);
  4457. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4458. break;
  4459. }
  4460. }
  4461. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4462. {
  4463. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4464. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4465. }
  4466. }
  4467. //==========================================
  4468. // csu trigger DataTransferReq
  4469. //==========================================
  4470. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4471. {
  4472. sendDataTransferRequest(gun_index);
  4473. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4474. }
  4475. //==========================================
  4476. // CSU Trigger Authorize Request
  4477. //==========================================
  4478. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4479. {
  4480. sendAuthorizeRequest(0);
  4481. authorizeRetryTimes = authorizeRetryTimes + 1;
  4482. if(authorizeRetryTimes < 3)
  4483. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4484. }
  4485. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4486. {
  4487. authorizeRetryTimes = 0;
  4488. SetOcppConnStatus(FALSE);
  4489. server_sign = FALSE;
  4490. }
  4491. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  4492. {
  4493. sendAuthorizeRequest(0);
  4494. }
  4495. //==========================================
  4496. // Charger start transaction
  4497. //==========================================
  4498. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4499. {
  4500. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4501. sendStartTransactionRequest(gun_index);
  4502. refreshStartTimer(&clientTime.StartTransaction);
  4503. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4504. storeTempStopTransaction(gun_index);
  4505. }
  4506. //==========================================
  4507. // Charger stop transaction
  4508. //==========================================
  4509. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4510. {
  4511. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4512. sendStopTransactionRequest(gun_index);
  4513. OCPP_updatePeriodEnergy(gun_index);
  4514. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4515. refreshStartTimer(&clientTime.StopTransaction);
  4516. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4517. }
  4518. //==========================================
  4519. // Charger status report
  4520. //==========================================
  4521. //--- Check Mode Change ---//
  4522. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4523. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4524. {
  4525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4526. {
  4527. tempIndex = ((gun_index==2) ? 1: 0);
  4528. }
  4529. else
  4530. {
  4531. tempIndex = gun_index;
  4532. }
  4533. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4534. {
  4535. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4536. {
  4537. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4538. {
  4539. // Sent unplug message for California pricing logic
  4540. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4541. {
  4542. uint8_t ts[36];
  4543. getNowDatetime(ts);
  4544. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4545. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4546. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4547. sendUnplugByDataTransferRequest(gun_index);
  4548. interLock.isSentUnplug[gun_index] = 1;
  4549. }
  4550. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4551. {
  4552. interLock.isSentUnplug[gun_index] = 0;
  4553. }
  4554. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4555. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4556. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4557. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4558. {
  4559. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4560. if((access(filenmae,F_OK))!=-1)
  4561. {
  4562. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4563. sprintf(str,"rm -f %s",filenmae);
  4564. system(str);
  4565. }
  4566. }
  4567. }
  4568. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4569. #if 1 // for TempStopTransaction
  4570. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4571. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4572. {
  4573. checkTempStopTransaction(gun_index);
  4574. }
  4575. #endif
  4576. }
  4577. }
  4578. }
  4579. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4580. {
  4581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4582. {
  4583. tempIndex = ((gun_index==2) ? 1: 0);
  4584. }
  4585. else
  4586. {
  4587. tempIndex = gun_index;
  4588. }
  4589. for (int index = 0; index < CCS_QUANTITY; index++)
  4590. {
  4591. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4592. {
  4593. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  4594. {
  4595. // Sent unplug message for California pricing logic
  4596. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4597. {
  4598. uint8_t ts[36];
  4599. getNowDatetime(ts);
  4600. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4601. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4602. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4603. sendUnplugByDataTransferRequest(gun_index);
  4604. interLock.isSentUnplug[gun_index] = 1;
  4605. }
  4606. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4607. {
  4608. interLock.isSentUnplug[gun_index] = 0;
  4609. }
  4610. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4611. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4612. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4613. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4614. {
  4615. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4616. if((access(filenmae,F_OK))!=-1)
  4617. {
  4618. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4619. sprintf(str,"rm -f %s",filenmae);
  4620. system(str);
  4621. }
  4622. }
  4623. }
  4624. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4625. #if 1 // for TempStopTransaction
  4626. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4627. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4628. {
  4629. checkTempStopTransaction(gun_index);
  4630. }
  4631. #endif
  4632. }
  4633. }
  4634. }
  4635. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4636. {
  4637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4638. {
  4639. tempIndex = ((gun_index==2) ? 1: 0);
  4640. }
  4641. else
  4642. {
  4643. tempIndex = gun_index;
  4644. }
  4645. for (int index = 0; index < GB_QUANTITY; index++)
  4646. {
  4647. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4648. {
  4649. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4650. {
  4651. // Sent unplug message for California pricing logic
  4652. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4653. {
  4654. uint8_t ts[36];
  4655. getNowDatetime(ts);
  4656. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4657. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4658. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4659. sendUnplugByDataTransferRequest(gun_index);
  4660. interLock.isSentUnplug[gun_index] = 1;
  4661. }
  4662. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4663. {
  4664. interLock.isSentUnplug[gun_index] = 0;
  4665. }
  4666. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4667. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4668. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4669. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4670. {
  4671. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4672. if((access(filenmae,F_OK))!=-1)
  4673. {
  4674. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4675. sprintf(str,"rm -f %s",filenmae);
  4676. system(str);
  4677. }
  4678. }
  4679. }
  4680. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4681. #if 1 // for TempStopTransaction
  4682. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4683. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4684. {
  4685. checkTempStopTransaction(gun_index);
  4686. }
  4687. #endif
  4688. }
  4689. }
  4690. }
  4691. else if(gunType[gun_index] == GUN_TYPE_DO)
  4692. {
  4693. tempIndex = gun_index;
  4694. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4695. {
  4696. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4697. {
  4698. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4699. {
  4700. // Sent unplug message for California pricing logic
  4701. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4702. {
  4703. uint8_t ts[36];
  4704. getNowDatetime(ts);
  4705. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4706. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4707. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4708. sendUnplugByDataTransferRequest(gun_index);
  4709. interLock.isSentUnplug[gun_index] = 1;
  4710. }
  4711. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4712. {
  4713. interLock.isSentUnplug[gun_index] = 0;
  4714. }
  4715. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4716. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4717. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4718. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  4719. {
  4720. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4721. if((access(filenmae,F_OK))!=-1)
  4722. {
  4723. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4724. sprintf(str,"rm -f %s",filenmae);
  4725. system(str);
  4726. }
  4727. }
  4728. }
  4729. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4730. #if 1 // for TempStopTransaction
  4731. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4732. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4733. {
  4734. checkTempStopTransaction(gun_index);
  4735. }
  4736. #endif
  4737. }
  4738. }
  4739. }
  4740. else
  4741. {
  4742. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4743. {
  4744. tempIndex = 2;
  4745. }
  4746. else
  4747. {
  4748. tempIndex = gun_index;
  4749. }
  4750. for (int index = 0; index < AC_QUANTITY; index++)
  4751. {
  4752. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4753. {
  4754. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4755. {
  4756. // Sent unplug message for California pricing logic
  4757. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4758. {
  4759. uint8_t ts[36];
  4760. getNowDatetime(ts);
  4761. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4762. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4763. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4764. sendUnplugByDataTransferRequest(gun_index);
  4765. interLock.isSentUnplug[gun_index] = 1;
  4766. }
  4767. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4768. {
  4769. interLock.isSentUnplug[gun_index] = 0;
  4770. }
  4771. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4772. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4773. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4774. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4775. {
  4776. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4777. if((access(filenmae,F_OK))!=-1)
  4778. {
  4779. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4780. sprintf(str,"rm -f %s",filenmae);
  4781. system(str);
  4782. }
  4783. }
  4784. }
  4785. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4786. #if 1 // for TempStopTransaction
  4787. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4788. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4789. {
  4790. checkTempStopTransaction(gun_index);
  4791. }
  4792. #endif
  4793. }
  4794. }// END
  4795. }
  4796. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4797. (
  4798. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4799. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4800. )
  4801. )
  4802. {
  4803. sendStatusNotificationRequest(gun_index);
  4804. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4805. }
  4806. //==============================================
  4807. // TCCI reader status report
  4808. //==============================================
  4809. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4810. {
  4811. reportReaderStatus(gun_index);
  4812. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4813. }
  4814. //==============================================
  4815. // CSU Trigger Smart Charging Profile
  4816. //==============================================
  4817. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4818. {
  4819. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4820. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4821. }
  4822. //==============================================
  4823. // Meter report
  4824. //==============================================
  4825. // Trigger MeterValue
  4826. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4827. {
  4828. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4829. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4830. }
  4831. // Clock-aligned Meter value
  4832. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4833. {
  4834. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4835. reqClockAlignMeter[gun_index] = 0;
  4836. }
  4837. // Sample period MeterValue
  4838. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4839. {
  4840. //check Transaction active
  4841. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4842. {
  4843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4844. {
  4845. tempIndex = ((gun_index==2) ? 1: 0);
  4846. }
  4847. else
  4848. {
  4849. tempIndex = gun_index;
  4850. }
  4851. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4852. {
  4853. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4854. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4855. {
  4856. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4857. {
  4858. reqSampleMeter[gun_index] = 1;
  4859. }
  4860. }
  4861. }// End for CHAdeMO
  4862. }
  4863. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4864. {
  4865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4866. {
  4867. tempIndex = ((gun_index==2) ? 1: 0);
  4868. }
  4869. else
  4870. {
  4871. tempIndex = gun_index;
  4872. }
  4873. for (int index = 0; index < CCS_QUANTITY; index++)
  4874. {
  4875. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4876. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4877. {
  4878. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4879. {
  4880. reqSampleMeter[gun_index] = 1;
  4881. }
  4882. }
  4883. } // End for CCS
  4884. }
  4885. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4886. {
  4887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4888. {
  4889. tempIndex = ((gun_index==2) ? 1: 0);
  4890. }
  4891. else
  4892. {
  4893. tempIndex = gun_index;
  4894. }
  4895. for (int index = 0; index < GB_QUANTITY; index++)
  4896. {
  4897. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4898. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4899. {
  4900. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4901. {
  4902. reqSampleMeter[gun_index] = 1;
  4903. }
  4904. }
  4905. }// End for GB
  4906. }
  4907. else if(gunType[gun_index] == GUN_TYPE_DO)
  4908. {
  4909. tempIndex = gun_index;
  4910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4911. {
  4912. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4913. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4914. {
  4915. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4916. {
  4917. reqSampleMeter[gun_index] = 1;
  4918. }
  4919. }
  4920. }
  4921. }
  4922. else
  4923. {
  4924. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4925. {
  4926. tempIndex = 2;
  4927. }
  4928. else
  4929. {
  4930. tempIndex = gun_index;
  4931. }
  4932. for (int index = 0; index < AC_QUANTITY; index++)
  4933. {
  4934. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4935. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4936. {
  4937. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4938. {
  4939. reqSampleMeter[gun_index] = 1;
  4940. }
  4941. }
  4942. }//End for AC
  4943. }
  4944. if(reqSampleMeter[gun_index] == 1)
  4945. {
  4946. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4947. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4948. storeTempStopTransaction(gun_index);
  4949. reqSampleMeter[gun_index] = 0;
  4950. }
  4951. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4952. }
  4953. //==============================================
  4954. // Check Connector reserved
  4955. //==============================================
  4956. //===============================
  4957. // Check if Reserve is expired
  4958. //===============================
  4959. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4960. {
  4961. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4962. {
  4963. DEBUG_INFO("reserve expired.\n");
  4964. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4965. }
  4966. }//END OF Check if Reserve is expired
  4967. //==========================================
  4968. // csu trigger FirmwareStatusNotificationReq
  4969. //==========================================
  4970. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4971. {
  4972. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4973. }
  4974. //==========================================
  4975. // csu trigger DiagnosticsStatusNotificationReq
  4976. //==========================================
  4977. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4978. {
  4979. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4980. }
  4981. //==========================================
  4982. // csu trigger CancelReservationConf
  4983. //==========================================
  4984. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4985. {
  4986. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4987. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4988. }
  4989. //==========================================
  4990. // csu trigger ChangeAvailabilityConf
  4991. //==========================================
  4992. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4993. {
  4994. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4995. }
  4996. //==========================================
  4997. // csu trigger UnlockConnectorConf
  4998. //==========================================
  4999. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5000. {
  5001. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5002. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5003. }
  5004. //==========================================
  5005. // csu trigger ReserveNowConf
  5006. //==========================================
  5007. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5008. {
  5009. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5010. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5011. }
  5012. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  5013. {
  5014. sendSignCertificateRequest();
  5015. }
  5016. }
  5017. }
  5018. //==========================================
  5019. // send request routine
  5020. //==========================================
  5021. int sendAuthorizeRequest(int gun_index)
  5022. {
  5023. mtrace();
  5024. int result = FAIL;
  5025. char message[100]={0};
  5026. char guid[37];
  5027. char tempdata[65]={0};
  5028. DEBUG_INFO("sendAuthorizeRequest...\n");
  5029. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5030. //Local Authorize
  5031. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5032. {
  5033. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5034. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5035. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5036. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5037. result = PASS;
  5038. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5039. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5040. authorizeRetryTimes = 0;
  5041. return result;
  5042. }
  5043. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  5044. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5045. {
  5046. // Query from cache
  5047. DEBUG_INFO("Authorize from cache.\n");
  5048. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5049. // Query from list
  5050. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5051. {
  5052. DEBUG_INFO("Authorize from list.\n");
  5053. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5054. }
  5055. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5056. {
  5057. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5058. {
  5059. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5060. }
  5061. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5062. {
  5063. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5064. }
  5065. if(!GetOcppConnStatus())
  5066. {
  5067. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5068. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5069. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5070. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5071. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5072. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5073. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5074. authorizeRetryTimes = 0;
  5075. return result;
  5076. }
  5077. }
  5078. else
  5079. {
  5080. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5081. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5082. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5083. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5084. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5085. else
  5086. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5087. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5088. result = PASS;
  5089. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5090. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5091. authorizeRetryTimes = 0;
  5092. return result;
  5093. }
  5094. }
  5095. //initialize struct Authorize
  5096. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5097. //get data from shared memory
  5098. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5099. random_uuid(guid);
  5100. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5101. LWS_Send(message);
  5102. sprintf(tempdata, "Authorize,%d", gun_index);
  5103. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5104. {
  5105. result = PASS;
  5106. DEBUG_INFO("Authorize mapItem pass\n");
  5107. }
  5108. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5109. return result;
  5110. }
  5111. int sendBootNotificationRequest(void)
  5112. {
  5113. mtrace();
  5114. int result = FAIL;
  5115. char message[500]={0}, payload[700]={0};
  5116. char guid[37]={0};
  5117. char tempdata[65]={0};
  5118. // Fill BootNotification fields
  5119. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5120. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5121. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5122. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5123. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5124. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5125. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5126. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5127. ShmOCPP16Data->ChargeBoxId
  5128. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5129. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5130. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5131. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5132. ,ShmOCPP16Data->BootNotification.CpIccid
  5133. ,ShmOCPP16Data->BootNotification.CpImsi);
  5134. random_uuid(guid);
  5135. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5136. LWS_Send(message);
  5137. sprintf(tempdata, "BootNotification,0");
  5138. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5139. {
  5140. result = PASS;
  5141. }
  5142. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5143. strcpy(queuedata,message);
  5144. return result;
  5145. }
  5146. int sendDataTransferRequest(int gun_index)
  5147. {
  5148. mtrace();
  5149. char message[1000]={0};
  5150. char guid[37]={0};
  5151. char tempdata[65]={0};
  5152. int result = FAIL;
  5153. random_uuid(guid);
  5154. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5155. MESSAGE_TYPE_CALL,
  5156. guid,
  5157. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5158. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5159. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5160. LWS_Send(message);
  5161. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5162. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5163. {
  5164. result = PASS;
  5165. DEBUG_INFO("DataTransfer mapItem pass\n");
  5166. }
  5167. return result;
  5168. }
  5169. int sendUnplugByDataTransferRequest(int gun_index)
  5170. {
  5171. mtrace();
  5172. char message[1000]={0};
  5173. char guid[37]={0};
  5174. char tempdata[65]={0};
  5175. int result = FAIL;
  5176. random_uuid(guid);
  5177. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5178. (gun_index+1),
  5179. MESSAGE_TYPE_CALL,
  5180. guid,
  5181. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5182. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5183. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5184. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5185. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5186. {
  5187. result = PASS;
  5188. DEBUG_INFO("DataTransfer mapItem pass\n");
  5189. }
  5190. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5191. return result;
  5192. }
  5193. int sendDiagnosticsStatusNotificationRequest(char *status)
  5194. {
  5195. mtrace();
  5196. int result = FAIL;
  5197. char message[110]={0};
  5198. char guid[37]={0};
  5199. char tempdata[65]={0};
  5200. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5201. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5202. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5203. random_uuid(guid);
  5204. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5205. LWS_SendNow(message);
  5206. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5207. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5208. {
  5209. result = PASS;
  5210. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5211. }
  5212. //#ifdef SystemLogMessage
  5213. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5214. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5215. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5216. //#endif
  5217. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5218. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5219. //record status
  5220. if(strcmp(status,"Idle")==0)
  5221. {
  5222. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5223. }
  5224. else if(strcmp(status,"Uploaded")==0)
  5225. {
  5226. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5227. }
  5228. else if(strcmp(status,"UploadFailed")==0)
  5229. {
  5230. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5231. }
  5232. else if(strcmp(status,"Uploading")==0)
  5233. {
  5234. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5235. }
  5236. return result;
  5237. }
  5238. int sendFirmwareStatusNotificationRequest(char *status)
  5239. {
  5240. mtrace();
  5241. int result = FAIL;
  5242. char message[110]={0};
  5243. char guid[37]={0};
  5244. char tempdata[65]={0};
  5245. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5246. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5247. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5248. random_uuid(guid);
  5249. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5250. LWS_SendNow(message);
  5251. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5252. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5253. {
  5254. result = PASS;
  5255. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5256. }
  5257. //#ifdef SystemLogMessage
  5258. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5259. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5260. //#endif
  5261. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5262. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5263. //record status
  5264. if(strcmp(status,"Downloaded")==0)
  5265. {
  5266. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5267. }
  5268. else if(strcmp(status,"DownloadFailed")==0)
  5269. {
  5270. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5271. }
  5272. else if(strcmp(status,"Downloading")==0)
  5273. {
  5274. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5275. }
  5276. else if(strcmp(status,"Idle")==0)
  5277. {
  5278. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5279. }
  5280. else if(strcmp(status,"InstallationFailed")==0)
  5281. {
  5282. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5283. }
  5284. else if(strcmp(status,"Installing")==0)
  5285. {
  5286. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5287. }
  5288. else if(strcmp(status,"Installed")==0)
  5289. {
  5290. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5291. }
  5292. return result;
  5293. }
  5294. int sendHeartbeatRequest(int gun_index)
  5295. {
  5296. mtrace();
  5297. int result = FAIL;
  5298. char message[80]={0};
  5299. char guid[37]={0};
  5300. char tempdata[65]={0};
  5301. random_uuid(guid);
  5302. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5303. , MESSAGE_TYPE_CALL
  5304. , guid );
  5305. LWS_Send(message);
  5306. sprintf(tempdata, "Heartbeat,%d", 0);
  5307. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5308. {
  5309. result = PASS;
  5310. }
  5311. return result;
  5312. }
  5313. int sendStartTransactionRequest(int gun_index)
  5314. {
  5315. mtrace();
  5316. int result = FAIL;
  5317. char message[250]={0};
  5318. char guid[37]={0};
  5319. struct timeval tmnow;
  5320. struct tm *tm;
  5321. char buf[28];//, usec_buf[6];
  5322. char tempdata[65]={0};
  5323. int tempIndex = 0;
  5324. DEBUG_INFO("sendStartTransactionRequest...\n");
  5325. gettimeofday(&tmnow, NULL);
  5326. time_t t;
  5327. t = time(NULL);
  5328. /*UTC time and date*/
  5329. tm = gmtime(&t);
  5330. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5331. #if 0 // remove temporally
  5332. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5333. strcat(buf,".");
  5334. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5335. strcat(buf,usec_buf);
  5336. #endif
  5337. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5338. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5339. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5340. // clear StartTransaction Response
  5341. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5342. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5343. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5344. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5345. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5346. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5347. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5348. {
  5349. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5350. {
  5351. tempIndex = ((gun_index==2) ? 1: 0);
  5352. }
  5353. else
  5354. {
  5355. tempIndex = gun_index;
  5356. }
  5357. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5358. {
  5359. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5360. {
  5361. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5362. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5363. }
  5364. }
  5365. }
  5366. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5367. {
  5368. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5369. {
  5370. tempIndex = ((gun_index==2) ? 1: 0);
  5371. }
  5372. else
  5373. {
  5374. tempIndex = gun_index;
  5375. }
  5376. for (int index = 0; index < CCS_QUANTITY; index++)
  5377. {
  5378. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5379. {
  5380. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5381. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5382. }
  5383. }
  5384. }
  5385. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5386. {
  5387. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5388. {
  5389. tempIndex = ((gun_index==2) ? 1: 0);
  5390. }
  5391. else
  5392. {
  5393. tempIndex = gun_index;
  5394. }
  5395. for (int index = 0; index < GB_QUANTITY; index++)
  5396. {
  5397. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5398. {
  5399. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5400. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5401. }
  5402. }
  5403. }
  5404. else if(gunType[gun_index] == GUN_TYPE_DO)
  5405. {
  5406. tempIndex = gun_index;
  5407. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5408. {
  5409. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5410. {
  5411. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5412. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5413. }
  5414. }
  5415. }
  5416. else
  5417. {
  5418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5419. {
  5420. tempIndex = 2;
  5421. }
  5422. else
  5423. {
  5424. tempIndex = gun_index;
  5425. }
  5426. for (int index = 0; index < AC_QUANTITY; index++)
  5427. {
  5428. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5429. {
  5430. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5431. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5432. }
  5433. }
  5434. }
  5435. random_uuid(guid);
  5436. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5437. {
  5438. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5439. , gun_index +1
  5440. , MESSAGE_TYPE_CALL
  5441. , guid
  5442. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5443. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5444. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5445. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5446. }
  5447. else
  5448. {
  5449. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5450. , gun_index +1
  5451. , MESSAGE_TYPE_CALL
  5452. , guid
  5453. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5454. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5455. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5456. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5457. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5458. }
  5459. #if 1
  5460. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5461. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5462. {
  5463. result = PASS;
  5464. }
  5465. #endif
  5466. strcpy(queuedata, message);
  5467. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5468. OCPP_insert_transaction_msg(YES, queuedata);
  5469. return result;
  5470. }
  5471. int sendStatusNotificationRequest(int gun_index)
  5472. {
  5473. mtrace();
  5474. int result = FAIL;
  5475. char message[600]={0};
  5476. char guid[37];
  5477. int currentStatus = 0;
  5478. struct timeval tmnow;
  5479. struct tm *tm;
  5480. char buf[28];//, usec_buf[6];
  5481. char tempdata[65]={0};
  5482. int tempIndex = 0;
  5483. uint8_t isStateChanged = TRUE;
  5484. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5485. gettimeofday(&tmnow, NULL);
  5486. time_t t;
  5487. t = time(NULL);
  5488. /*UTC time and date*/
  5489. tm = gmtime(&t);
  5490. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5491. #if 0 // remove temporally
  5492. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5493. strcat(buf,".");
  5494. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5495. strcat(buf,usec_buf);
  5496. #endif
  5497. //printf("%s",buf);
  5498. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5499. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5500. // it's option
  5501. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5502. /*
  5503. enum _SYSTEM_STATUS
  5504. {
  5505. S_BOOTING = 0,
  5506. S_IDLE, = 1
  5507. S_AUTHORIZING, =2
  5508. S_REASSIGN_CHECK, =3
  5509. S_REASSIGN, =4
  5510. S_PRECHARGE, =5
  5511. S_PREPARING_FOR_EV, =6
  5512. S_PREPARING_FOR_EVSE, =7
  5513. S_CHARGING, =8
  5514. S_TERMINATING, =9
  5515. S_COMPLETE, =10
  5516. S_ALARM, =11
  5517. S_FAULT =12
  5518. }
  5519. */
  5520. //check Transaction active
  5521. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5522. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5523. {
  5524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5525. {
  5526. tempIndex = ((gun_index==2) ? 1: 0);
  5527. }
  5528. else
  5529. {
  5530. tempIndex = gun_index;
  5531. }
  5532. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5533. {
  5534. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5535. {
  5536. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5537. {
  5538. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5539. {
  5540. currentStatus = Preparing; //OCPP Status: Preparing
  5541. }
  5542. else
  5543. {
  5544. currentStatus = Available; //OCPP Status: Available
  5545. }
  5546. }
  5547. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5548. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5549. ) //S_PRECHARGE
  5550. {
  5551. currentStatus = Preparing; //OCPP Status: Preparing
  5552. }
  5553. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5554. {
  5555. currentStatus = Charging; //OCPP Status: Charging
  5556. }
  5557. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5558. {
  5559. currentStatus = Finishing; //OCPP Status: Finishing
  5560. }
  5561. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5562. {
  5563. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5564. }
  5565. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5566. {
  5567. currentStatus = Unavailable; //OCPP Status: Unavailable
  5568. }
  5569. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5570. {
  5571. currentStatus = Faulted; //OCPP Status: Faulted
  5572. }
  5573. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5574. {
  5575. currentStatus = Reserved; //OCPP Status: Reserved
  5576. }
  5577. } //end of the same index
  5578. }//end of for CHAdeMO_QUANTITY
  5579. }
  5580. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5581. {
  5582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5583. {
  5584. tempIndex = ((gun_index==2) ? 1: 0);
  5585. }
  5586. else
  5587. {
  5588. tempIndex = gun_index;
  5589. }
  5590. for (int index = 0; index < CCS_QUANTITY; index++)
  5591. {
  5592. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5593. {
  5594. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5595. {
  5596. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5597. {
  5598. currentStatus = Preparing; //OCPP Status: Preparing
  5599. }
  5600. else
  5601. {
  5602. currentStatus = Available; //OCPP Status: Available
  5603. }
  5604. }
  5605. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5606. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5607. ) //S_PRECHARGE
  5608. {
  5609. currentStatus = Preparing; //OCPP Status: Preparing
  5610. }
  5611. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5612. {
  5613. currentStatus = Charging; //OCPP Status: Charging
  5614. }
  5615. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5616. {
  5617. currentStatus = Finishing; //OCPP Status: Finishing
  5618. }
  5619. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5620. {
  5621. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5622. }
  5623. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5624. {
  5625. currentStatus = Unavailable; //OCPP Status : Unavailable
  5626. }
  5627. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5628. {
  5629. currentStatus = Faulted; //OCPP Status: Faulted
  5630. }
  5631. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5632. {
  5633. currentStatus = Reserved; //OCPP Status: Reserved
  5634. }
  5635. } //end of the same index
  5636. } // end of for CCS_QUANTITY
  5637. }
  5638. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5639. {
  5640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5641. {
  5642. tempIndex = ((gun_index==2) ? 1: 0);
  5643. }
  5644. else
  5645. {
  5646. tempIndex = gun_index;
  5647. }
  5648. for (int index = 0; index < GB_QUANTITY; index++)
  5649. {
  5650. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5651. {
  5652. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5653. {
  5654. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5655. {
  5656. currentStatus = Preparing; //OCPP Status: Preparing
  5657. }
  5658. else
  5659. {
  5660. currentStatus = Available; //OCPP Status: Available
  5661. }
  5662. }
  5663. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5664. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5665. ) //S_PRECHARGE
  5666. {
  5667. currentStatus = Preparing; //OCPP Status: Preparing
  5668. }
  5669. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5670. {
  5671. currentStatus = Charging; //OCPP Status: Charging
  5672. }
  5673. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5674. {
  5675. currentStatus = Finishing; //OCPP Status: Finishing
  5676. }
  5677. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5678. {
  5679. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5680. }
  5681. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5682. {
  5683. currentStatus = Unavailable; //OCPP Status: Unavailable
  5684. }
  5685. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5686. {
  5687. currentStatus = Faulted; //OCPP Status: Faulted
  5688. }
  5689. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5690. {
  5691. currentStatus = Reserved; //OCPP Status: Reserved
  5692. }
  5693. } //end of the same index
  5694. } // end of for GB_QUANTITY
  5695. }
  5696. else if(gunType[gun_index] == GUN_TYPE_DO)
  5697. {
  5698. tempIndex = gun_index;
  5699. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5700. {
  5701. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5702. {
  5703. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5704. {
  5705. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5706. {
  5707. currentStatus = Preparing; //OCPP Status: Preparing
  5708. }
  5709. else
  5710. {
  5711. currentStatus = Available; //OCPP Status: Available
  5712. }
  5713. }
  5714. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5715. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5716. ) //S_PRECHARGE
  5717. {
  5718. currentStatus = Preparing; //OCPP Status: Preparing
  5719. }
  5720. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5721. {
  5722. currentStatus = Charging; //OCPP Status: Charging
  5723. }
  5724. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5725. {
  5726. currentStatus = Finishing; //OCPP Status: Finishing
  5727. }
  5728. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5729. {
  5730. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5731. }
  5732. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5733. {
  5734. currentStatus = Unavailable; //OCPP Status: Unavailable
  5735. }
  5736. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5737. {
  5738. currentStatus = Faulted; //OCPP Status: Faulted
  5739. }
  5740. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5741. {
  5742. currentStatus = Reserved; //OCPP Status: Reserved
  5743. }
  5744. } //end of the same index
  5745. }
  5746. }
  5747. else
  5748. {
  5749. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5750. {
  5751. tempIndex = 2;
  5752. }
  5753. else
  5754. {
  5755. tempIndex = gun_index;
  5756. }
  5757. for (int index = 0; index < AC_QUANTITY; index++)
  5758. {
  5759. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5760. {
  5761. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5762. {
  5763. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  5764. {
  5765. currentStatus = Preparing; //OCPP Status: Preparing
  5766. }
  5767. else
  5768. {
  5769. currentStatus = Available; //OCPP Status: Available
  5770. }
  5771. }
  5772. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5773. {
  5774. currentStatus = Preparing; //OCPP Status: Preparing
  5775. }
  5776. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5777. {
  5778. currentStatus = Charging; //OCPP Status: Charging
  5779. }
  5780. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5781. {
  5782. currentStatus = Finishing; //OCPP Status: Finishing
  5783. }
  5784. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5785. {
  5786. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5787. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5788. else
  5789. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5790. }
  5791. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5792. {
  5793. currentStatus = Unavailable; //OCPP Status: Unavailable
  5794. }
  5795. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5796. {
  5797. currentStatus = Faulted; //OCPP Status: Faulted
  5798. }
  5799. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5800. {
  5801. currentStatus = Reserved; //OCPP Status: Reserved
  5802. }
  5803. }//end of the same index
  5804. }//end of for AC_QUANTITY
  5805. }
  5806. //it's option
  5807. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5808. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5809. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5810. {
  5811. isStateChanged = FALSE;
  5812. }
  5813. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5814. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5815. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5816. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5817. random_uuid(guid);
  5818. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5819. , MESSAGE_TYPE_CALL
  5820. , guid
  5821. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5822. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5823. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5824. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5825. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5826. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5827. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5828. if((server_sign == TRUE) && isStateChanged)
  5829. {
  5830. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5831. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5832. LWS_Send(message);
  5833. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5834. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5835. {
  5836. //DEBUG_ERROR("statusNotification mapitem pass");
  5837. result = PASS;
  5838. }
  5839. }
  5840. else
  5841. {
  5842. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5843. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5844. result = PASS;
  5845. }
  5846. return result;
  5847. }
  5848. int sendStopTransactionRequest(int gun_index)
  5849. {
  5850. mtrace();
  5851. int result = FAIL;
  5852. //char message[1500]={0};
  5853. char guid[37]={0};
  5854. char tempdata[65]={0};
  5855. int tempIndex = 0;
  5856. char TempStopTransaction[256];
  5857. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5858. //int idx_sample=0;
  5859. DEBUG_INFO("sendStopTransactionRequest \n");
  5860. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5861. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5862. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5863. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5865. {
  5866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5867. {
  5868. tempIndex = ((gun_index==2) ? 1: 0);
  5869. }
  5870. else
  5871. {
  5872. tempIndex = gun_index;
  5873. }
  5874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5875. {
  5876. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5877. {
  5878. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5879. }
  5880. }// END OF CHAdeMO_QUANTITY
  5881. }
  5882. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5883. {
  5884. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5885. {
  5886. tempIndex = ((gun_index==2) ? 1: 0);
  5887. }
  5888. else
  5889. {
  5890. tempIndex = gun_index;
  5891. }
  5892. for (int index = 0; index < CCS_QUANTITY; index++)
  5893. {
  5894. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5895. {
  5896. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5897. }
  5898. }// END OF CCS_QUANTITY
  5899. }
  5900. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5901. {
  5902. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5903. {
  5904. tempIndex = ((gun_index==2) ? 1: 0);
  5905. }
  5906. else
  5907. {
  5908. tempIndex = gun_index;
  5909. }
  5910. for (int index = 0; index < GB_QUANTITY; index++)
  5911. {
  5912. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5913. {
  5914. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5915. }
  5916. }// END OF GB_QUANTITY
  5917. }
  5918. else if(gunType[gun_index] == GUN_TYPE_DO)
  5919. {
  5920. tempIndex = gun_index;
  5921. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5922. {
  5923. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5924. {
  5925. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5926. }
  5927. }// END OF GB_QUANTITY
  5928. }
  5929. else
  5930. {
  5931. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5932. {
  5933. tempIndex = 2;
  5934. }
  5935. else
  5936. {
  5937. tempIndex = gun_index;
  5938. }
  5939. for (int index = 0; index < AC_QUANTITY; index++)
  5940. {
  5941. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5942. {
  5943. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5944. }
  5945. }// END OF AC_QUANTITY
  5946. }
  5947. //====================================== Stop Transaction Time =====================================================
  5948. struct timeval tmnow;
  5949. struct tm *tm;
  5950. char buf[28];//, usec_buf[6];
  5951. gettimeofday(&tmnow, NULL);
  5952. time_t t;
  5953. t = time(NULL);
  5954. /*UTC time and date*/
  5955. tm = gmtime(&t);
  5956. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5958. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5959. random_uuid(guid);
  5960. /***********************************transactionData******************************************************/
  5961. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5963. //=================================
  5964. // Transaction_Begin
  5965. //=================================
  5966. //=================================
  5967. // Transaction_End
  5968. //=================================
  5969. // ================================= Current.Import L1 ===============================================
  5970. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5971. {
  5972. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5973. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5974. {
  5975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5976. {
  5977. tempIndex = ((gun_index==2) ? 1: 0);
  5978. }
  5979. else
  5980. {
  5981. tempIndex = gun_index;
  5982. }
  5983. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5984. {
  5985. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5986. {
  5987. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5988. }
  5989. }// End of for CHAdeMO_QUANTITY
  5990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5991. }
  5992. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5993. {
  5994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5995. {
  5996. tempIndex = ((gun_index==2) ? 1: 0);
  5997. }
  5998. else
  5999. {
  6000. tempIndex = gun_index;
  6001. }
  6002. for (int index = 0; index < CCS_QUANTITY; index++)
  6003. {
  6004. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6005. {
  6006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6007. }
  6008. }// End of for CCS_QUANTITY
  6009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6010. }
  6011. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6012. {
  6013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6014. {
  6015. tempIndex = ((gun_index==2) ? 1: 0);
  6016. }
  6017. else
  6018. {
  6019. tempIndex = gun_index;
  6020. }
  6021. for (int index = 0; index < GB_QUANTITY; index++)
  6022. {
  6023. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6024. {
  6025. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6026. }
  6027. }// End of for GB_QUANTITY
  6028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6029. }
  6030. else if(gunType[gun_index] == GUN_TYPE_DO)
  6031. {
  6032. tempIndex = gun_index;
  6033. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6034. {
  6035. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6036. {
  6037. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6038. }
  6039. }
  6040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6041. }
  6042. else
  6043. {
  6044. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6045. {
  6046. tempIndex = 2;
  6047. }
  6048. else
  6049. {
  6050. tempIndex = gun_index;
  6051. }
  6052. for (int index = 0; index < AC_QUANTITY; index++)
  6053. {
  6054. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6055. {
  6056. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6057. }
  6058. }// End of for AC_QUANTITY
  6059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6060. }
  6061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6066. }
  6067. // ================================= Energy.Active.Import.Interval ==============================================
  6068. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6069. {
  6070. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6071. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6072. {
  6073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6074. {
  6075. tempIndex = ((gun_index==2) ? 1: 0);
  6076. }
  6077. else
  6078. {
  6079. tempIndex = gun_index;
  6080. }
  6081. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6082. {
  6083. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6084. {
  6085. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6086. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6087. }
  6088. }// END OF CHAdeMO_QUANTITY
  6089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6090. }
  6091. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6092. {
  6093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6094. {
  6095. tempIndex = ((gun_index==2) ? 1: 0);
  6096. }
  6097. else
  6098. {
  6099. tempIndex = gun_index;
  6100. }
  6101. for (int index = 0; index < CCS_QUANTITY; index++)
  6102. {
  6103. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6104. {
  6105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6106. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6107. }
  6108. }// END OF CCS_QUANTITY
  6109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6110. }
  6111. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6112. {
  6113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6114. {
  6115. tempIndex = ((gun_index==2) ? 1: 0);
  6116. }
  6117. else
  6118. {
  6119. tempIndex = gun_index;
  6120. }
  6121. for (int index = 0; index < GB_QUANTITY; index++)
  6122. {
  6123. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6124. {
  6125. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6126. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6127. }
  6128. }// END OF GB_QUANTITY
  6129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6130. }
  6131. else if(gunType[gun_index] == GUN_TYPE_DO)
  6132. {
  6133. tempIndex = gun_index;
  6134. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6135. {
  6136. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6137. {
  6138. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6139. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6140. }
  6141. }
  6142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6143. }
  6144. else
  6145. {
  6146. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6147. {
  6148. tempIndex = 2;
  6149. }
  6150. else
  6151. {
  6152. tempIndex = gun_index;
  6153. }
  6154. for (int index = 0; index < AC_QUANTITY; index++)
  6155. {
  6156. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6157. {
  6158. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6159. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6160. }
  6161. }// END OF AC_QUANTITY
  6162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6163. }
  6164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6169. }
  6170. //=================================== Power.Active.Import ==================================================
  6171. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6172. {
  6173. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6174. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6175. {
  6176. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6177. {
  6178. tempIndex = ((gun_index==2) ? 1: 0);
  6179. }
  6180. else
  6181. {
  6182. tempIndex = gun_index;
  6183. }
  6184. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6185. {
  6186. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6187. {
  6188. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6189. }
  6190. } // End for CHAdeMO_QUANTITY
  6191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6192. }
  6193. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6194. {
  6195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6196. {
  6197. tempIndex = ((gun_index==2) ? 1: 0);
  6198. }
  6199. else
  6200. {
  6201. tempIndex = gun_index;
  6202. }
  6203. for (int index = 0; index < CCS_QUANTITY; index++)
  6204. {
  6205. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6206. {
  6207. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6208. }
  6209. } // END for CCS_QUANTITY
  6210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6211. }
  6212. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6213. {
  6214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6215. {
  6216. tempIndex = ((gun_index==2) ? 1: 0);
  6217. }
  6218. else
  6219. {
  6220. tempIndex = gun_index;
  6221. }
  6222. for (int index = 0; index < GB_QUANTITY; index++)
  6223. {
  6224. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6225. {
  6226. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6227. }
  6228. }// END for GB_QUANTITY
  6229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6230. }
  6231. else if(gunType[gun_index] == GUN_TYPE_DO)
  6232. {
  6233. tempIndex = gun_index;
  6234. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6235. {
  6236. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6237. {
  6238. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6239. }
  6240. }
  6241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6242. }
  6243. else
  6244. {
  6245. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6246. {
  6247. tempIndex = 2;
  6248. }
  6249. else
  6250. {
  6251. tempIndex = gun_index;
  6252. }
  6253. for (int index = 0; index < AC_QUANTITY; index++)
  6254. {
  6255. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6256. {
  6257. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6258. }
  6259. } // END for AC_QUANTITY
  6260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6261. }
  6262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6267. }
  6268. //============================ Voltage L1 ====================================
  6269. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6270. {
  6271. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6272. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6273. {
  6274. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6275. {
  6276. tempIndex = ((gun_index==2) ? 1: 0);
  6277. }
  6278. else
  6279. {
  6280. tempIndex = gun_index;
  6281. }
  6282. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6283. {
  6284. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6285. {
  6286. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6287. }
  6288. } // END OF FOR CHAdeMO_QUANTITY
  6289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6290. }
  6291. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6292. {
  6293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6294. {
  6295. tempIndex = ((gun_index==2) ? 1: 0);
  6296. }
  6297. else
  6298. {
  6299. tempIndex = gun_index;
  6300. }
  6301. for (int index = 0; index < CCS_QUANTITY; index++)
  6302. {
  6303. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6304. {
  6305. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6306. }
  6307. } // END OF FOR CCS_QUANTITY
  6308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6309. }
  6310. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6311. {
  6312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6313. {
  6314. tempIndex = ((gun_index==2) ? 1: 0);
  6315. }
  6316. else
  6317. {
  6318. tempIndex = gun_index;
  6319. }
  6320. for (int index = 0; index < GB_QUANTITY; index++)
  6321. {
  6322. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6323. {
  6324. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6325. }
  6326. } // END OF FOR GB_QUANTITY
  6327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6328. }
  6329. else if(gunType[gun_index] == GUN_TYPE_DO)
  6330. {
  6331. tempIndex = gun_index;
  6332. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6333. {
  6334. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6335. {
  6336. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6337. }
  6338. }
  6339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6340. }
  6341. else
  6342. {
  6343. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6344. {
  6345. tempIndex = 2;
  6346. }
  6347. else
  6348. {
  6349. tempIndex = gun_index;
  6350. }
  6351. for (int index = 0; index < AC_QUANTITY; index++)
  6352. {
  6353. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6354. {
  6355. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6356. }
  6357. } // END OF FOR AC_QUANTITY
  6358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6359. }
  6360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6365. }
  6366. //====================== End SoC ================================
  6367. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6368. {
  6369. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6370. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6371. {
  6372. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6373. {
  6374. tempIndex = ((gun_index==2) ? 1: 0);
  6375. }
  6376. else
  6377. {
  6378. tempIndex = gun_index;
  6379. }
  6380. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6381. {
  6382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6383. {
  6384. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6385. {
  6386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6387. }
  6388. }
  6389. }
  6390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6391. {
  6392. for (int index = 0; index < CCS_QUANTITY; index++)
  6393. {
  6394. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6395. {
  6396. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6397. }
  6398. }
  6399. }
  6400. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6401. {
  6402. for (int index = 0; index < GB_QUANTITY; index++)
  6403. {
  6404. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6405. {
  6406. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6407. }
  6408. }
  6409. }
  6410. else if(gunType[gun_index] == GUN_TYPE_DO)
  6411. {
  6412. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6413. {
  6414. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6415. {
  6416. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6417. }
  6418. }
  6419. }
  6420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6426. } // END FOR DC CASE
  6427. }
  6428. // ================================= Current.Import L2 ===============================================
  6429. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6430. {
  6431. // AC 3 phse L2 current
  6432. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6433. {
  6434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6435. {
  6436. tempIndex = 2;
  6437. }
  6438. else
  6439. {
  6440. tempIndex = gun_index;
  6441. }
  6442. for (int index = 0; index < AC_QUANTITY; index++)
  6443. {
  6444. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6445. {
  6446. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6447. }
  6448. }// End of for AC_QUANTITY
  6449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6450. }
  6451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6456. }
  6457. // ================================= Current.Import L3 ===============================================
  6458. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6459. {
  6460. // AC 3 phse L3 current
  6461. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6462. {
  6463. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6464. {
  6465. tempIndex = 2;
  6466. }
  6467. else
  6468. {
  6469. tempIndex = gun_index;
  6470. }
  6471. for (int index = 0; index < AC_QUANTITY; index++)
  6472. {
  6473. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6474. {
  6475. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6476. }
  6477. }// End of for AC_QUANTITY
  6478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6479. }
  6480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6485. }
  6486. //============================ Voltage L2 ====================================
  6487. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6488. {
  6489. // AC 3 phse L2 voltage
  6490. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6491. {
  6492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6493. {
  6494. tempIndex = 2;
  6495. }
  6496. else
  6497. {
  6498. tempIndex = gun_index;
  6499. }
  6500. for (int index = 0; index < AC_QUANTITY; index++)
  6501. {
  6502. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6503. {
  6504. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6505. }
  6506. } // END OF FOR AC_QUANTITY
  6507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6508. }
  6509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6514. }
  6515. //============================ Voltage L3 ====================================
  6516. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6517. {
  6518. // AC 3 phse L3 voltage
  6519. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6520. {
  6521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6522. {
  6523. tempIndex = 2;
  6524. }
  6525. else
  6526. {
  6527. tempIndex = gun_index;
  6528. }
  6529. for (int index = 0; index < AC_QUANTITY; index++)
  6530. {
  6531. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6532. {
  6533. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6534. }
  6535. } // END OF FOR AC_QUANTITY
  6536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6537. }
  6538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6543. }
  6544. //====================== Start SoC ================================
  6545. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6546. {
  6547. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6548. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6549. {
  6550. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6551. {
  6552. tempIndex = ((gun_index==2) ? 1: 0);
  6553. }
  6554. else
  6555. {
  6556. tempIndex = gun_index;
  6557. }
  6558. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6559. {
  6560. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6561. {
  6562. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6563. {
  6564. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6565. }
  6566. }
  6567. }
  6568. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6569. {
  6570. for (int index = 0; index < CCS_QUANTITY; index++)
  6571. {
  6572. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6573. {
  6574. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6575. }
  6576. }
  6577. }
  6578. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6579. {
  6580. for (int index = 0; index < GB_QUANTITY; index++)
  6581. {
  6582. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6583. {
  6584. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6585. }
  6586. }
  6587. }
  6588. else if(gunType[gun_index] == GUN_TYPE_DO)
  6589. {
  6590. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6591. {
  6592. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6593. {
  6594. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6595. }
  6596. }
  6597. }
  6598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6604. } // END FOR DC CASE
  6605. }
  6606. //================================================ Message create ====================================================
  6607. json_object *StopTransaction = json_object_new_object();
  6608. json_object *transactionDatas = json_object_new_array();
  6609. json_object *sampledValues = json_object_new_array();
  6610. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6611. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6612. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6613. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6614. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6615. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6616. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6617. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6618. {
  6619. json_object *transactionData = json_object_new_object();
  6620. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6621. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6622. {
  6623. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6624. {
  6625. json_object *sampledValue = json_object_new_object();
  6626. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6627. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6628. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6629. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6630. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6631. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6632. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6633. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6634. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6635. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6636. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6637. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6638. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6639. json_object_array_add(sampledValues, sampledValue);
  6640. }
  6641. }
  6642. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6643. json_object_array_add(transactionDatas, transactionData);
  6644. }
  6645. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6646. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6647. ,MESSAGE_TYPE_CALL
  6648. ,guid
  6649. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6650. json_object_put(StopTransaction);
  6651. #if 1 // for TempStopTransaction
  6652. //Delete TempStopTransaction
  6653. if((access(TempStopTransaction,F_OK))!=-1)
  6654. {
  6655. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6656. }
  6657. #endif
  6658. #if 1
  6659. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6660. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6661. {
  6662. result = PASS;
  6663. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6664. }
  6665. #endif
  6666. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6667. OCPP_insert_transaction_msg(NO, queuedata);
  6668. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6669. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6670. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6671. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6672. {
  6673. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6674. }
  6675. //for test
  6676. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6677. return result;
  6678. }
  6679. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6680. {
  6681. mtrace();
  6682. int result = FAIL;
  6683. char guid[37]={0};
  6684. char tempdata[65]={0};
  6685. int tempIndex = 0;
  6686. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6687. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6688. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6689. //set value
  6690. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6691. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6692. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6693. -1);
  6694. random_uuid(guid);
  6695. //UTC Date time
  6696. struct timeval tmnow;
  6697. struct tm *tm;
  6698. char buf[28];//, usec_buf[6];
  6699. gettimeofday(&tmnow, NULL);
  6700. time_t t;
  6701. t = time(NULL);
  6702. /*UTC time and date*/
  6703. tm = gmtime(&t);
  6704. if(dataType == ReadingContext_Sample_Clock)
  6705. {
  6706. struct tm *tmTarget;
  6707. struct timeb tbTarget;
  6708. tbTarget.time = mktime(tm);
  6709. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6710. tmTarget = gmtime(&tbTarget.time);
  6711. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6712. }
  6713. else
  6714. {
  6715. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6716. }
  6717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6718. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6719. //********************************(1)Current.Import L1************************************************/
  6720. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6721. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6722. (dataType == ReadingContext_Trigger))
  6723. {
  6724. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6725. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6726. {
  6727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6728. {
  6729. tempIndex = ((gun_index==2) ? 1: 0);
  6730. }
  6731. else
  6732. {
  6733. tempIndex = gun_index;
  6734. }
  6735. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6736. {
  6737. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6738. {
  6739. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6740. }
  6741. }
  6742. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6743. }
  6744. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6745. {
  6746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6747. {
  6748. tempIndex = ((gun_index==2) ? 1: 0);
  6749. }
  6750. else
  6751. {
  6752. tempIndex = gun_index;
  6753. }
  6754. for (int index = 0; index < CCS_QUANTITY; index++)
  6755. {
  6756. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6757. {
  6758. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6759. }
  6760. }
  6761. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6762. }
  6763. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6764. {
  6765. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6766. {
  6767. tempIndex = ((gun_index==2) ? 1: 0);
  6768. }
  6769. else
  6770. {
  6771. tempIndex = gun_index;
  6772. }
  6773. for (int index = 0; index < GB_QUANTITY; index++)
  6774. {
  6775. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6776. {
  6777. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6778. }
  6779. }
  6780. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6781. }
  6782. else if(gunType[gun_index] == GUN_TYPE_DO)
  6783. {
  6784. tempIndex = gun_index;
  6785. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6786. {
  6787. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6788. {
  6789. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6790. }
  6791. }
  6792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6793. }
  6794. else
  6795. {
  6796. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6797. {
  6798. tempIndex = 2;
  6799. }
  6800. else
  6801. {
  6802. tempIndex = gun_index;
  6803. }
  6804. for (int index = 0; index < AC_QUANTITY; index++)
  6805. {
  6806. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6807. {
  6808. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6809. }
  6810. }
  6811. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6812. }
  6813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6815. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6816. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6818. }
  6819. //********************************(2)Energy.Active.Import.Register ************************************************/
  6820. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6821. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6822. (dataType == ReadingContext_Trigger))
  6823. {
  6824. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6825. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6826. {
  6827. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6828. {
  6829. tempIndex = ((gun_index==2) ? 1: 0);
  6830. }
  6831. else
  6832. {
  6833. tempIndex = gun_index;
  6834. }
  6835. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6836. {
  6837. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6838. {
  6839. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6840. }
  6841. }
  6842. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6843. }
  6844. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6845. {
  6846. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6847. {
  6848. tempIndex = ((gun_index==2) ? 1: 0);
  6849. }
  6850. else
  6851. {
  6852. tempIndex = gun_index;
  6853. }
  6854. for (int index = 0; index < CCS_QUANTITY; index++)
  6855. {
  6856. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6857. {
  6858. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6859. }
  6860. }
  6861. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6862. }
  6863. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6864. {
  6865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6866. {
  6867. tempIndex = ((gun_index==2) ? 1: 0);
  6868. }
  6869. else
  6870. {
  6871. tempIndex = gun_index;
  6872. }
  6873. for (int index = 0; index < GB_QUANTITY; index++)
  6874. {
  6875. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6876. {
  6877. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6878. }
  6879. }
  6880. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6881. }
  6882. else if(gunType[gun_index] == GUN_TYPE_DO)
  6883. {
  6884. tempIndex = gun_index;
  6885. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6886. {
  6887. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6888. {
  6889. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6890. }
  6891. }
  6892. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6893. }
  6894. else
  6895. {
  6896. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6897. {
  6898. tempIndex = 2;
  6899. }
  6900. else
  6901. {
  6902. tempIndex = gun_index;
  6903. }
  6904. for (int index = 0; index < AC_QUANTITY; index++)
  6905. {
  6906. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6907. {
  6908. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6909. }
  6910. }
  6911. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6912. }
  6913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6918. }
  6919. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6920. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6921. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6922. (dataType == ReadingContext_Trigger))
  6923. {
  6924. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6925. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6926. {
  6927. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6928. {
  6929. tempIndex = ((gun_index==2) ? 1: 0);
  6930. }
  6931. else
  6932. {
  6933. tempIndex = gun_index;
  6934. }
  6935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6936. {
  6937. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6938. {
  6939. if(dataType == ReadingContext_Sample_Clock)
  6940. {
  6941. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6942. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6943. }
  6944. else if(dataType == ReadingContext_Sample_Periodic)
  6945. {
  6946. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6947. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6948. }
  6949. else
  6950. {
  6951. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6952. }
  6953. }
  6954. } // END OF FOR CHAdeMO_QUANTITY
  6955. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6956. }
  6957. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6958. {
  6959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6960. {
  6961. tempIndex = ((gun_index==2) ? 1: 0);
  6962. }
  6963. else
  6964. {
  6965. tempIndex = gun_index;
  6966. }
  6967. for (int index = 0; index < CCS_QUANTITY; index++)
  6968. {
  6969. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6970. {
  6971. if(dataType == ReadingContext_Sample_Clock)
  6972. {
  6973. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6974. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6975. }
  6976. else if(dataType == ReadingContext_Sample_Periodic)
  6977. {
  6978. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6979. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6980. }
  6981. else
  6982. {
  6983. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6984. }
  6985. }
  6986. } // END OF CCS_QUANTITY
  6987. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6988. }
  6989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6990. {
  6991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6992. {
  6993. tempIndex = ((gun_index==2) ? 1: 0);
  6994. }
  6995. else
  6996. {
  6997. tempIndex = gun_index;
  6998. }
  6999. for (int index = 0; index < GB_QUANTITY; index++)
  7000. {
  7001. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7002. {
  7003. if(dataType == ReadingContext_Sample_Clock)
  7004. {
  7005. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7006. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7007. }
  7008. else if(dataType == ReadingContext_Sample_Periodic)
  7009. {
  7010. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7011. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7012. }
  7013. else
  7014. {
  7015. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7016. }
  7017. }
  7018. } // END OF GB_QUANTITY
  7019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7020. }
  7021. else if(gunType[gun_index] == GUN_TYPE_DO)
  7022. {
  7023. tempIndex = gun_index;
  7024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7025. {
  7026. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7027. {
  7028. if(dataType == ReadingContext_Sample_Clock)
  7029. {
  7030. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7031. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7032. }
  7033. else if(dataType == ReadingContext_Sample_Periodic)
  7034. {
  7035. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7036. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7037. }
  7038. else
  7039. {
  7040. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7041. }
  7042. }
  7043. }
  7044. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7045. }
  7046. else
  7047. {
  7048. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7049. {
  7050. tempIndex = 2;
  7051. }
  7052. else
  7053. {
  7054. tempIndex = gun_index;
  7055. }
  7056. for (int index = 0; index < AC_QUANTITY; index++)
  7057. {
  7058. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7059. {
  7060. if(dataType == ReadingContext_Sample_Clock)
  7061. {
  7062. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7063. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7064. }
  7065. else if(dataType == ReadingContext_Sample_Periodic)
  7066. {
  7067. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7068. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7069. }
  7070. else
  7071. {
  7072. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7073. }
  7074. }
  7075. }
  7076. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7077. }
  7078. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7079. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7080. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7081. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7082. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7083. }
  7084. //********************************(4)Power.Active.Import************************************************/
  7085. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7086. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7087. (dataType == ReadingContext_Trigger))
  7088. {
  7089. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7090. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7091. {
  7092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7093. {
  7094. tempIndex = ((gun_index==2) ? 1: 0);
  7095. }
  7096. else
  7097. {
  7098. tempIndex = gun_index;
  7099. }
  7100. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7101. {
  7102. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7103. {
  7104. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7105. }
  7106. } // END OF FOR
  7107. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7108. }
  7109. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7110. {
  7111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7112. {
  7113. tempIndex = ((gun_index==2) ? 1: 0);
  7114. }
  7115. else
  7116. {
  7117. tempIndex = gun_index;
  7118. }
  7119. for (int index = 0; index < CCS_QUANTITY; index++)
  7120. {
  7121. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7122. {
  7123. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7124. }
  7125. }
  7126. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7127. }
  7128. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7129. {
  7130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7131. {
  7132. tempIndex = ((gun_index==2) ? 1: 0);
  7133. }
  7134. else
  7135. {
  7136. tempIndex = gun_index;
  7137. }
  7138. for (int index = 0; index < GB_QUANTITY; index++)
  7139. {
  7140. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7141. {
  7142. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7143. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7144. }
  7145. }
  7146. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7147. }
  7148. else if(gunType[gun_index] == GUN_TYPE_DO)
  7149. {
  7150. tempIndex = gun_index;
  7151. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7152. {
  7153. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7154. {
  7155. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7156. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7157. }
  7158. }
  7159. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7160. }
  7161. else
  7162. {
  7163. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7164. {
  7165. tempIndex = 2;
  7166. }
  7167. else
  7168. {
  7169. tempIndex = gun_index;
  7170. }
  7171. for (int index = 0; index < AC_QUANTITY; index++)
  7172. {
  7173. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7174. {
  7175. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7176. }
  7177. }
  7178. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7179. }
  7180. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7182. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7184. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7185. }
  7186. //***********************************************(5)VOLTAGE L1******************************************************/
  7187. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7188. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7189. (dataType == ReadingContext_Trigger))
  7190. {
  7191. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7192. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7193. {
  7194. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7195. {
  7196. tempIndex = ((gun_index==2) ? 1: 0);
  7197. }
  7198. else
  7199. {
  7200. tempIndex = gun_index;
  7201. }
  7202. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7203. {
  7204. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7205. {
  7206. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7207. }
  7208. }
  7209. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7210. }
  7211. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7212. {
  7213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7214. {
  7215. tempIndex = ((gun_index==2) ? 1: 0);
  7216. }
  7217. else
  7218. {
  7219. tempIndex = gun_index;
  7220. }
  7221. for (int index = 0; index < CCS_QUANTITY; index++)
  7222. {
  7223. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7224. {
  7225. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7226. }
  7227. }
  7228. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7229. }
  7230. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7231. {
  7232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7233. {
  7234. tempIndex = ((gun_index==2) ? 1: 0);
  7235. }
  7236. else
  7237. {
  7238. tempIndex = gun_index;
  7239. }
  7240. for (int index = 0; index < GB_QUANTITY; index++)
  7241. {
  7242. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7243. {
  7244. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7245. }
  7246. }
  7247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7248. }
  7249. else if(gunType[gun_index] == GUN_TYPE_DO)
  7250. {
  7251. tempIndex = gun_index;
  7252. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7253. {
  7254. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7255. {
  7256. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7257. }
  7258. }
  7259. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7260. }
  7261. else
  7262. {
  7263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7264. {
  7265. tempIndex = 2;
  7266. }
  7267. else
  7268. {
  7269. tempIndex = gun_index;
  7270. }
  7271. for (int index = 0; index < AC_QUANTITY; index++)
  7272. {
  7273. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7274. {
  7275. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7276. }
  7277. }
  7278. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7279. }
  7280. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7281. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7284. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7285. }
  7286. //***********************************************(6)SOC******************************************************/
  7287. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7288. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7289. (dataType == ReadingContext_Trigger))
  7290. {
  7291. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  7292. {
  7293. //idx_sample=5;
  7294. //sampledValue = NULL;
  7295. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7296. {
  7297. tempIndex = ((gun_index==2) ? 1: 0);
  7298. }
  7299. else
  7300. {
  7301. tempIndex = gun_index;
  7302. }
  7303. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7304. {
  7305. //tempIndex = ((gun_index==2) ? 1: 0);
  7306. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7307. {
  7308. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7309. {
  7310. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7311. }
  7312. }
  7313. }
  7314. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7315. {
  7316. //tempIndex = ((gun_index==2) ? 1: 0);
  7317. for (int index = 0; index < CCS_QUANTITY; index++)
  7318. {
  7319. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7320. {
  7321. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7322. }
  7323. }
  7324. }
  7325. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7326. {
  7327. //tempIndex = ((gun_index==2) ? 1: 0);
  7328. for (int index = 0; index < GB_QUANTITY; index++)
  7329. {
  7330. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7331. {
  7332. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7333. }
  7334. }
  7335. }
  7336. else if(gunType[gun_index] == GUN_TYPE_DO)
  7337. {
  7338. //tempIndex = ((gun_index==2) ? 1: 0);
  7339. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7340. {
  7341. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7342. {
  7343. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7344. }
  7345. }
  7346. }
  7347. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7348. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7349. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7350. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7353. }
  7354. }
  7355. //********************************(7)Current.Import L2************************************************/
  7356. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7357. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7358. (dataType == ReadingContext_Trigger))
  7359. {
  7360. // Only for AC 3 phase
  7361. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7362. {
  7363. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7364. {
  7365. tempIndex = 2;
  7366. }
  7367. else
  7368. {
  7369. tempIndex = gun_index;
  7370. }
  7371. for (int index = 0; index < AC_QUANTITY; index++)
  7372. {
  7373. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7374. {
  7375. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7376. }
  7377. }
  7378. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7379. }
  7380. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7381. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7382. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7383. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7384. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7385. }
  7386. //********************************(8)Current.Import L3************************************************/
  7387. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7388. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7389. (dataType == ReadingContext_Trigger))
  7390. {
  7391. // Only for AC 3 phase
  7392. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7393. {
  7394. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7395. {
  7396. tempIndex = 2;
  7397. }
  7398. else
  7399. {
  7400. tempIndex = gun_index;
  7401. }
  7402. for (int index = 0; index < AC_QUANTITY; index++)
  7403. {
  7404. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7405. {
  7406. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7407. }
  7408. }
  7409. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7410. }
  7411. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7412. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7413. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7416. }
  7417. //***********************************************(9)VOLTAGE L2******************************************************/
  7418. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7419. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7420. (dataType == ReadingContext_Trigger))
  7421. {
  7422. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7423. {
  7424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7425. {
  7426. tempIndex = 2;
  7427. }
  7428. else
  7429. {
  7430. tempIndex = gun_index;
  7431. }
  7432. for (int index = 0; index < AC_QUANTITY; index++)
  7433. {
  7434. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7435. {
  7436. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7437. }
  7438. }
  7439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7440. }
  7441. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7442. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7446. }
  7447. //***********************************************(10)VOLTAGE L3******************************************************/
  7448. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7449. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7450. (dataType == ReadingContext_Trigger))
  7451. {
  7452. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7453. {
  7454. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7455. {
  7456. tempIndex = 2;
  7457. }
  7458. else
  7459. {
  7460. tempIndex = gun_index;
  7461. }
  7462. for (int index = 0; index < AC_QUANTITY; index++)
  7463. {
  7464. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7465. {
  7466. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7467. }
  7468. }
  7469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7470. }
  7471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7474. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7475. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7476. }
  7477. //***********************************************(11)Current.Offered******************************************************/
  7478. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7479. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7480. (dataType == ReadingContext_Trigger))
  7481. {
  7482. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7483. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7484. {
  7485. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7486. {
  7487. tempIndex = ((gun_index==2) ? 1: 0);
  7488. }
  7489. else
  7490. {
  7491. tempIndex = gun_index;
  7492. }
  7493. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7494. {
  7495. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7496. {
  7497. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7498. }
  7499. } // END OF FOR CHAdeMO_QUANTITY
  7500. }
  7501. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7502. {
  7503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7504. {
  7505. tempIndex = ((gun_index==2) ? 1: 0);
  7506. }
  7507. else
  7508. {
  7509. tempIndex = gun_index;
  7510. }
  7511. for (int index = 0; index < CCS_QUANTITY; index++)
  7512. {
  7513. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7514. {
  7515. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7516. }
  7517. } // END OF CCS_QUANTITY
  7518. }
  7519. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7520. {
  7521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7522. {
  7523. tempIndex = ((gun_index==2) ? 1: 0);
  7524. }
  7525. else
  7526. {
  7527. tempIndex = gun_index;
  7528. }
  7529. for (int index = 0; index < GB_QUANTITY; index++)
  7530. {
  7531. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7532. {
  7533. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7534. }
  7535. } // END OF GB_QUANTITY
  7536. }
  7537. else if(gunType[gun_index] == GUN_TYPE_DO)
  7538. {
  7539. tempIndex = gun_index;
  7540. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7541. {
  7542. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7543. {
  7544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7545. }
  7546. }
  7547. }
  7548. else
  7549. {
  7550. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7551. {
  7552. tempIndex = 2;
  7553. }
  7554. else
  7555. {
  7556. tempIndex = gun_index;
  7557. }
  7558. for (int index = 0; index < AC_QUANTITY; index++)
  7559. {
  7560. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7561. {
  7562. uint16_t currentOffer;
  7563. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7564. {
  7565. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7566. }
  7567. else
  7568. {
  7569. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7570. }
  7571. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7572. }
  7573. }
  7574. }
  7575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7580. }
  7581. //***********************************************(12)Power.Offered******************************************************/
  7582. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7583. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7584. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7585. {
  7586. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7587. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7588. {
  7589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7590. {
  7591. tempIndex = ((gun_index==2) ? 1: 0);
  7592. }
  7593. else
  7594. {
  7595. tempIndex = gun_index;
  7596. }
  7597. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7598. {
  7599. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7600. {
  7601. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7602. }
  7603. } // END OF FOR CHAdeMO_QUANTITY
  7604. }
  7605. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7606. {
  7607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7608. {
  7609. tempIndex = ((gun_index==2) ? 1: 0);
  7610. }
  7611. else
  7612. {
  7613. tempIndex = gun_index;
  7614. }
  7615. for (int index = 0; index < CCS_QUANTITY; index++)
  7616. {
  7617. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7618. {
  7619. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7620. }
  7621. } // END OF CCS_QUANTITY
  7622. }
  7623. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7624. {
  7625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7626. {
  7627. tempIndex = ((gun_index==2) ? 1: 0);
  7628. }
  7629. else
  7630. {
  7631. tempIndex = gun_index;
  7632. }
  7633. for (int index = 0; index < GB_QUANTITY; index++)
  7634. {
  7635. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7636. {
  7637. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7638. }
  7639. } // END OF GB_QUANTITY
  7640. }
  7641. else if(gunType[gun_index] == GUN_TYPE_DO)
  7642. {
  7643. tempIndex = gun_index;
  7644. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7645. {
  7646. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7647. {
  7648. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7649. }
  7650. }
  7651. }
  7652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7657. }
  7658. // Message create ====================================================================================================
  7659. if(TRUE)
  7660. {
  7661. json_object *MeterValueReq = json_object_new_object();
  7662. json_object *MeterValues = json_object_new_array();
  7663. json_object *sampledValues = json_object_new_array();
  7664. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7665. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7666. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7667. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7668. {
  7669. json_object *MeterValue = json_object_new_object();
  7670. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7671. {
  7672. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7673. {
  7674. json_object *sampledValue = json_object_new_object();
  7675. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7676. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7677. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7678. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7679. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7680. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7681. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7682. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7683. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7684. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7685. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7686. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7687. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7688. json_object_array_add(sampledValues, sampledValue);
  7689. }
  7690. }
  7691. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7692. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7693. json_object_array_add(MeterValues, MeterValue);
  7694. }
  7695. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7696. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7697. ,gun_index + 1
  7698. ,MESSAGE_TYPE_CALL
  7699. ,guid
  7700. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7701. json_object_put(MeterValueReq);
  7702. }
  7703. // Put request guid to hash map
  7704. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7705. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  7706. {
  7707. result = PASS;
  7708. //DEBUG_INFO("MeterValues mapitem pass\n");
  7709. }
  7710. if((dataType != ReadingContext_Trigger) &&
  7711. (dataType != ReadingContext_Sample_Clock) &&
  7712. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7713. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7714. else
  7715. {
  7716. if(FirstHeartBeat)
  7717. LWS_Send(queuedata +2);
  7718. }
  7719. return result;
  7720. }
  7721. int sendLogStatusNotificationRequest(char *status)
  7722. {
  7723. mtrace();
  7724. int result = PASS;
  7725. char message[4096]={0};
  7726. char guid[37]={0};
  7727. char tempdata[128]={0};
  7728. json_object *LogStatusNotification = json_object_new_object();
  7729. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7730. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7731. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7732. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7733. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7734. random_uuid(guid);
  7735. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7736. json_object_put(LogStatusNotification);
  7737. LWS_Send(message);
  7738. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7739. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7740. {
  7741. result = PASS;
  7742. }
  7743. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7744. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7745. return result;
  7746. }
  7747. int sendSecurityEventNotificationRequest()
  7748. {
  7749. mtrace();
  7750. int result = PASS;
  7751. char message[4096]={0};
  7752. char guid[37]={0};
  7753. char tempdata[128]={0};
  7754. json_object *SecurityEventNotification = json_object_new_object();
  7755. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7756. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7757. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7758. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7759. random_uuid(guid);
  7760. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7761. json_object_put(SecurityEventNotification);
  7762. LWS_Send(message);
  7763. sprintf(tempdata, "SecurityEventNotification,0");
  7764. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7765. {
  7766. result = PASS;
  7767. }
  7768. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7769. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7770. return result;
  7771. }
  7772. int sendSignCertificateRequest()
  7773. {
  7774. mtrace();
  7775. int result = PASS;
  7776. char message[4096]={0};
  7777. char guid[37]={0};
  7778. char tempdata[128]={0};
  7779. json_object *SignCertificate = json_object_new_object();
  7780. DEBUG_INFO("sendSignCertificateRequest...\n");
  7781. // Read csr file content
  7782. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7783. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7784. char *line = NULL;
  7785. size_t len = 0;
  7786. while(getline(&line, &len, fp) != -1)
  7787. {
  7788. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7789. {
  7790. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7791. }
  7792. }
  7793. fclose(fp);
  7794. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7795. random_uuid(guid);
  7796. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7797. json_object_put(SignCertificate);
  7798. LWS_Send(message);
  7799. sprintf(tempdata, "SignCertificate,0");
  7800. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7801. {
  7802. result = PASS;
  7803. }
  7804. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7805. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7806. return result;
  7807. }
  7808. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7809. {
  7810. mtrace();
  7811. int result = PASS;
  7812. char message[110]={0};
  7813. char guid[37]={0};
  7814. char tempdata[65]={0};
  7815. json_object *FirmwareStatusNotification = json_object_new_object();
  7816. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7817. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7818. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7819. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7820. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7821. random_uuid(guid);
  7822. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7823. json_object_put(FirmwareStatusNotification);
  7824. LWS_Send(message);
  7825. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7826. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7827. {
  7828. result = PASS;
  7829. }
  7830. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7831. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7832. return result;
  7833. }
  7834. //==========================================
  7835. // send confirm routine
  7836. //==========================================
  7837. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7838. {
  7839. mtrace();
  7840. int result = FAIL;
  7841. char message[100]={0};
  7842. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7843. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7844. LWS_Send(message);
  7845. result = TRUE;
  7846. return result;
  7847. }
  7848. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7849. {
  7850. mtrace();
  7851. int result = FAIL;
  7852. char message[100]={0};
  7853. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7854. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7855. LWS_Send(message);
  7856. result = TRUE;
  7857. return result;
  7858. }
  7859. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7860. {
  7861. mtrace();
  7862. int result = FAIL;
  7863. char message[100]={0};
  7864. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7865. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7866. LWS_Send(message);
  7867. result = TRUE;
  7868. return result;
  7869. }
  7870. int sendClearCacheConfirmation(char *uuid,char *payload)
  7871. {
  7872. mtrace();
  7873. int result = FAIL;
  7874. char message[500]={0};
  7875. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7876. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7877. LWS_Send(message);
  7878. return result;
  7879. }
  7880. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7881. {
  7882. mtrace();
  7883. int result = FAIL;
  7884. char message[500]={0};
  7885. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7886. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7887. LWS_Send(message);
  7888. return result;
  7889. }
  7890. int sendDataTransferConfirmation(char *uuid,char *payload)
  7891. {
  7892. mtrace();
  7893. char statusStr[20]={0};
  7894. char dataStr[10]={0};
  7895. char sstr[20]={0};
  7896. int c = 0;
  7897. char *loc;
  7898. int result = FAIL;
  7899. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7900. /**********************status**************************/
  7901. loc = strstr(payload, "status");
  7902. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7903. c = 0;
  7904. while (loc[3+strlen("status")+c] != '\"')
  7905. {
  7906. sstr[c] = loc[3+strlen("status")+c];
  7907. c++;
  7908. }
  7909. sstr[c] = '\0';
  7910. strcpy(statusStr, sstr);
  7911. /**********************data**************************/
  7912. loc = strstr(payload, "data");
  7913. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7914. c = 0;
  7915. while (loc[3+strlen("data")+c] != '\"')
  7916. {
  7917. sstr[c] = loc[3+strlen("data")+c];
  7918. c++;
  7919. }
  7920. sstr[c] = '\0';
  7921. strcpy(dataStr, sstr);
  7922. return result;
  7923. }
  7924. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7925. {
  7926. mtrace();
  7927. int result = FAIL;
  7928. char message[1000]={0};
  7929. int CompositeScheduleIndex = 0;
  7930. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7931. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7932. if(nPeriod == 0)
  7933. {
  7934. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7935. {
  7936. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7937. ,MESSAGE_TYPE_CALLRESULT
  7938. ,uuid
  7939. ,payload
  7940. ,connectorIdInt);
  7941. }
  7942. else
  7943. {
  7944. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7945. ,MESSAGE_TYPE_CALLRESULT
  7946. ,uuid
  7947. ,payload
  7948. ,connectorIdInt
  7949. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7950. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7951. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7952. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7953. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7954. }
  7955. }
  7956. else
  7957. {
  7958. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7959. ,MESSAGE_TYPE_CALLRESULT
  7960. ,uuid
  7961. ,payload
  7962. ,connectorIdInt
  7963. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7964. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7965. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7966. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7967. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7968. {
  7969. if (idx_sample == 0)
  7970. {
  7971. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7972. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7973. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7974. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7975. }
  7976. else
  7977. {
  7978. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7979. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7980. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7981. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7982. }
  7983. }
  7984. sprintf(message + strlen(message), "]}}]");
  7985. }
  7986. LWS_Send(message);
  7987. result = TRUE;
  7988. return result;
  7989. }
  7990. int sendGetConfigurationConfirmation(char *uuid)
  7991. {
  7992. mtrace();
  7993. int result = FAIL;
  7994. int MaxKeySupported = 0;
  7995. int sentConfigurationNumber= 0;
  7996. int sentunConfigurationNumber= 0;
  7997. char message[1024*10]={0};
  7998. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7999. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8000. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8001. ,MESSAGE_TYPE_CALLRESULT
  8002. ,uuid );
  8003. //configuration key
  8004. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8005. {
  8006. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8007. {
  8008. if (sentConfigurationNumber == 0)
  8009. {
  8010. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8011. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8012. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8013. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8014. }
  8015. else
  8016. {
  8017. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8018. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8019. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8020. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8021. }
  8022. sentConfigurationNumber = sentConfigurationNumber + 1;
  8023. }
  8024. }
  8025. sprintf(message + strlen(message), "]");
  8026. if(UnknownKeynum != 0)
  8027. {
  8028. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8029. //unkown key
  8030. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8031. {
  8032. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8033. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8034. if(sentunConfigurationNumber == 0)
  8035. {
  8036. sprintf(message + strlen(message), "\"%s\""
  8037. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8038. }
  8039. else
  8040. {
  8041. sprintf(message + strlen(message), ",\"%s\""
  8042. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8043. }
  8044. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8045. }
  8046. sprintf(message + strlen(message), "]");
  8047. }
  8048. sprintf(message + strlen(message), "}]");
  8049. LWS_Send(message);
  8050. return result;
  8051. }
  8052. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8053. {
  8054. mtrace();
  8055. int result = FAIL;
  8056. char message[400]={0};
  8057. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8058. if(strcmp(payload,"")==0)
  8059. {
  8060. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8061. }
  8062. else
  8063. {
  8064. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8065. }
  8066. LWS_Send(message);
  8067. result = TRUE;
  8068. return result;
  8069. }
  8070. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8071. {
  8072. mtrace();
  8073. int result = FAIL;
  8074. char message[80]={0};
  8075. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8076. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8077. LWS_Send(message);
  8078. result = TRUE;
  8079. return result;
  8080. }
  8081. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8082. {
  8083. mtrace();
  8084. int result = FAIL;
  8085. char message[80]={0};
  8086. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8087. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8088. LWS_Send(message);
  8089. result = TRUE;
  8090. return result;
  8091. }
  8092. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8093. {
  8094. mtrace();
  8095. int result = FAIL;
  8096. char message[80]={0};
  8097. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8098. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8099. LWS_Send(message);
  8100. result = TRUE;
  8101. return result;
  8102. }
  8103. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8104. {
  8105. mtrace();
  8106. int result = FAIL;
  8107. char message[80]={0};
  8108. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8109. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8110. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8111. LWS_Send(message);
  8112. result = TRUE;
  8113. return result;
  8114. }
  8115. int sendResetConfirmation(char *uuid,char *payload)
  8116. {
  8117. mtrace();
  8118. int result = FAIL;
  8119. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8120. char message[80]={0};
  8121. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8122. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8123. LWS_Send(message);
  8124. result = TRUE;
  8125. return result;
  8126. }
  8127. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8128. {
  8129. mtrace();
  8130. int result = FAIL;
  8131. char message[500]={0};
  8132. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8133. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8134. LWS_Send(message);
  8135. result = TRUE;
  8136. return result;
  8137. }
  8138. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8139. {
  8140. mtrace();
  8141. int result = FAIL;
  8142. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8143. char message[80]={0};
  8144. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8145. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8146. LWS_Send(message);
  8147. result = TRUE;
  8148. return result;
  8149. }
  8150. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8151. {
  8152. mtrace();
  8153. int result = FAIL;
  8154. char message[80]={0};
  8155. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8156. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8157. LWS_Send(message);
  8158. result = TRUE;
  8159. return result;
  8160. }
  8161. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8162. {
  8163. mtrace();
  8164. int result = FAIL;
  8165. char message[80]={0};
  8166. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8167. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8168. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8169. LWS_Send(message);
  8170. result = TRUE;
  8171. return result;
  8172. }
  8173. int sendUpdateFirmwareConfirmation(char *uuid)
  8174. {
  8175. mtrace();
  8176. int result = FAIL;
  8177. char message[60]={0};
  8178. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8179. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8180. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8181. LWS_Send(message);
  8182. result = TRUE;
  8183. return result;
  8184. }
  8185. int sendCertificateSignedConfirmation(char *uuid)
  8186. {
  8187. mtrace();
  8188. int result = PASS;
  8189. char message[4096]={0};
  8190. json_object *CertificateSigned = json_object_new_object();
  8191. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8192. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8193. sprintf(message,"[%d,\"%s\",%s]"
  8194. ,MESSAGE_TYPE_CALLRESULT
  8195. ,uuid
  8196. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8197. json_object_put(CertificateSigned);
  8198. LWS_Send(message);
  8199. return result;
  8200. }
  8201. int sendDeleteCertificateConfirmation(char *uuid)
  8202. {
  8203. mtrace();
  8204. int result = PASS;
  8205. char message[4096]={0};
  8206. json_object *DeleteCertificate = json_object_new_object();
  8207. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8208. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8209. sprintf(message,"[%d,\"%s\",%s]"
  8210. ,MESSAGE_TYPE_CALLRESULT
  8211. ,uuid
  8212. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8213. json_object_put(DeleteCertificate);
  8214. LWS_Send(message);
  8215. return result;
  8216. }
  8217. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8218. {
  8219. mtrace();
  8220. int result = PASS;
  8221. char message[4096]={0};
  8222. json_object *ExtendedTriggerMessage = json_object_new_object();
  8223. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8224. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8225. sprintf(message,"[%d,\"%s\",%s]"
  8226. ,MESSAGE_TYPE_CALLRESULT
  8227. ,uuid
  8228. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8229. json_object_put(ExtendedTriggerMessage);
  8230. LWS_Send(message);
  8231. return result;
  8232. }
  8233. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8234. {
  8235. mtrace();
  8236. int result = PASS;
  8237. char message[4096]={0};
  8238. json_object *GetInstalledCertificateIds = json_object_new_object();
  8239. json_object *certificateHashDataDatas = json_object_new_array();
  8240. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8241. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8242. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8243. {
  8244. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8245. {
  8246. json_object *certificateHashData = json_object_new_object();
  8247. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8248. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8249. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8250. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8251. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8252. }
  8253. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8254. }
  8255. else
  8256. {
  8257. json_object_put(certificateHashDataDatas);
  8258. }
  8259. sprintf(message,"[%d,\"%s\",%s]"
  8260. ,MESSAGE_TYPE_CALLRESULT
  8261. ,uuid
  8262. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8263. json_object_put(GetInstalledCertificateIds);
  8264. LWS_Send(message);
  8265. return result;
  8266. }
  8267. int sendGetLogConfirmation(char *uuid)
  8268. {
  8269. mtrace();
  8270. int result = PASS;
  8271. char message[4096]={0};
  8272. json_object *GetLog = json_object_new_object();
  8273. DEBUG_INFO("sendGetLogConfirmation...\n");
  8274. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8275. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8276. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8277. sprintf(message,"[%d,\"%s\",%s]"
  8278. ,MESSAGE_TYPE_CALLRESULT
  8279. ,uuid
  8280. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8281. json_object_put(GetLog);
  8282. LWS_Send(message);
  8283. return result;
  8284. }
  8285. int sendInstallCertificateConfirmation(char *uuid)
  8286. {
  8287. mtrace();
  8288. int result = PASS;
  8289. char message[4096]={0};
  8290. json_object *InstallCertificate = json_object_new_object();
  8291. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8292. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8293. sprintf(message,"[%d,\"%s\",%s]"
  8294. ,MESSAGE_TYPE_CALLRESULT
  8295. ,uuid
  8296. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8297. json_object_put(InstallCertificate);
  8298. LWS_Send(message);
  8299. return result;
  8300. }
  8301. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8302. {
  8303. mtrace();
  8304. int result = PASS;
  8305. char message[4096]={0};
  8306. json_object *SignedUpdateFirmware = json_object_new_object();
  8307. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8308. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8309. sprintf(message,"[%d,\"%s\",%s]"
  8310. ,MESSAGE_TYPE_CALLRESULT
  8311. ,uuid
  8312. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8313. json_object_put(SignedUpdateFirmware);
  8314. LWS_Send(message);
  8315. return result;
  8316. }
  8317. int sendUnknownConfirmation(char *uuid)
  8318. {
  8319. mtrace();
  8320. int result = PASS;
  8321. char message[256]={0};
  8322. DEBUG_INFO("sendUnknownConfirmation...\n");
  8323. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8324. LWS_Send(message);
  8325. return result;
  8326. }
  8327. //==========================================
  8328. // Handle server request routine Start
  8329. //==========================================
  8330. int handleCancelReservationRequest(char *uuid, char *payload)
  8331. {
  8332. mtrace();
  8333. int result = FAIL;
  8334. int gunNO = 0;
  8335. int reservationIdInt = -1;
  8336. char comfirmstr[20];
  8337. DEBUG_INFO("handleCancelReservationRequest...\n");
  8338. json_object *CancelReservation;
  8339. CancelReservation = json_tokener_parse(payload);
  8340. if(!is_error(CancelReservation))
  8341. {
  8342. // Required data
  8343. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8344. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8345. }
  8346. json_object_put(CancelReservation);
  8347. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8348. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8349. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8350. if(reservationIdInt != -1)
  8351. {
  8352. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8353. //check Transaction active
  8354. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8356. {
  8357. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8358. {
  8359. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8360. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8361. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8362. {
  8363. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8364. }
  8365. else
  8366. {
  8367. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8368. }
  8369. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8370. goto end;
  8371. }
  8372. }
  8373. for (int index = 0; index < CCS_QUANTITY; index++)
  8374. {
  8375. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8376. {
  8377. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8378. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8379. if(gunType[2] == GUN_TYPE_CCS)
  8380. {
  8381. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8382. }
  8383. else
  8384. {
  8385. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8386. }
  8387. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8388. goto end;
  8389. }
  8390. }
  8391. for (int index = 0; index < GB_QUANTITY; index++)
  8392. {
  8393. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8394. {
  8395. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8396. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8397. if(gunType[2] == GUN_TYPE_GBT)
  8398. {
  8399. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8400. }
  8401. else
  8402. {
  8403. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8404. }
  8405. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8406. goto end;
  8407. }
  8408. }
  8409. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8410. {
  8411. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8412. {
  8413. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8414. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8415. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8416. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8417. goto end;
  8418. }
  8419. }
  8420. for (int index = 0; index < AC_QUANTITY; index++)
  8421. {
  8422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8423. {
  8424. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8425. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8426. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8427. {
  8428. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8429. }
  8430. else
  8431. {
  8432. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8433. }
  8434. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8435. goto end;
  8436. }
  8437. }
  8438. }
  8439. //The reservationId does NOT match the reservationId
  8440. sendCancelReservationConfirmation(uuid, comfirmstr);
  8441. end:
  8442. // Fill in ocpp packet uuid
  8443. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8444. return result;
  8445. }
  8446. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8447. {
  8448. mtrace();
  8449. int result = FAIL;
  8450. int gunIndex = -1;
  8451. char typeStr[16]={0};
  8452. char comfirmstr[20];
  8453. int specificId = FALSE;
  8454. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8455. json_object *ChangeAvailability;
  8456. ChangeAvailability = json_tokener_parse(payload);
  8457. if(!is_error(ChangeAvailability))
  8458. {
  8459. // Required data
  8460. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8461. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8462. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8463. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8464. }
  8465. json_object_put(ChangeAvailability);
  8466. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8467. {
  8468. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8469. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8470. }
  8471. else if(gunIndex == 0)
  8472. {
  8473. for(int i=0; i < gunTotalNumber; i++)
  8474. {
  8475. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8476. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8477. }
  8478. }
  8479. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8480. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8481. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8482. {
  8483. specificId = TRUE;
  8484. }
  8485. if(specificId == FALSE)
  8486. goto end;
  8487. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8488. {
  8489. //----------------------gunIndex is 0 ------------------------------------------------//
  8490. if(gunIndex == 0)
  8491. {
  8492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8493. {
  8494. for(int i=0; i < gunTotalNumber; i++)
  8495. {
  8496. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8497. {
  8498. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8499. {
  8500. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8501. {
  8502. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8503. goto end;
  8504. }
  8505. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8506. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8507. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8508. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8509. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8510. {
  8511. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8512. goto end;
  8513. }
  8514. }
  8515. }//END FOR CHAdeMO_QUANTITY
  8516. for (int index = 0; index < CCS_QUANTITY; index++)
  8517. {
  8518. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8519. {
  8520. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8521. {
  8522. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8523. goto end;
  8524. }
  8525. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8526. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8527. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8528. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8529. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8530. {
  8531. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8532. goto end;
  8533. }
  8534. }
  8535. }//END FOR CCS_QUANTITY
  8536. for (int index = 0; index < GB_QUANTITY; index++)
  8537. {
  8538. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8539. {
  8540. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8541. {
  8542. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8543. goto end;
  8544. }
  8545. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8546. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8547. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8548. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8549. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8550. {
  8551. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8552. goto end;
  8553. }
  8554. }
  8555. }// END FOR GB_QUANTITY
  8556. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8557. {
  8558. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8559. {
  8560. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8561. {
  8562. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8563. goto end;
  8564. }
  8565. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8566. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8567. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8568. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8569. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8570. {
  8571. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8572. goto end;
  8573. }
  8574. }
  8575. }// END FOR GENERAL_GUN_QUANTITY
  8576. for (int index = 0; index < AC_QUANTITY; index++)
  8577. {
  8578. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8579. {
  8580. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8581. {
  8582. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8583. goto end;
  8584. }
  8585. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8586. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8587. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8588. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8589. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8590. {
  8591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8592. goto end;
  8593. }
  8594. }
  8595. }//END FOR AC_QUANTITY
  8596. }// END FOR gunTotalNumber
  8597. }
  8598. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8599. {
  8600. for(int i=0; i < gunTotalNumber; i++)
  8601. {
  8602. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8603. {
  8604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8605. goto end;
  8606. }
  8607. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8608. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8609. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8610. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8611. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8612. {
  8613. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8614. goto end;
  8615. }
  8616. }
  8617. }
  8618. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8619. goto end;
  8620. }
  8621. //----------------------gunIndex is not 0 ------------------------------------------------//
  8622. //check Transaction active
  8623. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8624. {
  8625. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8626. {
  8627. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8628. {
  8629. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8630. goto end;
  8631. }
  8632. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8633. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8634. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8635. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8636. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8637. {
  8638. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8639. goto end;
  8640. }
  8641. else
  8642. {
  8643. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8644. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8645. goto end;
  8646. }
  8647. }
  8648. }//END FOR CHAdeMO_QUANTITY
  8649. for (int index = 0; index < CCS_QUANTITY; index++)
  8650. {
  8651. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8652. {
  8653. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8654. {
  8655. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8656. goto end;
  8657. }
  8658. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8659. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8660. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8661. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8662. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8663. {
  8664. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8665. goto end;
  8666. }
  8667. else
  8668. {
  8669. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8671. goto end;
  8672. }
  8673. }
  8674. }//END FOR CCS_QUANTITY
  8675. for (int index = 0; index < GB_QUANTITY; index++)
  8676. {
  8677. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8678. {
  8679. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8680. {
  8681. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8682. goto end;
  8683. }
  8684. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8685. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8686. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8687. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8688. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8689. {
  8690. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8691. goto end;
  8692. }
  8693. else
  8694. {
  8695. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8696. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8697. goto end;
  8698. }
  8699. }
  8700. }// END FOR GB_QUANTITY
  8701. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8702. {
  8703. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8704. {
  8705. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8706. {
  8707. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8708. goto end;
  8709. }
  8710. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8711. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8712. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8713. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8714. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8715. {
  8716. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8717. goto end;
  8718. }
  8719. else
  8720. {
  8721. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8722. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8723. goto end;
  8724. }
  8725. }
  8726. }// END FOR GENERAL_GUN_QUANTITY
  8727. for (int index = 0; index < AC_QUANTITY; index++)
  8728. {
  8729. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8730. {
  8731. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8732. {
  8733. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8734. goto end;
  8735. }
  8736. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8737. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8738. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8739. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8740. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8741. {
  8742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8743. goto end;
  8744. }
  8745. else
  8746. {
  8747. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8749. goto end;
  8750. }
  8751. }
  8752. }//END FOR AC_QUANTITY
  8753. }//END FOR AvailabilityTypeStr[Inoperative]
  8754. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8755. {
  8756. //----------------------gunIndex is 0 ------------------------------------------------//
  8757. if(gunIndex == 0)
  8758. {
  8759. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8760. {
  8761. for(int i=0; i < gunTotalNumber; i++)
  8762. {
  8763. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8764. {
  8765. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8766. {
  8767. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8768. goto end;
  8769. }
  8770. }//END FOR CHAdeMO_QUANTITY
  8771. for (int index = 0; index < CCS_QUANTITY; index++)
  8772. {
  8773. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8774. {
  8775. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8776. goto end;
  8777. }
  8778. }//END FOR CCS_QUANTITY
  8779. for (int index = 0; index < GB_QUANTITY; index++)
  8780. {
  8781. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8782. {
  8783. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8784. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8785. goto end;
  8786. }
  8787. }// END FOR GB_QUANTITY
  8788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8789. {
  8790. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8791. {
  8792. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8793. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8794. goto end;
  8795. }
  8796. }// END FOR GENERAL_GUN_QUANTITY
  8797. for (int index = 0; index < AC_QUANTITY; index++)
  8798. {
  8799. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8800. {
  8801. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8802. goto end;
  8803. }
  8804. }//END FOR CHAdeMO_QUANTITY
  8805. }// END FOR gunTotalNumber
  8806. }
  8807. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8808. {
  8809. for(int i=0; i < gunTotalNumber; i++)
  8810. {
  8811. for (int index = 0; index < AC_QUANTITY; index++)
  8812. {
  8813. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8814. {
  8815. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8816. goto end;
  8817. }
  8818. }//END FOR CHAdeMO_QUANTITY
  8819. } // END FOR gunTotalNumber
  8820. }
  8821. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8822. goto end;
  8823. }
  8824. //----------------------gunIndex is not 0 ------------------------------------------------//
  8825. //check Transaction active
  8826. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8827. {
  8828. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8829. {
  8830. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8831. goto end;
  8832. }
  8833. }//END FOR CHAdeMO_QUANTITY
  8834. for (int index = 0; index < CCS_QUANTITY; index++)
  8835. {
  8836. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8837. {
  8838. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8839. goto end;
  8840. }
  8841. }//END FOR CCS_QUANTITY
  8842. for (int index = 0; index < GB_QUANTITY; index++)
  8843. {
  8844. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8845. {
  8846. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8847. goto end;
  8848. }
  8849. }// END FOR GB_QUANTITY
  8850. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8851. {
  8852. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8853. {
  8854. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8855. goto end;
  8856. }
  8857. }// END FOR GENERAL_GUN_QUANTITY
  8858. for (int index = 0; index < AC_QUANTITY; index++)
  8859. {
  8860. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8861. {
  8862. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8863. goto end;
  8864. }
  8865. }//END FOR AC_QUANTITY
  8866. }//END FOR AvailabilityTypeStr[Operative]
  8867. end:
  8868. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8869. {
  8870. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8871. }
  8872. else
  8873. {
  8874. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8875. }
  8876. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8877. {
  8878. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8879. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8880. }
  8881. else if(gunIndex == 0)
  8882. {
  8883. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8884. {
  8885. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8886. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8887. }
  8888. }
  8889. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8890. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8891. return result;
  8892. }
  8893. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8894. {
  8895. mtrace();
  8896. int valueInvalid = NO;
  8897. int result = FAIL;
  8898. char keystr[40]={0};
  8899. char valuestr[501]={0}; //value should be limited in 500 bytes
  8900. char comfirmstr[20]={0};
  8901. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8902. json_object *ChangeConfiguration;
  8903. ChangeConfiguration = json_tokener_parse(payload);
  8904. if(!is_error(ChangeConfiguration))
  8905. {
  8906. // Required data
  8907. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8908. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8909. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8910. {
  8911. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8912. }
  8913. else
  8914. {
  8915. valueInvalid = YES;
  8916. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8917. }
  8918. }
  8919. json_object_put(ChangeConfiguration);
  8920. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8921. {
  8922. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8923. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8924. }
  8925. else
  8926. {
  8927. int status = setKeyValue(keystr, valuestr);
  8928. switch(status)
  8929. {
  8930. case ConfigurationStatus_Accepted:
  8931. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8932. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8933. StoreConfigurationTable();
  8934. break;
  8935. case RebootRequired:
  8936. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8937. StoreConfigurationTable();
  8938. break;
  8939. case NotSupported:
  8940. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8941. break;
  8942. case ConfigurationStatus_Rejected:
  8943. default:
  8944. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8945. break;
  8946. }
  8947. }
  8948. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8949. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8950. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8951. {
  8952. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8953. SetOcppConnStatus(FALSE);
  8954. }
  8955. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8956. {
  8957. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8958. }
  8959. return result;
  8960. }
  8961. int handleClearCacheRequest(char *uuid, char *payload)
  8962. {
  8963. mtrace();
  8964. int result = FAIL;
  8965. char comfirmstr[20];
  8966. char rmFileCmd[100]={0};
  8967. struct stat stats;
  8968. DEBUG_INFO("handleClearCacheRequest...\n");
  8969. stat("/Storage/OCPP", &stats);
  8970. // Check for directory existence
  8971. if (S_ISDIR(stats.st_mode) == 1)
  8972. {}
  8973. else
  8974. {
  8975. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8976. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8977. system(rmFileCmd);
  8978. }
  8979. if(OCPP_cleanLocalCache())
  8980. {
  8981. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8982. }
  8983. else
  8984. {
  8985. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8986. }
  8987. sendClearCacheConfirmation(uuid, comfirmstr);
  8988. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8989. return result;
  8990. }
  8991. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8992. {
  8993. mtrace();
  8994. int result = FAIL;
  8995. int resultRename;
  8996. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8997. char chargingProfilePurposeStr[26]={0};
  8998. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8999. char tempchargingProfilePurposeStr[26]={0};
  9000. char str[100]={0};
  9001. char fname[200]={0};
  9002. char comfirmstr[20]={0};
  9003. char word[1600]={0};
  9004. int clearflag = FALSE;
  9005. int chargingProfileIdIsNULL = FALSE;
  9006. int connectorIsNULL = FALSE;
  9007. int chargingProfilePurposeIsNULL = FALSE;
  9008. int stackLevelIsNULL = FALSE;
  9009. //int GotoEnd = FALSE;
  9010. FILE *fptr1, *fptr2;
  9011. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9012. int n_chargingProfile=0;
  9013. int isEmptyFile = FALSE;
  9014. char sLineWord[1600]={0};
  9015. char chargingProfiles[10][100]={0};
  9016. int ChargeProfileCount = 0;
  9017. int ch;
  9018. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9019. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9020. json_object *ClearChargingProfile;
  9021. ClearChargingProfile = json_tokener_parse(payload);
  9022. if(!is_error(ClearChargingProfile))
  9023. {
  9024. // Optional data
  9025. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9026. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9027. else
  9028. chargingProfileIdIsNULL = TRUE;
  9029. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9030. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9031. else
  9032. connectorIsNULL = TRUE;
  9033. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9034. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9035. else
  9036. chargingProfilePurposeIsNULL = TRUE;
  9037. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9038. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9039. else
  9040. stackLevelIsNULL = TRUE;
  9041. }
  9042. json_object_put(ClearChargingProfile);
  9043. if(connectorIsNULL == FALSE)
  9044. {
  9045. switch(connectorIdInt)
  9046. {
  9047. case 0:
  9048. if(chargingProfilePurposeIsNULL == TRUE)
  9049. {
  9050. int l = 0;
  9051. strcpy(fname, ChargePointMaxProfile_JSON);
  9052. if((access(fname,F_OK))!=-1)
  9053. {
  9054. strcpy(chargingProfiles[l], fname);
  9055. l = l + 1;
  9056. }
  9057. strcpy(fname, TxDefaultProfile_0_JSON);
  9058. if((access(fname,F_OK))!=-1)
  9059. {
  9060. strcpy(chargingProfiles[l], fname);
  9061. l = l + 1;
  9062. }
  9063. ChargeProfileCount = l;
  9064. }
  9065. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9066. {
  9067. strcpy(fname, ChargePointMaxProfile_JSON);
  9068. if((access(fname,F_OK))!=-1)
  9069. {
  9070. strcpy(chargingProfiles[0], fname);
  9071. ChargeProfileCount = 1;
  9072. }
  9073. }
  9074. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9075. {
  9076. strcpy(fname, TxDefaultProfile_0_JSON);
  9077. if((access(fname,F_OK))!=-1)
  9078. {
  9079. strcpy(chargingProfiles[0], fname);
  9080. ChargeProfileCount = 1;
  9081. }
  9082. }
  9083. break;
  9084. default:
  9085. if(chargingProfilePurposeIsNULL == TRUE)
  9086. {
  9087. int m = 0;
  9088. memset(fname, 0, ARRAY_SIZE(fname));
  9089. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9090. if((access(fname,F_OK))!=-1)
  9091. {
  9092. strcpy(chargingProfiles[m], fname);
  9093. m = m + 1;
  9094. }
  9095. memset(fname, 0, ARRAY_SIZE(fname));
  9096. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9097. if((access(fname,F_OK))!=-1)
  9098. {
  9099. strcpy(chargingProfiles[m], fname);
  9100. m = m + 1;
  9101. }
  9102. ChargeProfileCount = m;
  9103. }
  9104. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9105. {
  9106. //strcpy(fname, TxDefaultProfile_1_JSON);
  9107. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9108. if((access(fname,F_OK))!=-1)
  9109. {
  9110. strcpy(chargingProfiles[0], fname);
  9111. ChargeProfileCount = 1;
  9112. }
  9113. }
  9114. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9115. {
  9116. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9117. if((access(fname,F_OK))!=-1)
  9118. {
  9119. strcpy(chargingProfiles[0], fname);
  9120. ChargeProfileCount = 1;
  9121. }
  9122. //strcpy(fname, TxProfile_1_JSON);
  9123. }
  9124. //strcpy(fname, ChargePointMaxProfile_JSON );
  9125. break;
  9126. }
  9127. }
  9128. else // Check all Charging Profiles
  9129. {
  9130. int i = 0;
  9131. char fnametemp[200]={0};
  9132. ChargeProfileCount = 0;
  9133. //Check ChargePointMaxProfile.json exit
  9134. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9135. {
  9136. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9137. i = i + 1;
  9138. }
  9139. //Check TxDefaultProfile_0.json exit
  9140. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9141. {
  9142. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9143. i = i + 1;
  9144. }
  9145. //Check TxDefaultProfile_%d.json
  9146. for(int j=1; j <= gunTotalNumber; j++)
  9147. {
  9148. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9149. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9150. if((access(fnametemp,F_OK))!=-1)
  9151. {
  9152. strcpy(chargingProfiles[i], fnametemp);
  9153. i = i + 1;
  9154. }
  9155. }
  9156. //Check TxProfile_%d.json
  9157. for(int j=1; j <= gunTotalNumber; j++)
  9158. {
  9159. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9160. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9161. if((access(fnametemp,F_OK))!=-1)
  9162. {
  9163. strcpy(chargingProfiles[i], fnametemp);
  9164. i = i + 1;
  9165. }
  9166. }
  9167. ChargeProfileCount = i;
  9168. }// End connectorIsNULL is TRUE
  9169. if(ChargeProfileCount == 0)
  9170. {
  9171. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9172. goto end;
  9173. }
  9174. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9175. {
  9176. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9177. goto end;
  9178. }
  9179. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9180. {
  9181. memset(str, 0, ARRAY_SIZE(str));
  9182. // clear temp file
  9183. sprintf(str,"rm -f %s",temp);
  9184. system(str);
  9185. for(int k=0; k < ChargeProfileCount; k++)
  9186. {
  9187. memset(str, 0, ARRAY_SIZE(str));
  9188. //clear file in C
  9189. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9190. system(str);
  9191. }
  9192. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9193. goto end;
  9194. }
  9195. else if(connectorIsNULL == TRUE)
  9196. {
  9197. for(int k=0; k < ChargeProfileCount; k++)
  9198. {
  9199. fptr1 = fopen(chargingProfiles[k], "r");
  9200. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9201. //Check Charging Profile Count
  9202. while(fscanf(fptr1, "%s", word) != EOF)
  9203. {
  9204. //DEBUG_INFO("word=%s\n",word);
  9205. if(strstr(word, "chargingProfileId")!= NULL)
  9206. {
  9207. //DEBUG_INFO("test chargingProfileId \n");
  9208. n_chargingProfile = n_chargingProfile + 1;
  9209. //DEBUG_INFO("chargingProfileId Found\n");
  9210. }
  9211. }
  9212. rewind(fptr1);
  9213. //search Charging Profile Element
  9214. //int i= 0;
  9215. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9216. {
  9217. json_object *tmpProfilee;
  9218. tmpProfilee = json_tokener_parse(sLineWord);
  9219. if(!is_error(tmpProfilee))
  9220. {
  9221. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9222. {
  9223. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9224. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9225. }
  9226. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9227. {
  9228. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9229. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9230. }
  9231. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9232. {
  9233. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9234. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9235. }
  9236. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9237. {
  9238. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9239. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9240. }
  9241. }
  9242. json_object_put(tmpProfilee);
  9243. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9244. {
  9245. //------- not write to fptr2-------//
  9246. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9247. //clearflag = TRUE;
  9248. }
  9249. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9250. {
  9251. //------- not write to fptr2-------//
  9252. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9253. }
  9254. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9255. {
  9256. //------- not write to fptr2-------//
  9257. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9258. }
  9259. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9260. {
  9261. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9262. }
  9263. else
  9264. {
  9265. fprintf(fptr2, sLineWord);//writing data into file
  9266. }
  9267. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9268. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9269. if(clearflag == TRUE)
  9270. {
  9271. fclose(fptr1);
  9272. fclose(fptr2);
  9273. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9274. system(str);
  9275. // clear temp file
  9276. sprintf(str,"rm -f %s",temp);
  9277. system(str);
  9278. }
  9279. else
  9280. {
  9281. fclose(fptr1);
  9282. fclose(fptr2);
  9283. memset(str, 0, ARRAY_SIZE(str));
  9284. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9285. system(str);
  9286. resultRename = rename(temp, chargingProfiles[k]);
  9287. if(resultRename == 0)
  9288. {
  9289. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9290. }
  9291. else
  9292. {
  9293. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9294. }
  9295. if(comfirmstr[0]== 0)
  9296. {
  9297. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9298. }
  9299. //Check chargingProfile is empty file
  9300. /*------ Read the file ----------------*/
  9301. fptr1=fopen(chargingProfiles[k],"r");
  9302. ch=fgetc(fptr1);
  9303. rewind(fptr1);
  9304. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9305. if(ch!=EOF)
  9306. {
  9307. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9308. {
  9309. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9310. if(sLineWord[0]=='\0')
  9311. {
  9312. isEmptyFile = TRUE;
  9313. break;
  9314. }
  9315. else
  9316. {
  9317. isEmptyFile = FALSE;
  9318. break;
  9319. }
  9320. }
  9321. }
  9322. else
  9323. isEmptyFile = TRUE;
  9324. fclose(fptr1);
  9325. if(isEmptyFile == TRUE)
  9326. {
  9327. memset(str, 0, ARRAY_SIZE(str));
  9328. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9329. system(str);
  9330. }
  9331. }
  9332. }// End of while(int k=0; k < ChargePointCount; k++)
  9333. }
  9334. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9335. {
  9336. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9337. for(int k=0; k < ChargeProfileCount; k++)
  9338. {
  9339. fptr1 = fopen(chargingProfiles[k], "r");
  9340. fptr2 = fopen(temp, "w+");
  9341. //Check Charging Profile Count
  9342. while(fscanf(fptr1, "%s", word) != EOF)
  9343. {
  9344. //DEBUG_INFO("word=%s\n",word);
  9345. if(strstr(word, "chargingProfileId")!= NULL)
  9346. {
  9347. n_chargingProfile = n_chargingProfile + 1;
  9348. }
  9349. }
  9350. rewind(fptr1);
  9351. //search Charging Profile Element
  9352. //int i= 0;
  9353. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9354. {
  9355. json_object *tmpProfilee;
  9356. tmpProfilee = json_tokener_parse(sLineWord);
  9357. if(!is_error(tmpProfilee))
  9358. {
  9359. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9360. {
  9361. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9362. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9363. }
  9364. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9365. {
  9366. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9367. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9368. }
  9369. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9370. {
  9371. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9372. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9373. }
  9374. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9375. {
  9376. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9377. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9378. }
  9379. }
  9380. json_object_put(tmpProfilee);
  9381. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9382. {
  9383. //------- not write to fptr2-------//
  9384. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9385. //clearflag = TRUE;
  9386. }
  9387. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9388. {
  9389. //------- not write to fptr2-------//
  9390. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9391. }
  9392. else if(stackLevelIsNULL == TRUE)
  9393. {
  9394. //Clear Whole File
  9395. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9396. clearflag = TRUE;
  9397. break;
  9398. }
  9399. else
  9400. {
  9401. fprintf(fptr2, sLineWord);//writing data into file
  9402. }
  9403. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9404. }
  9405. if(clearflag == TRUE)
  9406. {
  9407. fclose(fptr1);
  9408. fclose(fptr2);
  9409. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9410. system(str);
  9411. // clear temp file
  9412. sprintf(str,"rm -f %s",temp);
  9413. system(str);
  9414. }
  9415. else
  9416. {
  9417. fclose(fptr1);
  9418. fclose(fptr2);
  9419. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9420. system(str);
  9421. resultRename = rename(temp, chargingProfiles[k]);
  9422. if(resultRename == 0)
  9423. {
  9424. DEBUG_INFO("File ChargingProfile renamed successfully");
  9425. }
  9426. else
  9427. {
  9428. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9429. }
  9430. if(comfirmstr[0]== 0)
  9431. {
  9432. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9433. }
  9434. //Check chargingProfile is empty file
  9435. /*------ Read the file ----------------*/
  9436. fptr1=fopen(chargingProfiles[k],"r");
  9437. ch=fgetc(fptr1);
  9438. rewind(fptr1);
  9439. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9440. if(ch!=EOF)
  9441. {
  9442. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9443. {
  9444. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9445. if(sLineWord[0]=='\0')
  9446. {
  9447. isEmptyFile = TRUE;
  9448. break;
  9449. }
  9450. else
  9451. {
  9452. isEmptyFile = FALSE;
  9453. break;
  9454. }
  9455. }
  9456. }
  9457. else
  9458. isEmptyFile = TRUE;
  9459. fclose(fptr1);
  9460. if(isEmptyFile == TRUE)
  9461. {
  9462. memset(str, 0, ARRAY_SIZE(str));
  9463. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9464. system(str);
  9465. }
  9466. /*------- End of reading ---------------*/
  9467. }
  9468. } // while(int k=0; k < ChargeProfileCount; k++)
  9469. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9470. end:
  9471. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9472. {
  9473. if(connectorIdInt == 0)
  9474. {
  9475. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9476. {
  9477. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9478. }
  9479. }
  9480. else
  9481. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9482. }
  9483. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9484. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9485. return result;
  9486. }
  9487. void createFirmwareVersionByDataTransfer(void)
  9488. {
  9489. json_object *FirmwareDataTransfer = json_object_new_object();
  9490. // AC & DC model
  9491. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9492. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9493. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9494. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9495. // DC model
  9496. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9497. {
  9498. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9499. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9500. (gunType[3] != GUN_TYPE_UNKNOWN))
  9501. {
  9502. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9503. }
  9504. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9505. {
  9506. // DS DM DW
  9507. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9508. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9509. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9510. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9511. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9512. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9513. }
  9514. else
  9515. {
  9516. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9517. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9518. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9519. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9520. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9521. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9522. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9523. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9524. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9525. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9526. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9527. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9528. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9529. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9530. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9531. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9532. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9533. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9534. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9535. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9536. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9537. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9538. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9539. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9540. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9541. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9542. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9543. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9544. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9545. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9546. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9547. }
  9548. }
  9549. // 4G model
  9550. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9551. {
  9552. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9553. }
  9554. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9555. json_object_put(FirmwareDataTransfer);
  9556. }
  9557. int handleDataTransferRequest(char *uuid, char *payload)
  9558. {
  9559. mtrace();
  9560. json_object *response = json_object_new_object();
  9561. int result = FAIL;
  9562. char tempvendorId[255]={0};
  9563. char tempmessageId[50]={0};
  9564. char tempdata[1024]={0};
  9565. char message[2048]={0};
  9566. DEBUG_INFO("handleDataTransferRequest...\n");
  9567. if((uuid != NULL) && (payload != NULL))
  9568. {
  9569. json_object *DataTransfer;
  9570. DataTransfer = json_tokener_parse(payload);
  9571. if(!is_error(DataTransfer))
  9572. {
  9573. // Required data
  9574. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9575. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9576. // Optional data
  9577. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9578. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9579. if(json_object_object_get(DataTransfer, "data") != NULL)
  9580. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9581. result = PASS;
  9582. }
  9583. json_object_put(DataTransfer);
  9584. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9585. {
  9586. // Send all moudle firmware version on EVSE
  9587. createFirmwareVersionByDataTransfer();
  9588. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9589. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9590. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9591. json_object_put(response);
  9592. }
  9593. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9594. {
  9595. system("/usr/bin/run_tmate_restart.sh &");
  9596. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9597. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9598. json_object_put(response);
  9599. }
  9600. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9601. {
  9602. json_object *data;
  9603. data = json_tokener_parse(tempdata);
  9604. if(!is_error(data))
  9605. {
  9606. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9607. {
  9608. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9609. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9610. if(json_object_object_get(data, "SOC") != NULL)
  9611. {
  9612. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9613. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9614. }
  9615. if(json_object_object_get(data, "Energy") != NULL)
  9616. {
  9617. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9618. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9619. }
  9620. if(json_object_object_get(data, "Duration") != NULL)
  9621. {
  9622. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9623. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9624. }
  9625. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9626. }
  9627. else
  9628. {
  9629. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9630. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9631. }
  9632. }
  9633. else
  9634. {
  9635. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9636. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9637. }
  9638. json_object_put(data);
  9639. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9640. json_object_put(response);
  9641. }
  9642. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9643. {
  9644. json_object *data;
  9645. data = json_tokener_parse(tempdata);
  9646. if(!is_error(data))
  9647. {
  9648. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9649. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9650. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9651. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9652. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9653. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9654. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9655. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9656. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9657. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9658. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9659. }
  9660. else
  9661. {
  9662. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9663. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9664. }
  9665. json_object_put(data);
  9666. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9667. json_object_put(response);
  9668. }
  9669. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9670. {
  9671. json_object *data;
  9672. data = json_tokener_parse(tempdata);
  9673. if(!is_error(data))
  9674. {
  9675. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9676. if(json_object_object_get(data, "idToken") != NULL)
  9677. {
  9678. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9679. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9680. }
  9681. if(json_object_object_get(data, "price") != NULL)
  9682. {
  9683. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9684. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9685. }
  9686. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9687. }
  9688. else
  9689. {
  9690. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9691. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9692. }
  9693. json_object_put(data);
  9694. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9695. json_object_put(response);
  9696. }
  9697. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9698. {
  9699. json_object *data;
  9700. data = json_tokener_parse(tempdata);
  9701. if(!is_error(data))
  9702. {
  9703. if(json_object_object_get(data, "txId") != NULL)
  9704. {
  9705. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9706. for(int idx = 0;idx<gunTotalNumber;idx++)
  9707. {
  9708. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9709. {
  9710. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9711. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9712. if(json_object_object_get(data, "description") != NULL)
  9713. {
  9714. // California pricing V1.0
  9715. DEBUG_INFO("California pricing V1.0\n");
  9716. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9717. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9718. }
  9719. else
  9720. {
  9721. // California pricing V1.1
  9722. DEBUG_INFO("California pricing V1.1\n");
  9723. if(json_object_object_get(data, "timestamp") != NULL)
  9724. {
  9725. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9726. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9727. }
  9728. if(json_object_object_get(data, "meterValue") != NULL)
  9729. {
  9730. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9731. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9732. }
  9733. if(json_object_object_get(data, "cost") != NULL)
  9734. {
  9735. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9736. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9737. }
  9738. if(json_object_object_get(data, "state") != NULL)
  9739. {
  9740. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9741. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9742. }
  9743. if(json_object_object_get(data, "chargingPrice") != NULL)
  9744. {
  9745. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9746. {
  9747. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9748. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9749. }
  9750. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9751. {
  9752. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9753. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9754. }
  9755. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9756. {
  9757. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9758. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9759. }
  9760. }
  9761. if(json_object_object_get(data, "idlePrice") != NULL)
  9762. {
  9763. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9764. {
  9765. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9766. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9767. }
  9768. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9769. {
  9770. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9771. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9772. }
  9773. }
  9774. if(json_object_object_get(data, "nextPeriod") != NULL)
  9775. {
  9776. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9777. {
  9778. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9779. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9780. }
  9781. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9782. {
  9783. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9784. {
  9785. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  9786. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  9787. }
  9788. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9789. {
  9790. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  9791. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  9792. }
  9793. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9794. {
  9795. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  9796. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  9797. }
  9798. }
  9799. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9800. {
  9801. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9802. {
  9803. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  9804. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  9805. }
  9806. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9807. {
  9808. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  9809. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  9810. }
  9811. }
  9812. }
  9813. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9814. {
  9815. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9816. {
  9817. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9818. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9819. }
  9820. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9821. {
  9822. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9823. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9824. }
  9825. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9826. {
  9827. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9828. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9829. }
  9830. }
  9831. }
  9832. }
  9833. }
  9834. }
  9835. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9836. }
  9837. else
  9838. {
  9839. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9840. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9841. }
  9842. json_object_put(data);
  9843. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9844. json_object_put(response);
  9845. }
  9846. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9847. {
  9848. json_object *data;
  9849. data = json_tokener_parse(tempdata);
  9850. if(!is_error(data))
  9851. {
  9852. if(json_object_object_get(data, "txId") != NULL)
  9853. {
  9854. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9855. for(int idx = 0;idx<gunTotalNumber;idx++)
  9856. {
  9857. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9858. {
  9859. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9860. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9861. if(json_object_object_get(data, "description") != NULL)
  9862. {
  9863. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9864. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9865. }
  9866. }
  9867. }
  9868. }
  9869. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9870. }
  9871. else
  9872. {
  9873. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9874. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9875. }
  9876. json_object_put(data);
  9877. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9878. json_object_put(response);
  9879. }
  9880. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9881. {
  9882. json_object *data;
  9883. data = json_tokener_parse(tempdata);
  9884. if(!is_error(data))
  9885. {
  9886. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9887. if(json_object_object_get(data, "Content_Type") != NULL)
  9888. {
  9889. if((0 <= json_object_get_int(json_object_object_get(data, "Content_Type"))) && (json_object_get_int(json_object_object_get(data, "Content_Type")) <= 1))
  9890. {
  9891. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9892. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9893. {
  9894. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9895. }
  9896. }
  9897. else
  9898. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9899. }
  9900. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9901. }
  9902. else
  9903. {
  9904. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9905. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9906. }
  9907. json_object_put(data);
  9908. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9909. json_object_put(response);
  9910. }
  9911. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9912. {
  9913. json_object *data;
  9914. data = json_tokener_parse(tempdata);
  9915. if(!is_error(data))
  9916. {
  9917. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9918. if(json_object_object_get(data, "ConnectorId") != NULL)
  9919. {
  9920. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9921. }
  9922. if(json_object_object_get(data, "SerialNo") != NULL)
  9923. {
  9924. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9925. }
  9926. if(json_object_object_get(data, "Page_Index") != NULL)
  9927. {
  9928. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9929. }
  9930. if(json_object_object_get(data, "Duration") != NULL)
  9931. {
  9932. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9933. }
  9934. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9935. }
  9936. else
  9937. {
  9938. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9939. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9940. }
  9941. json_object_put(data);
  9942. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9943. json_object_put(response);
  9944. }
  9945. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9946. {
  9947. json_object *data;
  9948. data = json_tokener_parse(tempdata);
  9949. if(!is_error(data))
  9950. {
  9951. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9952. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9953. {
  9954. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9955. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9956. else
  9957. {
  9958. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9959. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9960. }
  9961. }
  9962. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9963. {
  9964. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9965. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9966. else
  9967. {
  9968. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9969. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9970. }
  9971. }
  9972. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9973. {
  9974. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9975. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9976. else
  9977. {
  9978. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9979. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9980. }
  9981. }
  9982. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9983. {
  9984. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9985. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9986. else
  9987. {
  9988. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9989. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9990. }
  9991. }
  9992. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9993. {
  9994. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9995. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9996. else
  9997. {
  9998. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9999. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10000. }
  10001. }
  10002. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10003. {
  10004. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10005. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10006. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10007. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10008. else
  10009. {
  10010. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10011. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10012. }
  10013. }
  10014. if(json_object_object_get(data, "isAuthentication") != NULL)
  10015. {
  10016. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10017. {
  10018. case 0:
  10019. case 1:
  10020. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10021. break;
  10022. default:
  10023. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10024. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10025. break;
  10026. }
  10027. }
  10028. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10029. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10030. }
  10031. else
  10032. {
  10033. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10034. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10035. }
  10036. json_object_put(data);
  10037. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10038. json_object_put(response);
  10039. }
  10040. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10041. {
  10042. json_object *data;
  10043. data = json_tokener_parse(tempdata);
  10044. if(!is_error(data))
  10045. {
  10046. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10047. {
  10048. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10049. {
  10050. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10051. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10052. }
  10053. else
  10054. {
  10055. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10056. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10057. }
  10058. }
  10059. else
  10060. {
  10061. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10062. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10063. }
  10064. }
  10065. else
  10066. {
  10067. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10068. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10069. }
  10070. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10071. json_object_put(response);
  10072. }
  10073. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10074. {
  10075. json_object *data;
  10076. data = json_tokener_parse(tempdata);
  10077. if(!is_error(data))
  10078. {
  10079. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10080. if(json_object_object_get(data, "stationName") != NULL)
  10081. {
  10082. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10083. }
  10084. else
  10085. {
  10086. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10087. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10088. }
  10089. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10090. {
  10091. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10092. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10093. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10094. }
  10095. }
  10096. else
  10097. {
  10098. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10099. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10100. }
  10101. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10102. json_object_put(response);
  10103. }
  10104. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10105. {
  10106. json_object *data;
  10107. data = json_tokener_parse(tempdata);
  10108. if(!is_error(data))
  10109. {
  10110. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10111. if(json_object_object_get(data, "weatherId") != NULL)
  10112. {
  10113. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10114. }
  10115. else
  10116. {
  10117. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10118. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10119. }
  10120. if(json_object_object_get(data, "Temperature") != NULL)
  10121. {
  10122. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10123. }
  10124. else
  10125. {
  10126. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10127. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10128. }
  10129. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10130. {
  10131. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10132. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10133. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10134. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10135. );
  10136. }
  10137. }
  10138. else
  10139. {
  10140. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10141. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10142. }
  10143. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10144. json_object_put(response);
  10145. }
  10146. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10147. {
  10148. json_object *data;
  10149. data = json_tokener_parse(tempdata);
  10150. if(!is_error(data))
  10151. {
  10152. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10153. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10154. {
  10155. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10156. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10157. }
  10158. else
  10159. {
  10160. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10161. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10162. }
  10163. }
  10164. else
  10165. {
  10166. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10167. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10168. }
  10169. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10170. json_object_put(response);
  10171. }
  10172. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10173. {
  10174. json_object *data;
  10175. data = json_tokener_parse(tempdata);
  10176. if(!is_error(data))
  10177. {
  10178. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10179. {
  10180. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10181. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10182. if(gun_index < gunTotalNumber)
  10183. {
  10184. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10185. {
  10186. json_object *responsedata = json_object_new_object();
  10187. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10188. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10189. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10190. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10191. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10192. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10193. }
  10194. else
  10195. {
  10196. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10197. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10198. }
  10199. }
  10200. else
  10201. {
  10202. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10203. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10204. }
  10205. }
  10206. else
  10207. {
  10208. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10209. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10210. }
  10211. }
  10212. else
  10213. {
  10214. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10215. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10216. }
  10217. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10218. json_object_put(response);
  10219. }
  10220. else
  10221. {
  10222. // Can not find valid message id
  10223. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10224. }
  10225. }
  10226. else
  10227. {
  10228. // Payload is null
  10229. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10230. }
  10231. LWS_Send(message);
  10232. return result;
  10233. }
  10234. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10235. {
  10236. mtrace();
  10237. int result = FAIL;
  10238. int connectorIdInt, durationInt;
  10239. char chargingRateUnitStr[4]={0};
  10240. char comfirmstr[20];
  10241. int confirmPeriods = 0;
  10242. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10243. json_object *GetCompositeSchedule;
  10244. GetCompositeSchedule = json_tokener_parse(payload);
  10245. if(!is_error(GetCompositeSchedule))
  10246. {
  10247. // Required data
  10248. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10249. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10250. else
  10251. connectorIdInt = -1;
  10252. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10253. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10254. else
  10255. durationInt = 86400;
  10256. // Optional data
  10257. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10258. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10259. }
  10260. json_object_put(GetCompositeSchedule);
  10261. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10262. if((connectorIdInt == 0) ||
  10263. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10264. {
  10265. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10266. struct StructChargingProfile tmpProfile[1];
  10267. if(strstr(chargingRateUnitStr, "W") != NULL)
  10268. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10269. else
  10270. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10271. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10272. {
  10273. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10274. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10275. }
  10276. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10277. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10278. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10279. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10280. {
  10281. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10282. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10283. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10284. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10285. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10286. {
  10287. confirmPeriods = idx;
  10288. break;
  10289. }
  10290. }
  10291. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10292. {
  10293. confirmPeriods += 1;
  10294. }
  10295. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10296. }
  10297. else
  10298. {
  10299. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10300. }
  10301. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10302. return result;
  10303. }
  10304. int handleGetConfigurationRequest(char *uuid, char *payload)
  10305. {
  10306. mtrace();
  10307. int result = FAIL;
  10308. int MaxKeySupported = 0;
  10309. int n_keys = 0;
  10310. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10311. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10312. json_object *GetConfiguration;
  10313. GetConfiguration = json_tokener_parse(payload);
  10314. if(!is_error(GetConfiguration))
  10315. {
  10316. // Optional data
  10317. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10318. {
  10319. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10320. {
  10321. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10322. n_keys = idx + 1;
  10323. }
  10324. }
  10325. }
  10326. json_object_put(GetConfiguration);
  10327. UnknownKeynum = 0;
  10328. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10329. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10330. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10331. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10332. if(n_keys != 0)
  10333. {
  10334. for(int i=0;i<n_keys;i++)
  10335. {
  10336. getKeyValue(requestKey[i]);
  10337. }
  10338. }
  10339. else
  10340. {
  10341. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10342. getKeyValue("");
  10343. }
  10344. processUnkownKey();
  10345. sendGetConfigurationConfirmation(uuid);
  10346. return result;
  10347. }
  10348. static char fnamePlusPath[100]={0};
  10349. static char fnamePWithNoPath[60]={0};
  10350. void checkUploadLog(void)
  10351. {
  10352. FILE *fp;
  10353. /* Open the command for reading. */
  10354. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10355. if (fp == NULL) {
  10356. DEBUG_WARN("Failed to run command\n" );
  10357. exit(1);
  10358. }
  10359. int ftppathlen = 0;
  10360. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10361. int i = 0;
  10362. /* Read the output a line at a time - output it. */
  10363. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10364. if(i==0)
  10365. {
  10366. ftppathlen = strlen(fnamePlusPath);
  10367. DEBUG_INFO("%s\n", fnamePlusPath);
  10368. fnamePlusPath[ftppathlen]='\0';
  10369. break;
  10370. }
  10371. i= i+1;
  10372. }
  10373. /* close */
  10374. pclose(fp);
  10375. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10376. {
  10377. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10378. {
  10379. fnamePlusPath[k]='\0';
  10380. }
  10381. }
  10382. i=1;
  10383. //char fname[60]={0};
  10384. while(i < ftppathlen)
  10385. {
  10386. int len=ftppathlen-i;
  10387. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10388. {
  10389. DEBUG_INFO("compare '/' all right\n");
  10390. break;
  10391. }
  10392. i=i+1;
  10393. }
  10394. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10395. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10396. fnamePWithNoPath[i+1] = '\0';
  10397. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10398. {
  10399. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10400. {
  10401. fnamePWithNoPath[j]='\0';
  10402. }
  10403. }
  10404. FILE* fp1 = fopen(fnamePlusPath, "r");
  10405. if (fp1)
  10406. {
  10407. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10408. // file exists
  10409. fclose(fp1);
  10410. }
  10411. else
  10412. {
  10413. // file doesn't exist
  10414. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10415. }
  10416. }
  10417. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10418. {
  10419. mtrace();
  10420. int result = FAIL;
  10421. time_t CurrentTime;
  10422. struct tm *tm;
  10423. pthread_t th_Status;
  10424. CurrentTime = time(NULL);
  10425. tm = localtime(&CurrentTime);
  10426. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10427. sprintf((char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName, "%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  10428. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10429. if(!interLock.isGetDiagnosticGoing)
  10430. {
  10431. interLock.isGetDiagnosticGoing = 1;
  10432. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10433. sleep(1);
  10434. }
  10435. else
  10436. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10437. return result;
  10438. }
  10439. void* GetDiagnosticsProcess(void* data)
  10440. {
  10441. pthread_detach(pthread_self());
  10442. mtrace();
  10443. int retriesInt=0, retryIntervalInt=0;
  10444. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10445. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  10446. int port=0;
  10447. int isSuccess = FALSE;
  10448. char cmdBuf[2048];
  10449. struct tm *tmNow;
  10450. time_t CurrentTime;
  10451. struct tm tmStart;
  10452. struct tm tmStop;
  10453. CurrentTime = time(NULL);
  10454. tmNow=localtime(&CurrentTime);
  10455. uint16_t targetYear, targetMonth;
  10456. json_object *GetDiagnostics;
  10457. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10458. GetDiagnostics = json_tokener_parse(data);
  10459. if(!is_error(GetDiagnostics))
  10460. {
  10461. // Required data
  10462. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10463. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10464. // Optional data
  10465. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10466. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10467. else
  10468. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10469. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10470. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10471. else
  10472. retryIntervalInt = 30;
  10473. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10474. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10475. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10476. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10477. }
  10478. json_object_put(GetDiagnostics);
  10479. // Pack log to compress file
  10480. if((sscanf((char*)startTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  10481. (sscanf((char*)stopTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  10482. {
  10483. // Pack system log
  10484. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10485. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10486. targetYear = tmStart.tm_year;
  10487. targetMonth = tmStart.tm_mon;
  10488. do
  10489. {
  10490. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10491. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10492. if(targetMonth+1>=13)
  10493. {
  10494. targetYear += 1;
  10495. targetMonth = 1;
  10496. }
  10497. else
  10498. {
  10499. targetMonth += 1;
  10500. }
  10501. }while((targetYear < (tmNow->tm_year+1900)) ||
  10502. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10503. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10504. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10505. system(cmdBuf);
  10506. // Pack charging & event log
  10507. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10508. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10509. targetYear = tmStart.tm_year;
  10510. targetMonth = tmStart.tm_mon;
  10511. do
  10512. {
  10513. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10514. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10515. if(targetMonth+1>=13)
  10516. {
  10517. targetYear += 1;
  10518. targetMonth = 1;
  10519. }
  10520. else
  10521. {
  10522. targetMonth += 1;
  10523. }
  10524. }while((targetYear < (tmNow->tm_year+1900)) ||
  10525. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10526. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10527. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10528. system(cmdBuf);
  10529. // Combine log file
  10530. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10531. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10532. }
  10533. else
  10534. {
  10535. system("exec /root/logPackTools 'log' 6");
  10536. }
  10537. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10538. system(cmdBuf);
  10539. checkUploadLog();
  10540. //****************location*******************/
  10541. if(strcmp(locationstr,"")==0)
  10542. {
  10543. DEBUG_INFO("location is <Empty>!\n");
  10544. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10545. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10546. goto end;
  10547. }
  10548. memset(protocol, 0, ARRAY_SIZE(protocol));
  10549. memset(user, 0, ARRAY_SIZE(user) );
  10550. memset(password, 0, ARRAY_SIZE(password));
  10551. memset(host, 0, ARRAY_SIZE(host));
  10552. memset(path, 0, ARRAY_SIZE(path));
  10553. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10554. memset(host1, 0, ARRAY_SIZE(host1));
  10555. memset(path1, 0, ARRAY_SIZE(path1));
  10556. /*location: ftp://user:password@host:port/path*/
  10557. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10558. if((access(fnamePlusPath,F_OK))!=-1)
  10559. {
  10560. DEBUG_INFO("fnamePlusPath exist.\n");
  10561. }
  10562. else
  10563. {
  10564. DEBUG_INFO("fnamePlusPath not exist!\n");
  10565. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10566. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10567. goto end;
  10568. }
  10569. if(strchr(locationstr,'@')==NULL)
  10570. {
  10571. sscanf(locationstr,
  10572. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10573. protocol, host, &port, path);
  10574. strcpy(user,"anonymous");
  10575. strcpy(password,"");
  10576. }
  10577. else
  10578. {
  10579. //DEBUG_INFO("pch=%s\n", pch);
  10580. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10581. protocol, user, password, host, &port, path);
  10582. }
  10583. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10584. {
  10585. DEBUG_INFO("protocol is not ftp/http ! \n");
  10586. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10587. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10588. goto end;
  10589. }
  10590. if(strncmp(locationstr,"http", 4) == 0)
  10591. {
  10592. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10593. sprintf(ftppath,"/%s", path);
  10594. do
  10595. {
  10596. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10597. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10598. sleep(3);
  10599. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10600. if(!isSuccess)
  10601. {
  10602. DEBUG_INFO("Diagnostics fail.\n");
  10603. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10604. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10605. sleep(retryIntervalInt);
  10606. }
  10607. else
  10608. {
  10609. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10610. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10611. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10612. }
  10613. retriesInt--;
  10614. }while((isSuccess == 0)&&(retriesInt >= 0));
  10615. }
  10616. else
  10617. {
  10618. sscanf(host,"%[^/]%s",host1, path1);
  10619. if(strlen(path) > 0)
  10620. sprintf(ftppath,"/%s", path);
  10621. else
  10622. sprintf(ftppath,"/%s", path1);
  10623. int ftppathlen=strlen(ftppath);
  10624. int i=1;
  10625. char filenametemp[50];
  10626. while(i < ftppathlen)
  10627. {
  10628. int len=ftppathlen-i;
  10629. if(ftppath[len]== 47) // '/' ascll code: 47
  10630. {
  10631. DEBUG_INFO("find '/' all right\n");
  10632. break;
  10633. }
  10634. i=i+1;
  10635. }
  10636. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10637. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10638. filenametemp[i+1] = 0;
  10639. if(port == 0)
  10640. port = 21;
  10641. do
  10642. {
  10643. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10644. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10645. sleep(3);
  10646. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10647. if(!isSuccess)
  10648. {
  10649. DEBUG_INFO("Diagnostics fail.\n");
  10650. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10651. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10652. sleep(retryIntervalInt);
  10653. }
  10654. else
  10655. {
  10656. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10657. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10658. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10659. }
  10660. retriesInt--;
  10661. }while((!isSuccess)&&(retriesInt >= 0));
  10662. }
  10663. end:
  10664. system("rm -f /mnt/*");
  10665. sleep(5);
  10666. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10667. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10668. interLock.isGetDiagnosticGoing = 0;
  10669. pthread_exit(NULL);
  10670. }
  10671. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10672. {
  10673. mtrace();
  10674. int result = FAIL;
  10675. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10676. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10677. {
  10678. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10679. locallistVersion = -1;
  10680. }
  10681. else
  10682. {
  10683. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10684. locallistVersion = 0;
  10685. OCPP_getListVerion();
  10686. }
  10687. //from db.OCPP_getListVerion
  10688. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10689. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10690. sendGetLocalListVersionConfirmation(uuid,"");
  10691. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10692. return result;
  10693. }
  10694. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10695. {
  10696. mtrace();
  10697. int result = FAIL;
  10698. int connectorIdInt=-1;
  10699. int tempIndex = 0;
  10700. int connectorIdIsNULL, chargingProfileIsNULL;
  10701. char comfirmstr[20]={0};
  10702. char cmdBuf[512];
  10703. json_object *RemoteStartTransaction;
  10704. FILE *fp;
  10705. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10706. if(server_pending == TRUE)
  10707. {
  10708. return 0;
  10709. }
  10710. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10711. RemoteStartTransaction = json_tokener_parse(payload);
  10712. if(!is_error(RemoteStartTransaction))
  10713. {
  10714. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10715. {
  10716. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10717. }
  10718. else
  10719. {
  10720. connectorIdIsNULL = TRUE;
  10721. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10722. {
  10723. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10724. {
  10725. connectorIdIsNULL = FALSE;
  10726. connectorIdInt = (gun_index+1);
  10727. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10728. break;
  10729. }
  10730. }
  10731. }
  10732. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10733. {
  10734. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10735. // Required data
  10736. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10737. // Optional data
  10738. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10739. {
  10740. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10741. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10742. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10743. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10744. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10745. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10746. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10747. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10748. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10749. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10750. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10751. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10752. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10753. {
  10754. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10755. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10756. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10757. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10758. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10759. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10760. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10761. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10762. {
  10763. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  10764. {
  10765. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10766. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10767. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  10768. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10769. }
  10770. }
  10771. }
  10772. }
  10773. else
  10774. {
  10775. chargingProfileIsNULL = TRUE;
  10776. }
  10777. }
  10778. }
  10779. else
  10780. {
  10781. connectorIdIsNULL = TRUE;
  10782. }
  10783. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10784. {
  10785. DEBUG_WARN("Connector id is NULL\n.");
  10786. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10787. goto end;
  10788. }
  10789. /*
  10790. enum _SYSTEM_STATUS
  10791. {
  10792. S_BOOTING = 0,
  10793. S_IDLE, = 1
  10794. S_AUTHORIZING, = 2
  10795. S_REASSIGN_CHECK, = 3
  10796. S_REASSIGN, = 4
  10797. S_PRECHARGE, = 5
  10798. S_PREPARING_FOR_EV, = 6
  10799. S_PREPARING_FOR_EVSE, = 7
  10800. S_CHARGING, = 8
  10801. S_TERMINATING, = 9
  10802. S_COMPLETE, = 10
  10803. S_ALARM, = 11
  10804. S_FAULT = 12
  10805. }
  10806. */
  10807. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10808. {
  10809. //check Transaction active
  10810. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10811. {
  10812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10813. {
  10814. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10815. }
  10816. else
  10817. {
  10818. tempIndex = connectorIdInt -1;
  10819. }
  10820. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10821. {
  10822. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10823. {
  10824. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10825. {
  10826. //Reserved
  10827. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10828. }
  10829. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10830. {
  10831. //Reserved
  10832. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10833. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10834. goto end;
  10835. }
  10836. else
  10837. {
  10838. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10839. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10840. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10841. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10842. {
  10843. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10844. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10845. goto end;
  10846. }
  10847. }//END FOR ELSE
  10848. }
  10849. }// END FOR CHAdeMO_QUANTITY
  10850. }
  10851. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10852. {
  10853. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10854. {
  10855. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10856. }
  10857. else
  10858. {
  10859. tempIndex = connectorIdInt -1;
  10860. }
  10861. for (int index = 0; index < CCS_QUANTITY; index++)
  10862. {
  10863. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10864. {
  10865. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10866. {
  10867. //Reserved
  10868. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10869. }
  10870. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10871. {
  10872. //Reserved
  10873. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10874. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10875. goto end;
  10876. }
  10877. else
  10878. {
  10879. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10880. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10881. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10882. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10883. {
  10884. DEBUG_WARN("CCS connector not allow start\n.");
  10885. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10886. goto end;
  10887. }
  10888. }// END FOR ELSE
  10889. }
  10890. }// END FOR CCS_QUANTITY
  10891. }
  10892. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10893. {
  10894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10895. {
  10896. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10897. }
  10898. else
  10899. {
  10900. tempIndex = connectorIdInt -1;
  10901. }
  10902. for (int index = 0; index < GB_QUANTITY; index++)
  10903. {
  10904. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10905. {
  10906. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10907. {
  10908. //Reserved
  10909. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10910. }
  10911. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10912. {
  10913. //Reserved
  10914. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10915. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10916. goto end;
  10917. }
  10918. else
  10919. {
  10920. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10921. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10922. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10923. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10924. {
  10925. DEBUG_WARN("GB connector not allow start\n.");
  10926. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10927. goto end;
  10928. }
  10929. }// END FOR ELSE
  10930. }
  10931. } // END FOR GB_QUANTITY
  10932. }
  10933. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10934. {
  10935. tempIndex = connectorIdInt -1;
  10936. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10937. {
  10938. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10939. {
  10940. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10941. {
  10942. //Reserved
  10943. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10944. }
  10945. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10946. {
  10947. //Reserved
  10948. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10949. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10950. goto end;
  10951. }
  10952. else
  10953. {
  10954. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10955. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10956. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10957. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10958. {
  10959. DEBUG_WARN("GB connector not allow start\n.");
  10960. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10961. goto end;
  10962. }
  10963. }// END FOR ELSE
  10964. }
  10965. } // END FOR GB_QUANTITY
  10966. }
  10967. else
  10968. {
  10969. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10970. {
  10971. tempIndex = 2;
  10972. }
  10973. else
  10974. {
  10975. tempIndex = connectorIdInt -1;
  10976. }
  10977. for (int index = 0; index < AC_QUANTITY; index++)
  10978. {
  10979. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10980. {
  10981. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10982. {
  10983. //Reserved
  10984. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10985. }
  10986. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10987. {
  10988. //Reserved
  10989. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10990. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10991. goto end;
  10992. }
  10993. else
  10994. {
  10995. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10996. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10997. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10998. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10999. {
  11000. DEBUG_WARN("AC connector not allow start\n.");
  11001. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11002. goto end;
  11003. }
  11004. }//END FOR ELSE
  11005. }
  11006. }// END FOR AC_QUANTITY
  11007. }
  11008. if(chargingProfileIsNULL == FALSE)
  11009. {
  11010. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11011. {
  11012. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11013. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11014. //memset idTag
  11015. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11016. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11017. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11018. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11019. // Save profile to file
  11020. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11021. system(cmdBuf);
  11022. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11023. fp = fopen(cmdBuf, "w");
  11024. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11025. fclose(fp);
  11026. }
  11027. else
  11028. {
  11029. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  11030. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11031. }
  11032. }
  11033. else
  11034. {
  11035. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11036. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11037. //memset idTag
  11038. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11039. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11040. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11041. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11042. }
  11043. }
  11044. else
  11045. {
  11046. DEBUG_WARN("Connector id over\n.");
  11047. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11048. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11049. }
  11050. end:
  11051. json_object_put(RemoteStartTransaction);
  11052. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  11053. {
  11054. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  11055. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  11056. }
  11057. //OCPP send RemoteStartConfirmation by first.
  11058. sendRemoteStartConfirmation(uuid, comfirmstr);
  11059. return result;
  11060. }
  11061. int handleRemoteStartRequest(char *uuid, char *payload)
  11062. {
  11063. mtrace();
  11064. int result = PASS;
  11065. int connectorIdInt=-1;
  11066. int tempIndex = 0;
  11067. char comfirmstr[20]={0};
  11068. char cmdBuf[512];
  11069. json_object *RemoteStartTransaction;
  11070. FILE *fp;
  11071. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11072. if(server_pending == TRUE)
  11073. {
  11074. result = FAIL;
  11075. }
  11076. RemoteStartTransaction = json_tokener_parse(payload);
  11077. if(!is_error(RemoteStartTransaction))
  11078. {
  11079. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11080. {
  11081. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11082. }
  11083. else
  11084. {
  11085. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11086. {
  11087. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11088. {
  11089. connectorIdInt = (gun_index+1);
  11090. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11091. break;
  11092. }
  11093. }
  11094. }
  11095. if(connectorIdInt == 0)
  11096. {
  11097. DEBUG_WARN("Connector id shall not equal 0.\n");
  11098. result = FAIL;
  11099. }
  11100. else if(connectorIdInt == -1)
  11101. {
  11102. DEBUG_INFO("Connector id does not specific.\n");
  11103. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11104. {
  11105. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11106. // Required data
  11107. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11108. // Optional data
  11109. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11110. {
  11111. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11112. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11113. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11114. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11115. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11116. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11117. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11118. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11119. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11120. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11121. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11122. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11123. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11124. {
  11125. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  11126. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11127. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  11128. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11129. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  11130. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11131. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  11132. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11133. {
  11134. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  11135. {
  11136. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  11137. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  11138. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  11139. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  11140. }
  11141. }
  11142. }
  11143. }
  11144. else
  11145. {
  11146. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11147. }
  11148. }
  11149. }
  11150. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11151. {
  11152. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11153. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11154. // Required data
  11155. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11156. // Optional data
  11157. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11158. {
  11159. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11160. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11161. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11162. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11163. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11164. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11165. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11166. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11167. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11168. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11169. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11170. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11171. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11172. {
  11173. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  11174. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11175. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  11176. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11177. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  11178. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11179. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  11180. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11181. {
  11182. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  11183. {
  11184. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  11185. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  11186. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  11187. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  11188. }
  11189. }
  11190. }
  11191. }
  11192. else
  11193. {
  11194. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11195. }
  11196. }
  11197. else
  11198. {
  11199. DEBUG_WARN("Connector id is over maximun value.\n");
  11200. result = FAIL;
  11201. }
  11202. }
  11203. if(result == PASS)
  11204. {
  11205. if(connectorIdInt > 0)
  11206. {
  11207. //check Transaction active
  11208. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11209. {
  11210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11211. {
  11212. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11213. }
  11214. else
  11215. {
  11216. tempIndex = connectorIdInt -1;
  11217. }
  11218. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11219. {
  11220. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11221. {
  11222. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11223. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11224. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11225. {
  11226. //Reserved
  11227. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11228. }
  11229. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11230. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11231. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11232. {
  11233. //Reserved
  11234. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11235. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11236. goto end;
  11237. }
  11238. else
  11239. {
  11240. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11241. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11242. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11243. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11244. {
  11245. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11246. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11247. goto end;
  11248. }
  11249. }//END FOR ELSE
  11250. }
  11251. }// END FOR CHAdeMO_QUANTITY
  11252. }
  11253. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11254. {
  11255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11256. {
  11257. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11258. }
  11259. else
  11260. {
  11261. tempIndex = connectorIdInt -1;
  11262. }
  11263. for (int index = 0; index < CCS_QUANTITY; index++)
  11264. {
  11265. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11266. {
  11267. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11268. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11269. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11270. {
  11271. //Reserved
  11272. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11273. }
  11274. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11275. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11276. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11277. {
  11278. //Reserved
  11279. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11280. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11281. goto end;
  11282. }
  11283. else
  11284. {
  11285. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11286. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11287. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11288. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11289. {
  11290. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11291. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11292. goto end;
  11293. }
  11294. }// END FOR ELSE
  11295. }
  11296. }// END FOR CCS_QUANTITY
  11297. }
  11298. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11299. {
  11300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11301. {
  11302. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11303. }
  11304. else
  11305. {
  11306. tempIndex = connectorIdInt -1;
  11307. }
  11308. for (int index = 0; index < GB_QUANTITY; index++)
  11309. {
  11310. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11311. {
  11312. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11313. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11314. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11315. {
  11316. //Reserved
  11317. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11318. }
  11319. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11320. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11321. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11322. {
  11323. //Reserved
  11324. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11325. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11326. goto end;
  11327. }
  11328. else
  11329. {
  11330. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11331. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11332. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11333. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11334. {
  11335. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11336. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11337. goto end;
  11338. }
  11339. }// END FOR ELSE
  11340. }
  11341. } // END FOR GB_QUANTITY
  11342. }
  11343. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11344. {
  11345. tempIndex = connectorIdInt -1;
  11346. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11347. {
  11348. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11349. {
  11350. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11351. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11352. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11353. {
  11354. //Reserved
  11355. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11356. }
  11357. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11358. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11359. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11360. {
  11361. //Reserved
  11362. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11363. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11364. goto end;
  11365. }
  11366. else
  11367. {
  11368. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11369. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11370. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11371. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11372. {
  11373. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11374. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11375. goto end;
  11376. }
  11377. }// END FOR ELSE
  11378. }
  11379. } // END FOR GB_QUANTITY
  11380. }
  11381. else
  11382. {
  11383. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11384. {
  11385. tempIndex = 2;
  11386. }
  11387. else
  11388. {
  11389. tempIndex = connectorIdInt -1;
  11390. }
  11391. for (int index = 0; index < AC_QUANTITY; index++)
  11392. {
  11393. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11394. {
  11395. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11396. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11397. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11398. {
  11399. //Reserved
  11400. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11401. }
  11402. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11403. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11404. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11405. {
  11406. //Reserved
  11407. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11408. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11409. goto end;
  11410. }
  11411. else
  11412. {
  11413. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11414. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11415. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11416. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11417. {
  11418. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11419. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11420. goto end;
  11421. }
  11422. }//END FOR ELSE
  11423. }
  11424. }// END FOR AC_QUANTITY
  11425. }
  11426. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11427. {
  11428. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11429. {
  11430. // Save profile to file
  11431. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11432. system(cmdBuf);
  11433. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11434. fp = fopen(cmdBuf, "w");
  11435. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11436. fclose(fp);
  11437. }
  11438. else
  11439. {
  11440. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11441. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11442. goto end;
  11443. }
  11444. }
  11445. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11446. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11447. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11448. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11449. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11450. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11451. }
  11452. else
  11453. {
  11454. uint8_t isHasIdleConnector = FALSE;
  11455. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11456. {
  11457. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11458. {
  11459. isHasIdleConnector = TRUE;
  11460. break;
  11461. }
  11462. }
  11463. if(isHasIdleConnector == TRUE)
  11464. {
  11465. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11466. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11467. {
  11468. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11469. {
  11470. // Save profile to file
  11471. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11472. system(cmdBuf);
  11473. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11474. fp = fopen(cmdBuf, "w");
  11475. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11476. fclose(fp);
  11477. refreshStartTimer(&clientTime.RemoteStartWait);
  11478. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11479. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11480. }
  11481. else
  11482. {
  11483. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11484. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11485. }
  11486. }
  11487. else
  11488. {
  11489. refreshStartTimer(&clientTime.RemoteStartWait);
  11490. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11491. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11492. }
  11493. }
  11494. else
  11495. {
  11496. DEBUG_INFO("There is not any connector is idle.\n");
  11497. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11498. }
  11499. }
  11500. }
  11501. else
  11502. {
  11503. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11504. }
  11505. end:
  11506. json_object_put(RemoteStartTransaction);
  11507. sendRemoteStartConfirmation(uuid, comfirmstr);
  11508. return result;
  11509. }
  11510. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11511. {
  11512. mtrace();
  11513. int result = FAIL;
  11514. int match = FALSE;
  11515. int GunNO = 0;
  11516. int tempIndex = 0;
  11517. int transactionIdInt=0;
  11518. int transactionIdIsNULL= TRUE;
  11519. char comfirmstr[20];
  11520. json_object *RemoteStopTransaction;
  11521. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11522. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11523. if(server_pending == TRUE)
  11524. {
  11525. return 0;
  11526. }
  11527. RemoteStopTransaction = json_tokener_parse(payload);
  11528. if(!is_error(RemoteStopTransaction))
  11529. {
  11530. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11531. {
  11532. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11533. transactionIdIsNULL = FALSE;
  11534. }
  11535. }
  11536. json_object_put(RemoteStopTransaction);
  11537. if(transactionIdIsNULL == FALSE)
  11538. {
  11539. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11540. {
  11541. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11542. {
  11543. //check Transaction active
  11544. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11545. {
  11546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11547. {
  11548. tempIndex = ((gun_index==2) ? 1: 0);
  11549. }
  11550. else
  11551. {
  11552. tempIndex = gun_index;
  11553. }
  11554. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11555. {
  11556. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11557. {
  11558. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11559. {
  11560. match = TRUE;
  11561. GunNO = gun_index;
  11562. }
  11563. }
  11564. }// END FOR CHAdeMO_QUANTITY
  11565. }
  11566. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11567. {
  11568. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11569. {
  11570. tempIndex = ((gun_index==2) ? 1: 0);
  11571. }
  11572. else
  11573. {
  11574. tempIndex = gun_index;
  11575. }
  11576. for (int index = 0; index < CCS_QUANTITY; index++)
  11577. {
  11578. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11579. {
  11580. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11581. {
  11582. match = TRUE;
  11583. GunNO = gun_index;
  11584. }
  11585. }
  11586. }// END FOR CCS_QUANTITY
  11587. }
  11588. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11589. {
  11590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11591. {
  11592. tempIndex = ((gun_index==2) ? 1: 0);
  11593. }
  11594. else
  11595. {
  11596. tempIndex = gun_index;
  11597. }
  11598. for (int index = 0; index < GB_QUANTITY; index++)
  11599. {
  11600. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11601. {
  11602. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11603. {
  11604. match = TRUE;
  11605. GunNO = gun_index;
  11606. }
  11607. }
  11608. }// END FOR GB_QUANTITY
  11609. }
  11610. else if(gunType[gun_index] == GUN_TYPE_DO)
  11611. {
  11612. tempIndex = gun_index;
  11613. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11614. {
  11615. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11616. {
  11617. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11618. {
  11619. match = TRUE;
  11620. GunNO = gun_index;
  11621. }
  11622. }
  11623. }// END FOR GB_QUANTITY
  11624. }
  11625. else
  11626. {
  11627. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11628. {
  11629. tempIndex = 2;
  11630. }
  11631. else
  11632. {
  11633. tempIndex = gun_index;
  11634. }
  11635. for (int index = 0; index < AC_QUANTITY; index++)
  11636. {
  11637. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11638. {
  11639. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11640. {
  11641. match = TRUE;
  11642. GunNO = gun_index;
  11643. }
  11644. }
  11645. }// END FOR CHAdeMO_QUANTITY
  11646. } // END FOR AC ELSE
  11647. }// CHECK IF ResponseTransactionId == transactionIdInt
  11648. }//END FOR
  11649. if( match == TRUE)
  11650. {
  11651. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11652. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11653. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11654. }
  11655. else
  11656. {
  11657. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11658. }
  11659. }
  11660. else
  11661. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11662. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11663. return result;
  11664. }
  11665. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11666. {
  11667. mtrace();
  11668. int result = FAIL;
  11669. int connectorIdInt=0, reservationIdInt=0;
  11670. int tempIndex = 0;
  11671. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11672. char comfirmstr[20]={0};
  11673. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11674. int c = 0;
  11675. char *loc;
  11676. //char *ptr;
  11677. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11678. strcpy(sstrtemp, stringtrimspace(payload));
  11679. //***(1)connectorId ****/
  11680. c=0;
  11681. loc = strstr(sstrtemp, "connectorId");
  11682. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11683. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11684. {
  11685. sstr[c] = loc[strlen("connectorId")+2+c];
  11686. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11687. c++;
  11688. }
  11689. sstr[c] = '\0';
  11690. connectorIdInt = atoi(sstr);
  11691. //***(2)expiryDate ****/
  11692. loc = strstr(sstrtemp, "expiryDate");
  11693. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11694. c = 0;
  11695. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11696. {
  11697. sstr[c] = loc[3+strlen("expiryDate")+c];
  11698. c++;
  11699. }
  11700. sstr[c] = '\0';
  11701. strcpy(expiryDatestr, sstr);
  11702. //***(3)idTag ****/
  11703. loc = strstr(sstrtemp, "idTag");
  11704. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11705. c = 0;
  11706. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11707. {
  11708. sstr[c] = loc[3+strlen("idTag")+c];
  11709. c++;
  11710. }
  11711. sstr[c] = '\0';
  11712. strcpy(idTagstr, sstr);
  11713. //***(4)parentIdTag ****/
  11714. loc = strstr(sstrtemp, "parentIdTag");
  11715. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11716. c = 0;
  11717. if(loc == NULL)
  11718. {
  11719. strcpy(parentIdTagstr, "");
  11720. }
  11721. else
  11722. {
  11723. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11724. {
  11725. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11726. c++;
  11727. }
  11728. sstr[c] = '\0';
  11729. strcpy(parentIdTagstr, sstr);
  11730. }
  11731. //***(5)reservationId ****/
  11732. c=0;
  11733. loc = strstr(sstrtemp, "reservationId");
  11734. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11735. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11736. {
  11737. sstr[c] = loc[strlen("reservationId")+2+c];
  11738. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11739. c++;
  11740. }
  11741. sstr[c] = '\0';
  11742. reservationIdInt = atoi(sstr);
  11743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11744. /*
  11745. enum SYSTEM_STATUS
  11746. {
  11747. SYS_MODE_BOOTING = 0,
  11748. SYS_MODE_IDLE = 1,
  11749. SYS_MODE_AUTHORIZING = 2,
  11750. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11751. SYS_MODE_REASSIGN = 4,
  11752. SYS_MODE_PREPARING = 5,
  11753. SYS_MODE_PREPARE_FOR_EV = 6,
  11754. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11755. SYS_MODE_CHARGING = 8,
  11756. SYS_MODE_TERMINATING = 9,
  11757. SYS_MODE_COMPLETE = 10,
  11758. SYS_MODE_ALARM = 11,
  11759. SYS_MODE_FAULT = 12,
  11760. SYS_MODE_RESERVATION = 13,
  11761. SYS_MODE_BOOKING = 14,
  11762. SYS_MODE_MAINTAIN = 15,
  11763. SYS_MODE_DEBUG = 16,
  11764. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11765. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11766. SYS_MODE_UPDATE = 19
  11767. };
  11768. */
  11769. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11770. {
  11771. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11772. goto end;
  11773. }
  11774. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11775. {
  11776. //check Transaction active
  11777. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11778. {
  11779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11780. {
  11781. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11782. }
  11783. else
  11784. {
  11785. tempIndex = connectorIdInt -1;
  11786. }
  11787. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11788. {
  11789. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11790. {
  11791. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11792. {
  11793. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11794. {
  11795. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11796. {
  11797. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11798. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11799. }
  11800. 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'))
  11801. {
  11802. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11803. }
  11804. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11805. {
  11806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11807. }
  11808. else
  11809. {
  11810. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11811. }
  11812. }
  11813. 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
  11814. {
  11815. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11816. }
  11817. }
  11818. else
  11819. {
  11820. //replace reservation
  11821. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11823. }
  11824. }
  11825. } // END FOR CHAdeMO_QUANTITY
  11826. }
  11827. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11828. {
  11829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11830. {
  11831. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11832. }
  11833. else
  11834. {
  11835. tempIndex = connectorIdInt -1;
  11836. }
  11837. for (int index = 0; index < CCS_QUANTITY; index++)
  11838. {
  11839. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11840. {
  11841. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11842. {
  11843. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11844. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11845. {
  11846. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11847. {
  11848. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11849. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11850. }
  11851. 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'))
  11852. {
  11853. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11854. }
  11855. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11856. {
  11857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11858. }
  11859. else
  11860. {
  11861. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11862. }
  11863. }
  11864. 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
  11865. {
  11866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11867. }
  11868. }
  11869. else
  11870. {
  11871. //replace reservation
  11872. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11874. }
  11875. }
  11876. } // END FOR CCS_QUANTITY
  11877. }
  11878. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11879. {
  11880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11881. {
  11882. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11883. }
  11884. else
  11885. {
  11886. tempIndex = connectorIdInt -1;
  11887. }
  11888. for (int index = 0; index < GB_QUANTITY; index++)
  11889. {
  11890. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11891. {
  11892. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11893. {
  11894. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11895. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11896. {
  11897. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11898. {
  11899. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11901. }
  11902. 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'))
  11903. {
  11904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11905. }
  11906. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11907. {
  11908. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11909. }
  11910. else
  11911. {
  11912. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11913. }
  11914. }
  11915. 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
  11916. {
  11917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11918. }
  11919. }
  11920. else
  11921. {
  11922. //replace reservation
  11923. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11925. }
  11926. }
  11927. }// END FOR GB_QUANTITY
  11928. }
  11929. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11930. {
  11931. tempIndex = connectorIdInt -1;
  11932. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11933. {
  11934. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11935. {
  11936. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11937. {
  11938. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11939. 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
  11940. {
  11941. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11942. {
  11943. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11945. }
  11946. 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'))
  11947. {
  11948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11949. }
  11950. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11951. {
  11952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11953. }
  11954. else
  11955. {
  11956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11957. }
  11958. }
  11959. 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
  11960. {
  11961. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11962. }
  11963. }
  11964. else
  11965. {
  11966. //replace reservation
  11967. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11969. }
  11970. }
  11971. }// END FOR GB_QUANTITY
  11972. }
  11973. else
  11974. {
  11975. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11976. {
  11977. tempIndex = 2;
  11978. }
  11979. else
  11980. {
  11981. tempIndex = (connectorIdInt -1);
  11982. }
  11983. for (int index = 0; index < AC_QUANTITY; index++)
  11984. {
  11985. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11986. {
  11987. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11988. {
  11989. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11990. {
  11991. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11992. {
  11993. 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))
  11994. {
  11995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11996. }
  11997. else
  11998. {
  11999. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12001. }
  12002. }
  12003. 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'))
  12004. {
  12005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12006. }
  12007. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12008. {
  12009. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12010. }
  12011. else
  12012. {
  12013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12014. }
  12015. }
  12016. 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
  12017. {
  12018. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12019. }
  12020. }
  12021. else
  12022. {
  12023. //replace reservation
  12024. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12025. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12026. }
  12027. }
  12028. } // END FOR AC_QUANTITY
  12029. }
  12030. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12031. }
  12032. else if(connectorIdInt == 0)
  12033. {
  12034. //check Transaction active
  12035. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12036. {
  12037. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12038. {
  12039. 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'))
  12040. {
  12041. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12042. goto end;
  12043. }
  12044. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12045. {
  12046. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12047. goto end;
  12048. }
  12049. 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
  12050. {
  12051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12052. goto end;
  12053. }
  12054. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12055. {
  12056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12057. goto end;
  12058. }
  12059. }
  12060. }// END FOR CHAdeMO_QUANTITY
  12061. for (int index = 0; index < CCS_QUANTITY; index++)
  12062. {
  12063. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12064. {
  12065. 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'))
  12066. {
  12067. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12068. goto end;
  12069. }
  12070. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12071. {
  12072. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12073. goto end;
  12074. }
  12075. 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
  12076. {
  12077. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12078. goto end;
  12079. }
  12080. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12081. {
  12082. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12083. goto end;
  12084. }
  12085. }
  12086. } // END FOR CCS_QUANTITY
  12087. for (int index = 0; index < GB_QUANTITY; index++)
  12088. {
  12089. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12090. {
  12091. 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'))
  12092. {
  12093. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12094. goto end;
  12095. }
  12096. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12097. {
  12098. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12099. goto end;
  12100. }
  12101. 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
  12102. {
  12103. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12104. goto end;
  12105. }
  12106. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12107. {
  12108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12109. goto end;
  12110. }
  12111. }
  12112. } // END FOR GB_QUANTITY
  12113. for (int index = 0; index < AC_QUANTITY; index++)
  12114. {
  12115. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12116. {
  12117. 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'))
  12118. {
  12119. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12120. goto end;
  12121. }
  12122. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12123. {
  12124. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12125. goto end;
  12126. }
  12127. 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
  12128. {
  12129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12130. goto end;
  12131. }
  12132. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12133. {
  12134. 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))
  12135. {
  12136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12137. goto end;
  12138. }
  12139. }
  12140. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12141. {
  12142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12143. goto end;
  12144. }
  12145. }
  12146. }// END FOR AC_QUANTITY
  12147. //The connectorId is 0
  12148. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12149. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12150. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12151. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12152. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12153. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12154. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12155. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12156. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12157. result = TRUE;
  12158. return result;
  12159. }
  12160. else
  12161. {
  12162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12163. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12164. }
  12165. if(strcmp(comfirmstr,"Accepted") == 0)
  12166. {
  12167. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12168. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12169. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12170. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12171. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12172. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12173. result = TRUE;
  12174. return result;
  12175. }
  12176. end:
  12177. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12178. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12179. return result;
  12180. }
  12181. int handleResetRequest(char *uuid, char *payload)
  12182. {
  12183. mtrace();
  12184. int result = FAIL;
  12185. char sstr[10]={0},sstrtemp[30]={ 0 };
  12186. char typestr[10]={0};
  12187. char comfirmstr[20]={0};
  12188. int c = 0;
  12189. char *loc;
  12190. DEBUG_INFO("handleResetRequest...\n");
  12191. strcpy(sstrtemp, stringtrimspace(payload));
  12192. loc = strstr(sstrtemp, "type");
  12193. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12194. c = 0;
  12195. while (loc[3+strlen("type")+c] != '\"')
  12196. {
  12197. sstr[c] = loc[3+strlen("type")+c];
  12198. c++;
  12199. }
  12200. sstr[c] = '\0';
  12201. strcpy(typestr,sstr);
  12202. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12203. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12204. {
  12205. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12206. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12207. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12208. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12209. }
  12210. else
  12211. {
  12212. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12213. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12214. result = PASS;
  12215. }
  12216. sendResetConfirmation(uuid, comfirmstr);
  12217. return result;
  12218. }
  12219. int handleSendLocalListRequest(char *uuid, char *payload)
  12220. {
  12221. mtrace();
  12222. int result = FAIL;
  12223. char comfirmstr[20];
  12224. int checkState_Faulted = FALSE;
  12225. json_object *SendLocalList;
  12226. DEBUG_INFO("handleSendLocalListRequest...\n");
  12227. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12228. {
  12229. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12230. goto end;
  12231. }
  12232. //check Charge Point state
  12233. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12234. {
  12235. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12236. {
  12237. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12238. }
  12239. }
  12240. for (int index = 0; index < CCS_QUANTITY; index++)
  12241. {
  12242. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12243. {
  12244. checkState_Faulted = TRUE; //OCPP Status
  12245. }
  12246. }
  12247. for (int index = 0; index < GB_QUANTITY; index++)
  12248. {
  12249. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12250. {
  12251. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12252. }
  12253. }
  12254. //check Charge Point state
  12255. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12256. {
  12257. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12258. {
  12259. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12260. }
  12261. }
  12262. //check Charge Point state
  12263. for (int index = 0; index < AC_QUANTITY; index++)
  12264. {
  12265. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12266. {
  12267. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12268. }
  12269. }
  12270. if(checkState_Faulted == TRUE)
  12271. {
  12272. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12273. goto end;
  12274. }
  12275. // Parsing payload
  12276. SendLocalList = json_tokener_parse(payload);
  12277. if(!is_error(SendLocalList))
  12278. {
  12279. // Required data
  12280. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12281. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12282. // Optional data
  12283. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12284. {
  12285. //Check UpdateType
  12286. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12287. {
  12288. //Local list full update
  12289. DEBUG_INFO("Local list full update.\n");
  12290. locallistVersion = 0;
  12291. OCPP_getListVerion();
  12292. /*if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12293. {
  12294. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12295. goto end;
  12296. }*/
  12297. OCPP_cleanLocalList();
  12298. }
  12299. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12300. {
  12301. //Local list different update
  12302. DEBUG_INFO("Local list different update.\n");
  12303. locallistVersion = 0;
  12304. OCPP_getListVerion();
  12305. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12306. {
  12307. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12308. goto end;
  12309. }
  12310. }
  12311. else
  12312. {
  12313. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12314. goto end;
  12315. }
  12316. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12317. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12318. {
  12319. 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")));
  12320. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12321. {
  12322. 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")));
  12323. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12324. 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")));
  12325. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12326. 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")));
  12327. }
  12328. // Add to db
  12329. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12330. {
  12331. //Local list full update
  12332. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12333. idx,
  12334. ShmOCPP16Data->SendLocalList.ListVersion,
  12335. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12336. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12337. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12338. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12339. // update list
  12340. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12341. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12342. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12343. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12344. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12345. }
  12346. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12347. {
  12348. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12349. idx,
  12350. ShmOCPP16Data->SendLocalList.ListVersion,
  12351. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12352. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12353. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12354. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12355. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12356. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12357. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12358. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12359. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12360. }
  12361. }
  12362. }
  12363. else
  12364. {
  12365. //Check UpdateType
  12366. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12367. {
  12368. //Local list full update
  12369. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12370. OCPP_cleanLocalList();
  12371. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12372. goto end;
  12373. }
  12374. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12375. {
  12376. //Local list different update
  12377. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12378. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12379. goto end;
  12380. }
  12381. }
  12382. result = PASS;
  12383. }
  12384. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12385. end:
  12386. json_object_put(SendLocalList);
  12387. sendSendLocalListConfirmation(uuid, comfirmstr);
  12388. return result;
  12389. }
  12390. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12391. {
  12392. mtrace();
  12393. int result = FAIL;
  12394. struct StructSetChargingProfile SetProfileReq = {0};
  12395. int tempchargingProfileIdInt;
  12396. int tempstackLevelInt;
  12397. int chargingSchedulePeriodCount = 0;
  12398. char comfirmstr[20]={0};
  12399. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12400. char rmFileCmd[128]={0};
  12401. int profileQuantity = 0;
  12402. int replaceableProfileCnt = 0;
  12403. json_object *SetChargingProfile;
  12404. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12405. SetChargingProfile = json_tokener_parse(payload);
  12406. if(!is_error(SetChargingProfile))
  12407. {
  12408. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12409. {
  12410. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12411. }
  12412. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12413. {
  12414. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12415. {
  12416. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12417. }
  12418. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12419. {
  12420. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12421. }
  12422. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12423. {
  12424. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12425. }
  12426. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12427. {
  12428. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12429. }
  12430. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12431. {
  12432. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12433. }
  12434. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12435. {
  12436. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12437. }
  12438. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12439. {
  12440. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12441. }
  12442. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12443. {
  12444. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12445. }
  12446. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12447. {
  12448. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12449. {
  12450. 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")));
  12451. }
  12452. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12453. {
  12454. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12455. }
  12456. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12457. {
  12458. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12459. }
  12460. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12461. {
  12462. 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")));
  12463. }
  12464. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12465. {
  12466. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12467. if(chargingSchedulePeriodCount <= 10)
  12468. {
  12469. 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++)
  12470. {
  12471. 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)
  12472. {
  12473. 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"));
  12474. }
  12475. 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)
  12476. {
  12477. 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"));
  12478. }
  12479. 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)
  12480. {
  12481. 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"));
  12482. }
  12483. }
  12484. }
  12485. }
  12486. }
  12487. }
  12488. }
  12489. // Profile periods quantity check
  12490. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12491. {
  12492. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12493. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12494. goto end;
  12495. }
  12496. // Check invalid limit
  12497. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12498. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12499. {
  12500. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12501. {
  12502. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12503. {
  12504. 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)))) ||
  12505. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12506. {
  12507. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12508. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12509. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12510. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12511. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12512. goto end;
  12513. }
  12514. }
  12515. }
  12516. else
  12517. {
  12518. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12519. {
  12520. 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) ||
  12521. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) < (modelnameInfo.ratedPower*0.01)))
  12522. {
  12523. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12524. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12525. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12526. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12527. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12528. goto end;
  12529. }
  12530. }
  12531. }
  12532. }
  12533. // Profile purpose info check
  12534. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12535. {
  12536. FILE *fp;
  12537. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12538. if(SetProfileReq.ConnectorId != 0)
  12539. {
  12540. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12541. DEBUG_WARN("Profile connector id is not 0.\n");
  12542. goto end;
  12543. }
  12544. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12545. if (!fp)
  12546. {
  12547. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12548. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12549. }
  12550. else
  12551. {
  12552. char *line = NULL;
  12553. size_t len = 0;
  12554. while(getline(&line, &len, fp) != -1)
  12555. {
  12556. json_object *obj = NULL;
  12557. obj = json_tokener_parse(line);
  12558. if(is_error(obj))
  12559. {
  12560. DEBUG_ERROR("Parse txProfile from file error.\n");
  12561. }
  12562. else
  12563. {
  12564. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12565. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12566. {
  12567. profileQuantity += 1;
  12568. }
  12569. else
  12570. replaceableProfileCnt += 1;
  12571. }
  12572. }
  12573. }
  12574. fclose(fp);
  12575. }
  12576. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12577. {
  12578. FILE *fp;
  12579. char filename[128]={0};
  12580. int tmpProfileQuantity;
  12581. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12582. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12583. {
  12584. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12585. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12586. goto end;
  12587. }
  12588. if(SetProfileReq.ConnectorId == 0)
  12589. {
  12590. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12591. {
  12592. tmpProfileQuantity = 0;
  12593. memset(filename, 0, ARRAY_SIZE(filename));
  12594. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12595. fp = fopen(filename, "r");
  12596. if (!fp)
  12597. {
  12598. DEBUG_INFO("%s does not create.\n", filename);
  12599. fp = fopen(filename, "w+");
  12600. }
  12601. else
  12602. {
  12603. char *line = NULL;
  12604. size_t len = 0;
  12605. while(getline(&line, &len, fp) != -1)
  12606. {
  12607. json_object *obj = NULL;
  12608. obj = json_tokener_parse(line);
  12609. if(is_error(obj))
  12610. {
  12611. DEBUG_ERROR("Parse txProfile from file error.\n");
  12612. }
  12613. else
  12614. {
  12615. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12616. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12617. {
  12618. tmpProfileQuantity += 1;
  12619. }
  12620. else
  12621. replaceableProfileCnt += 1;
  12622. }
  12623. }
  12624. }
  12625. fclose(fp);
  12626. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12627. }
  12628. }
  12629. else
  12630. {
  12631. memset(filename, 0, ARRAY_SIZE(filename));
  12632. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12633. fp = fopen(filename, "r");
  12634. if (!fp)
  12635. {
  12636. DEBUG_INFO("%s does not create.\n", filename);
  12637. fp = fopen(filename, "w+");
  12638. }
  12639. else
  12640. {
  12641. char *line = NULL;
  12642. size_t len = 0;
  12643. while(getline(&line, &len, fp) != -1)
  12644. {
  12645. json_object *obj = NULL;
  12646. obj = json_tokener_parse(line);
  12647. if(is_error(obj))
  12648. {
  12649. DEBUG_ERROR("Parse txProfile from file error.\n");
  12650. }
  12651. else
  12652. {
  12653. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12654. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12655. {
  12656. profileQuantity += 1;
  12657. }
  12658. else
  12659. replaceableProfileCnt += 1;
  12660. }
  12661. }
  12662. }
  12663. fclose(fp);
  12664. }
  12665. }
  12666. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12667. {
  12668. int isMatchTransactiodId= FALSE;
  12669. FILE *fp;
  12670. char filename[128]={0};
  12671. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12672. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12673. if(SetProfileReq.ConnectorId == 0)
  12674. {
  12675. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12676. DEBUG_WARN("Profile connector id is 0.\n");
  12677. goto end;
  12678. }
  12679. int tempIndex = 0;
  12680. //check Transaction active
  12681. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12682. {
  12683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12684. {
  12685. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12686. }
  12687. else
  12688. {
  12689. tempIndex = SetProfileReq.ConnectorId -1;
  12690. }
  12691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12692. {
  12693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12694. {
  12695. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12696. {
  12697. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12698. {
  12699. isMatchTransactiodId = TRUE;
  12700. break;
  12701. }
  12702. }
  12703. }
  12704. }
  12705. }
  12706. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12707. {
  12708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12709. {
  12710. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12711. }
  12712. else
  12713. {
  12714. tempIndex = SetProfileReq.ConnectorId -1;
  12715. }
  12716. for (int index = 0; index < CCS_QUANTITY; index++)
  12717. {
  12718. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12719. {
  12720. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12721. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12722. {
  12723. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12724. {
  12725. isMatchTransactiodId = TRUE;
  12726. break;
  12727. }
  12728. }
  12729. }
  12730. }
  12731. }
  12732. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12733. {
  12734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12735. {
  12736. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12737. }
  12738. else
  12739. {
  12740. tempIndex = SetProfileReq.ConnectorId -1;
  12741. }
  12742. for (int index = 0; index < GB_QUANTITY; index++)
  12743. {
  12744. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12745. {
  12746. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12747. {
  12748. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12749. {
  12750. isMatchTransactiodId = TRUE;
  12751. break;
  12752. }
  12753. }
  12754. }
  12755. }
  12756. }
  12757. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12758. {
  12759. tempIndex = SetProfileReq.ConnectorId -1;
  12760. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12761. {
  12762. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12763. {
  12764. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12765. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12766. {
  12767. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12768. {
  12769. isMatchTransactiodId = TRUE;
  12770. break;
  12771. }
  12772. }
  12773. }
  12774. }
  12775. }
  12776. else
  12777. {
  12778. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12779. {
  12780. tempIndex = 2;
  12781. }
  12782. else
  12783. {
  12784. tempIndex = (SetProfileReq.ConnectorId -1);
  12785. }
  12786. for (int index = 0; index < AC_QUANTITY; index++)
  12787. {
  12788. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12789. {
  12790. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12791. {
  12792. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12793. {
  12794. isMatchTransactiodId = TRUE;
  12795. break;
  12796. }
  12797. }
  12798. }
  12799. }
  12800. }
  12801. //check Transaction active
  12802. if(isMatchTransactiodId == FALSE)
  12803. {
  12804. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12805. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12806. goto end;
  12807. }
  12808. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12809. {
  12810. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12811. DEBUG_WARN("Connector id is over max gun number.\n");
  12812. goto end;
  12813. }
  12814. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12815. fp = fopen(filename, "r");
  12816. if (!fp)
  12817. {
  12818. DEBUG_INFO("%s does not create.\n", filename);
  12819. fp = fopen(filename, "w+");
  12820. }
  12821. else
  12822. {
  12823. char *line = NULL;
  12824. size_t len = 0;
  12825. while(getline(&line, &len, fp) != -1)
  12826. {
  12827. json_object *obj = NULL;
  12828. obj = json_tokener_parse(line);
  12829. if(is_error(obj))
  12830. {
  12831. DEBUG_ERROR("Parse txProfile from file error.\n");
  12832. }
  12833. else
  12834. {
  12835. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12836. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12837. {
  12838. profileQuantity += 1;
  12839. }
  12840. else
  12841. replaceableProfileCnt += 1;
  12842. }
  12843. }
  12844. }
  12845. fclose(fp);
  12846. }
  12847. // Check ChargeProfileMaxStackLevel
  12848. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12849. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12850. {
  12851. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12852. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12853. goto end;
  12854. }
  12855. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12856. {
  12857. FILE *fp;
  12858. char dataLine[4096]={0};
  12859. char fnametemp[128]={0};
  12860. int tmpProfileQuantity;
  12861. //Check ChargePointMaxProfile.json exit
  12862. profileQuantity = 0;
  12863. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12864. {
  12865. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12866. //Check Charging Profile Count
  12867. tmpProfileQuantity = 0;
  12868. while(fscanf(fp, "%s", dataLine) != EOF)
  12869. {
  12870. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12871. {
  12872. profileQuantity += 1;
  12873. tmpProfileQuantity += 1;
  12874. }
  12875. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12876. }
  12877. fclose(fp);
  12878. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12879. }
  12880. //Check TxDefaultProfile_%d.json
  12881. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12882. {
  12883. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12884. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12885. if((access(fnametemp,F_OK))!=-1)
  12886. {
  12887. fp = fopen(fnametemp, "r");
  12888. //Check Charging Profile Count
  12889. tmpProfileQuantity = 0;
  12890. while(fscanf(fp, "%s", dataLine) != EOF)
  12891. {
  12892. //DEBUG_INFO("word=%s\n",word);
  12893. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12894. {
  12895. profileQuantity += 1;
  12896. tmpProfileQuantity += 1;
  12897. }
  12898. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12899. }
  12900. fclose(fp);
  12901. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12902. }
  12903. }
  12904. //Check TxProfile_%d.json
  12905. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12906. {
  12907. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12908. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12909. if((access(fnametemp,F_OK))!=-1)
  12910. {
  12911. fp = fopen(fnametemp, "r");
  12912. //Check Charging Profile Count
  12913. tmpProfileQuantity = 0;
  12914. while(fscanf(fp, "%s", dataLine) != EOF)
  12915. {
  12916. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12917. {
  12918. profileQuantity += 1;
  12919. tmpProfileQuantity += 1;
  12920. }
  12921. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12922. }
  12923. fclose(fp);
  12924. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12925. }
  12926. }
  12927. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12928. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12929. // To check total Profile quantity
  12930. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12931. {
  12932. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12933. {
  12934. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12935. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12936. goto end;
  12937. }
  12938. }
  12939. else
  12940. {
  12941. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12942. {
  12943. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12944. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12945. goto end;
  12946. }
  12947. }
  12948. }
  12949. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12950. //**********************************Write to File********************************************************/
  12951. {
  12952. FILE *infile;
  12953. FILE *outfile;
  12954. char dataLine[4096]={0};
  12955. char filename[128]={0};
  12956. int chkChar=0;
  12957. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12958. {
  12959. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12960. {
  12961. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12962. }
  12963. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12964. {
  12965. if(SetProfileReq.ConnectorId==0)
  12966. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12967. else
  12968. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12969. }
  12970. else
  12971. {
  12972. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12973. }
  12974. infile = fopen (filename, "r");
  12975. outfile = fopen (tempfile, "w");
  12976. chkChar = fgetc(infile);
  12977. rewind(infile);
  12978. if(chkChar == EOF)
  12979. {
  12980. // Profile is empty
  12981. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12982. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12983. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12984. fclose(infile);
  12985. fclose(outfile);
  12986. sprintf(rmFileCmd,"rm -f %s",filename);
  12987. system(rmFileCmd);
  12988. rename(tempfile, filename);
  12989. }
  12990. else
  12991. {
  12992. // Profile is not empty
  12993. int ChargingProfileAdded = FALSE;
  12994. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12995. {
  12996. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12997. json_object *tmpChargingProfile;
  12998. tmpChargingProfile = json_tokener_parse(dataLine);
  12999. if(!is_error(SetChargingProfile))
  13000. {
  13001. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13002. {
  13003. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13004. {
  13005. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13006. }
  13007. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13008. {
  13009. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13010. }
  13011. }
  13012. }
  13013. json_object_put(tmpChargingProfile);
  13014. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13015. {
  13016. if(ChargingProfileAdded == FALSE)
  13017. {
  13018. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13019. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13020. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13021. ChargingProfileAdded = TRUE;
  13022. }
  13023. }
  13024. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13025. {
  13026. if(ChargingProfileAdded == FALSE)
  13027. {
  13028. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13029. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13030. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13031. ChargingProfileAdded = TRUE;
  13032. }
  13033. }
  13034. else
  13035. {
  13036. fprintf(outfile,"%s\n",dataLine);
  13037. if(ChargingProfileAdded == FALSE)
  13038. {
  13039. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13040. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13041. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13042. ChargingProfileAdded = TRUE;
  13043. }
  13044. }
  13045. } // end of while loop
  13046. fclose(infile);
  13047. fclose(outfile);
  13048. sprintf(rmFileCmd,"rm -f %s",filename);
  13049. system(rmFileCmd);
  13050. rename(tempfile, filename);
  13051. }
  13052. }
  13053. sleep(1);
  13054. result = TRUE;
  13055. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13056. }
  13057. end:
  13058. json_object_put(SetChargingProfile);
  13059. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13060. {
  13061. if(SetProfileReq.ConnectorId == 0)
  13062. {
  13063. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13064. {
  13065. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13066. }
  13067. }
  13068. else
  13069. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13070. }
  13071. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13072. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13073. return result;
  13074. }
  13075. int handleTriggerMessageRequest(char *uuid, char *payload)
  13076. {
  13077. mtrace();
  13078. int result = FAIL;
  13079. int connectorIdIsNULL = FALSE;
  13080. int connectorIdInt =0;
  13081. char sstr[40]={0},sstrtemp[100]={ 0 };
  13082. char requestedMessagestr[40]={0};
  13083. char comfirmstr[20]={0};
  13084. int c = 0;
  13085. char *loc;
  13086. DEBUG_INFO("handleTriggerMessageRequest\n");
  13087. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13088. strcpy(sstrtemp, stringtrimspace(payload));
  13089. c = 0;
  13090. loc = strstr(sstrtemp, "requestedMessage");
  13091. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13092. {
  13093. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13094. c++;
  13095. }
  13096. sstr[c] = '\0';
  13097. strcpy(requestedMessagestr, sstr);
  13098. c = 0;
  13099. loc = strstr(sstrtemp, "connectorId");
  13100. if(loc == NULL)
  13101. {
  13102. connectorIdIsNULL = TRUE;
  13103. }
  13104. else
  13105. {
  13106. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13107. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13108. {
  13109. sstr[c] = loc[strlen("connectorId")+2+c];
  13110. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13111. c++;
  13112. }
  13113. sstr[c] = '\0';
  13114. connectorIdInt = atoi(sstr);
  13115. }
  13116. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13117. {
  13118. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13119. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13120. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13121. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13122. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13123. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13124. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13125. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13126. {
  13127. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13128. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13129. return TRUE;
  13130. }
  13131. else
  13132. {
  13133. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13134. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13135. }
  13136. }
  13137. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13138. {
  13139. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13140. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13141. return TRUE;
  13142. }
  13143. //==========================
  13144. // Trigger message
  13145. //==========================
  13146. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13147. {
  13148. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13149. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13150. {
  13151. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13152. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13153. }
  13154. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13155. }
  13156. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13157. {
  13158. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13159. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13160. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13161. }
  13162. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13163. {
  13164. //sendBootNotificationRequest();
  13165. server_sign = FALSE;
  13166. }
  13167. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13168. {
  13169. refreshStartTimer(&clientTime.Heartbeat);
  13170. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13171. }
  13172. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13173. {
  13174. if(connectorIdIsNULL == FALSE)
  13175. {
  13176. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13177. {
  13178. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13179. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13180. }
  13181. }
  13182. else
  13183. {
  13184. for(int idx=0;idx< gunTotalNumber;idx++)
  13185. {
  13186. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13187. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13188. }
  13189. }
  13190. }
  13191. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13192. {
  13193. if(connectorIdIsNULL == FALSE)
  13194. {
  13195. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13196. {
  13197. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13198. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13199. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13200. }
  13201. }
  13202. else
  13203. {
  13204. for(int idx=0;idx< gunTotalNumber;idx++)
  13205. {
  13206. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13207. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13208. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13209. }
  13210. }
  13211. }
  13212. return result;
  13213. }
  13214. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13215. {
  13216. mtrace();
  13217. int result = FAIL;
  13218. int connectorIdInt =0;
  13219. char comfirmstr[20]={0};
  13220. int tempIndex = 0;
  13221. json_object *UnlockConnector;
  13222. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13223. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13224. UnlockConnector = json_tokener_parse(payload);
  13225. if(!is_error(UnlockConnector))
  13226. {
  13227. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13228. {
  13229. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13230. }
  13231. }
  13232. json_object_put(UnlockConnector);
  13233. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13234. if(gunTotalNumber == 0)
  13235. {
  13236. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13237. goto end;
  13238. }
  13239. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13240. {
  13241. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13242. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13243. goto end;
  13244. }
  13245. else
  13246. {
  13247. //check Transaction active
  13248. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13249. {
  13250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13251. {
  13252. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13253. }
  13254. else
  13255. {
  13256. tempIndex = connectorIdInt -1;
  13257. }
  13258. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13259. {
  13260. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13261. {
  13262. //stop Transaction
  13263. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13264. }
  13265. }
  13266. }
  13267. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13268. {
  13269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13270. {
  13271. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13272. }
  13273. else
  13274. {
  13275. tempIndex = connectorIdInt -1;
  13276. }
  13277. for (int index = 0; index < CCS_QUANTITY; index++)
  13278. {
  13279. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13280. {
  13281. //stop Transaction
  13282. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13283. }
  13284. }
  13285. }
  13286. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13287. {
  13288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13289. {
  13290. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13291. }
  13292. else
  13293. {
  13294. tempIndex = connectorIdInt -1;
  13295. }
  13296. for (int index = 0; index < GB_QUANTITY; index++)
  13297. {
  13298. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13299. {
  13300. //stop Transaction
  13301. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13302. }
  13303. }
  13304. }
  13305. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13306. {
  13307. tempIndex = connectorIdInt -1;
  13308. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13309. {
  13310. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13311. {
  13312. //stop Transaction
  13313. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13314. }
  13315. }
  13316. }
  13317. else
  13318. {
  13319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13320. {
  13321. tempIndex = 2;
  13322. }
  13323. else
  13324. {
  13325. tempIndex = connectorIdInt-1;
  13326. }
  13327. for (int index = 0; index < AC_QUANTITY; index++)
  13328. {
  13329. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13330. {
  13331. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13332. }
  13333. }
  13334. }
  13335. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13336. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13337. result = TRUE;
  13338. return result;
  13339. }
  13340. end:
  13341. //json_object_put(obj); --- remove temporally
  13342. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13343. return result;
  13344. }
  13345. static char UpdateFirmwarepayloadData[300]={0};
  13346. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13347. {
  13348. mtrace();
  13349. int result = FAIL;
  13350. pthread_t t;
  13351. sendUpdateFirmwareConfirmation(uuid);
  13352. memset(UpdateFirmwarepayloadData, 0, 300);
  13353. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13354. if(!interLock.isUpdateFirmwareGoing)
  13355. {
  13356. interLock.isUpdateFirmwareGoing = 1;
  13357. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13358. sleep(1);
  13359. }
  13360. else
  13361. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13362. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13363. return result;
  13364. }
  13365. void *UpdateFirmwareProcess(void *data)
  13366. {
  13367. pthread_detach(pthread_self());
  13368. mtrace();
  13369. int retriesInt =0, retryIntervalInt=0;
  13370. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13371. int port=0;
  13372. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13373. int isSuccess = 0;
  13374. char ftpbuf[1024];
  13375. char temp[1024];
  13376. char * pch;
  13377. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13378. json_object *UpdateFirmware;
  13379. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13380. if(!is_error(UpdateFirmware))
  13381. {
  13382. // Required data
  13383. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13384. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13385. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13386. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13387. // Optional data
  13388. if(json_object_object_get(UpdateFirmware, "retries"))
  13389. {
  13390. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13391. }
  13392. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13393. {
  13394. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13395. }
  13396. }
  13397. json_object_put(UpdateFirmware);
  13398. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13399. memset(path, 0, ARRAY_SIZE(path));
  13400. // Wait retrieveData
  13401. if(strlen(retrieveDatestr) > 10)
  13402. {
  13403. do
  13404. {
  13405. sleep(1);
  13406. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13407. }
  13408. // Ready to download
  13409. system("rm -f /mnt/*");
  13410. if(strncmp(locationstr,"http", 4) == 0)
  13411. {
  13412. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13413. sprintf(ftppath,"/%s", path);
  13414. DEBUG_INFO("locationstr: %s\n", locationstr);
  13415. DEBUG_INFO("protocol: %s\n",protocol);
  13416. DEBUG_INFO("host: %s\n",host);
  13417. DEBUG_INFO("path: %s\n",path);
  13418. DEBUG_INFO("ftppath: %s\n",ftppath);
  13419. int ftppathlen=strlen(ftppath);
  13420. int i=1;
  13421. char filenametemp[50];
  13422. while(i < ftppathlen)
  13423. {
  13424. int len=ftppathlen-i;
  13425. if(ftppath[len]== 47) // '/' ascll code: 47
  13426. {
  13427. DEBUG_INFO("compare '/' all right\n");
  13428. break;
  13429. }
  13430. i=i+1;
  13431. }
  13432. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13433. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13434. filenametemp[i+1] = 0;
  13435. do
  13436. {
  13437. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13438. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13439. sleep(1);
  13440. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13441. if(!isSuccess)
  13442. {
  13443. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13444. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13445. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13446. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13447. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13448. }
  13449. else
  13450. {
  13451. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13452. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13453. }
  13454. retriesInt--;
  13455. }while((isSuccess == 0)&&(retriesInt >= 0));
  13456. }
  13457. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13458. {
  13459. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13460. memset(temp, 0, ARRAY_SIZE(temp));
  13461. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13462. strcpy(ftpbuf, locationstr);
  13463. int ftppathlen=strlen(ftpbuf);
  13464. int i=1;
  13465. char filenametemp[50];
  13466. while(i < ftppathlen)
  13467. {
  13468. int len=ftppathlen-i;
  13469. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13470. {
  13471. DEBUG_INFO(" compare '/' all right\n");
  13472. break;
  13473. }
  13474. i=i+1;
  13475. }
  13476. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13477. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13478. filenametemp[i+1] = 0;
  13479. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13480. pch=strchr(temp,'@');
  13481. if(pch==NULL)
  13482. {
  13483. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13484. protocol, host, &port, path);
  13485. strcpy(user,"anonymous");
  13486. strcpy(password,"");
  13487. }
  13488. else
  13489. {
  13490. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13491. protocol, user, host, &port, path);
  13492. }
  13493. sscanf(host,"%[^/]%s",host1, path1);
  13494. sprintf(ftppath,"%s:/%s", host,path);
  13495. if(port == 0)
  13496. {
  13497. port = 21;
  13498. }
  13499. do
  13500. {
  13501. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13502. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13503. sleep(1);
  13504. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13505. if(!isSuccess)
  13506. {
  13507. //BulldogUtil.sleepMs(interval*1000);
  13508. DEBUG_INFO("Update firmware request and download file fail.\n");
  13509. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13510. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13511. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13512. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13513. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13514. }
  13515. else
  13516. {
  13517. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13518. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13519. }
  13520. retriesInt--;
  13521. }while((!isSuccess)&&(retriesInt >= 0));
  13522. }
  13523. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13524. {
  13525. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13526. memset(temp, 0, ARRAY_SIZE(temp));
  13527. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13528. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13529. int ftppathlen=strlen(ftpbuf);
  13530. int i=1;
  13531. char filenametemp[50];
  13532. while(i < ftppathlen)
  13533. {
  13534. int len=ftppathlen-i;
  13535. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13536. {
  13537. DEBUG_INFO(" compare '/' all right\n");
  13538. break;
  13539. }
  13540. i=i+1;
  13541. }
  13542. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13543. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13544. filenametemp[i+1] = 0;
  13545. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13546. pch=strchr(temp,'@');
  13547. if(pch==NULL)
  13548. {
  13549. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13550. protocol, host, &port, path);
  13551. strcpy(user,"anonymous");
  13552. strcpy(password,"");
  13553. }
  13554. else
  13555. {
  13556. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13557. protocol, user, password, host, &port, path);
  13558. }
  13559. sscanf(host,"%[^/]%s",host1, path1);
  13560. sprintf(ftppath,"%s", path1);
  13561. //DEBUG_INFO("protocol =%s\n",protocol);
  13562. //DEBUG_INFO("user =%s\n",user);
  13563. //DEBUG_INFO("password =%s\n",password);
  13564. //DEBUG_INFO("host1 =%s\n",host1);
  13565. //DEBUG_INFO("port =%d\n",port);
  13566. //DEBUG_INFO("path1 =%s\n",path1);
  13567. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13568. //ftpFile(host, user, password, port, ftppath, fname);
  13569. //download firmware pthred
  13570. if(port == 0)
  13571. {
  13572. port = 21;
  13573. }
  13574. do
  13575. {
  13576. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13577. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13578. sleep(1);
  13579. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13580. if(!isSuccess)
  13581. {
  13582. //BulldogUtil.sleepMs(interval*1000);
  13583. DEBUG_INFO("Update firmware request and download file fail.\n");
  13584. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13585. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13586. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13587. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13588. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13589. }
  13590. else
  13591. {
  13592. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13593. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13594. }
  13595. retriesInt--;
  13596. }while((!isSuccess)&&(retriesInt >= 0));
  13597. }
  13598. else
  13599. {
  13600. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13601. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13602. sleep(1);
  13603. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13604. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13605. }
  13606. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13607. interLock.isUpdateFirmwareGoing = 0;
  13608. pthread_exit(NULL);
  13609. }
  13610. int handleCertificateSignedRequest(char *uuid, char *payload)
  13611. {
  13612. mtrace();
  13613. int result = PASS;
  13614. json_object *CertificateSigned;
  13615. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13616. CertificateSigned = json_tokener_parse(payload);
  13617. if(!is_error(CertificateSigned))
  13618. {
  13619. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13620. }
  13621. json_object_put(CertificateSigned);
  13622. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13623. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13624. fclose(fp);
  13625. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13626. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13627. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13628. sendCertificateSignedConfirmation(uuid);
  13629. return result;
  13630. }
  13631. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13632. {
  13633. mtrace();
  13634. int result = PASS;
  13635. json_object *DeleteCertificate;
  13636. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13637. DeleteCertificate = json_tokener_parse(payload);
  13638. if(!is_error(DeleteCertificate))
  13639. {
  13640. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13641. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13642. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13643. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13644. }
  13645. json_object_put(DeleteCertificate);
  13646. /*
  13647. * TODO: Delete certificateSigned process
  13648. */
  13649. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13650. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13651. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13652. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13653. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13654. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13655. sendDeleteCertificateConfirmation(uuid);
  13656. return result;
  13657. }
  13658. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13659. {
  13660. mtrace();
  13661. int result = PASS;
  13662. json_object *ExtendedTriggerMessage;
  13663. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13664. ExtendedTriggerMessage = json_tokener_parse(payload);
  13665. if(!is_error(ExtendedTriggerMessage))
  13666. {
  13667. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13668. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13669. {
  13670. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13671. }
  13672. else
  13673. {
  13674. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13675. }
  13676. }
  13677. json_object_put(ExtendedTriggerMessage);
  13678. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13679. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13680. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13681. {
  13682. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13683. }
  13684. else
  13685. {
  13686. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13687. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13688. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13689. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13690. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13691. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13692. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13693. {
  13694. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13695. }
  13696. else
  13697. {
  13698. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13699. }
  13700. }
  13701. sendExtendedTriggerMessageConfirmation(uuid);
  13702. //==========================
  13703. // Trigger message
  13704. //==========================
  13705. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13706. {
  13707. //sendBootNotificationRequest();
  13708. server_sign = FALSE;
  13709. }
  13710. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13711. {
  13712. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13713. }
  13714. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13715. {
  13716. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13717. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13718. {
  13719. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13720. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13721. }
  13722. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13723. }
  13724. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13725. {
  13726. refreshStartTimer(&clientTime.Heartbeat);
  13727. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13728. }
  13729. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13730. {
  13731. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13732. {
  13733. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13734. }
  13735. else
  13736. {
  13737. for(int idx=0;idx< gunTotalNumber;idx++)
  13738. {
  13739. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13740. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13741. }
  13742. }
  13743. }
  13744. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13745. {
  13746. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13747. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13748. {
  13749. 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\" &");
  13750. }
  13751. }
  13752. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13753. {
  13754. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13755. {
  13756. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13757. }
  13758. else
  13759. {
  13760. for(int idx=0;idx< gunTotalNumber;idx++)
  13761. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13762. }
  13763. }
  13764. return result;
  13765. }
  13766. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13767. {
  13768. mtrace();
  13769. int result = PASS;
  13770. json_object *GetInstalledCertificateIds;
  13771. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13772. GetInstalledCertificateIds = json_tokener_parse(payload);
  13773. if(!is_error(GetInstalledCertificateIds))
  13774. {
  13775. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13776. }
  13777. json_object_put(GetInstalledCertificateIds);
  13778. /*
  13779. * TODO: Return installed certificate process
  13780. */
  13781. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13782. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13783. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13784. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13785. sendGetInstalledCertificateIdsConfirmation(uuid);
  13786. return result;
  13787. }
  13788. int handleGetLogRequest(char *uuid, char *payload)
  13789. {
  13790. mtrace();
  13791. int result = PASS;
  13792. json_object *GetLog;
  13793. DEBUG_INFO("handleGetLogRequest...\n");
  13794. GetLog = json_tokener_parse(payload);
  13795. if(!is_error(GetLog))
  13796. {
  13797. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13798. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13799. if(json_object_object_get(GetLog, "retries") != NULL)
  13800. {
  13801. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13802. }
  13803. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13804. {
  13805. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13806. }
  13807. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13808. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13809. {
  13810. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13811. }
  13812. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13813. {
  13814. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13815. }
  13816. }
  13817. json_object_put(GetLog);
  13818. /*
  13819. * TODO: Upload log process
  13820. */
  13821. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13822. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13823. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13824. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13825. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13826. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13827. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13828. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13829. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13830. sendGetLogConfirmation(uuid);
  13831. return result;
  13832. }
  13833. int handleInstallCertificateRequest(char *uuid, char *payload)
  13834. {
  13835. mtrace();
  13836. int result = PASS;
  13837. json_object *InstallCertificate;
  13838. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13839. InstallCertificate = json_tokener_parse(payload);
  13840. if(!is_error(InstallCertificate))
  13841. {
  13842. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13843. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13844. /*
  13845. * TODO: Install certificate process
  13846. */
  13847. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13848. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13849. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13850. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13851. sendInstallCertificateConfirmation(uuid);
  13852. }
  13853. json_object_put(InstallCertificate);
  13854. return result;
  13855. }
  13856. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13857. {
  13858. mtrace();
  13859. int result = PASS;
  13860. json_object *SignedUpdateFirmware;
  13861. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13862. SignedUpdateFirmware = json_tokener_parse(payload);
  13863. if(!is_error(SignedUpdateFirmware))
  13864. {
  13865. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13866. {
  13867. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13868. }
  13869. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13870. {
  13871. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13872. }
  13873. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13874. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13875. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13876. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13877. {
  13878. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13879. }
  13880. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13881. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13882. }
  13883. json_object_put(SignedUpdateFirmware);
  13884. /*
  13885. * TODO: Upgrade firmware process
  13886. */
  13887. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13888. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13889. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13890. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13891. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13892. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13893. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13894. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13895. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13896. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13897. sendInstallCertificateConfirmation(uuid);
  13898. return result;
  13899. }
  13900. int handleUnknownRequest(char *uuid, char *payload)
  13901. {
  13902. mtrace();
  13903. int result = PASS;
  13904. DEBUG_INFO("handleUnknownRequest...\n");
  13905. sendUnknownConfirmation(uuid);
  13906. result = PASS;
  13907. return result;
  13908. }
  13909. //==========================================
  13910. // Handle server response routine
  13911. //==========================================
  13912. void handleAuthorizeResponse(char *payload, int gun_index)
  13913. {
  13914. mtrace();
  13915. char expiryDatestr[36]={0};
  13916. char parentIdTagstr[21]={0};
  13917. char statusstr[20]={0};
  13918. int expiryDateISNULL=FALSE;
  13919. int parentIdTagISNULL=FALSE;
  13920. DEBUG_INFO("handleAuthorizeResponse...\n");
  13921. json_object *Authorize;
  13922. Authorize = json_tokener_parse(payload);
  13923. if(!is_error(Authorize))
  13924. {
  13925. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13926. {
  13927. // Required data
  13928. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13929. // Optional data
  13930. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13931. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13932. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13933. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13934. }
  13935. }
  13936. json_object_put(Authorize);
  13937. if(expiryDateISNULL == FALSE)
  13938. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13939. if(parentIdTagISNULL == FALSE)
  13940. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13941. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13942. //Update idTag information to authorization cache if supproted
  13943. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13944. {
  13945. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13946. }
  13947. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13948. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13949. authorizeRetryTimes = 0;
  13950. }
  13951. void handleBootNotificationResponse(char *payload, int gun_index)
  13952. {
  13953. mtrace();
  13954. char statusStr[12]={0};
  13955. char currentTimeStr[30]={0};
  13956. int intervalInt = 0;
  13957. DEBUG_INFO("handleBootNotificationResponse...\n");
  13958. json_object *BootNotification;
  13959. BootNotification = json_tokener_parse(payload);
  13960. if(!is_error(BootNotification))
  13961. {
  13962. // Required data
  13963. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13964. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13965. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13966. }
  13967. json_object_put(BootNotification);
  13968. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13969. BootNotificationInterval = intervalInt;
  13970. //write back to ShmOCPP16Data->BootNotification
  13971. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13972. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13973. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13974. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13975. {
  13976. BootNotificationInterval = 0;
  13977. if((intervalInt == 0) || (intervalInt >= 10))
  13978. {
  13979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13980. HeartBeatWaitTime = intervalInt;
  13981. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13982. }
  13983. server_sign = TRUE;
  13984. server_pending =FALSE;
  13985. }
  13986. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13987. {
  13988. server_pending = TRUE;
  13989. }
  13990. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13991. srand(time(NULL));
  13992. refreshStartTimer(&clientTime.Heartbeat);
  13993. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13994. SetOcppConnStatus(TRUE);
  13995. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13996. }
  13997. void handleDataTransferResponse(char *payload, int gun_index)
  13998. {
  13999. json_object *DataTransfer = json_tokener_parse(payload);
  14000. if(!is_error(DataTransfer))
  14001. {
  14002. // Required data
  14003. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  14004. // Optional data
  14005. if(json_object_object_get(DataTransfer, "data") != NULL)
  14006. {
  14007. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14008. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  14009. if(!is_error(Data))
  14010. {
  14011. if(json_object_object_get(Data, "msgId") != NULL)
  14012. {
  14013. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  14014. {
  14015. 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")));
  14016. }
  14017. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  14018. {
  14019. if(json_object_object_get(Data, "ConnectorId") != NULL)
  14020. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  14021. }
  14022. }
  14023. }
  14024. json_object_put(Data);
  14025. }
  14026. }
  14027. json_object_put(DataTransfer);
  14028. }
  14029. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  14030. {
  14031. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  14032. //struct json_object *obj;
  14033. // obj = json_tokener_parse(payload);
  14034. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  14035. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  14036. //No fields are defined.
  14037. }
  14038. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14039. {
  14040. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  14041. //struct json_object *obj;
  14042. // obj = json_tokener_parse(payload);
  14043. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  14044. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  14045. //No fields are defined.
  14046. }
  14047. void handleHeartbeatResponse(char *payload, int gun_index)
  14048. {
  14049. mtrace();
  14050. DEBUG_INFO("handleHeartbeatResponse...\n");
  14051. json_object *Heartbeat;
  14052. Heartbeat = json_tokener_parse(payload);
  14053. if(!is_error(Heartbeat))
  14054. {
  14055. // Required data
  14056. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  14057. }
  14058. json_object_put(Heartbeat);
  14059. if(FirstHeartBeat == 0)
  14060. {
  14061. FirstHeartBeat = 1;
  14062. DEBUG_INFO("FirstHeartBeat \n");
  14063. }
  14064. HeartBeatWithNOResponse = 0;
  14065. refreshStartTimer(&clientTime.Heartbeat);
  14066. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  14067. }
  14068. void handleMeterValuesResponse(char *payload, int gun_index)
  14069. {
  14070. mtrace();
  14071. DEBUG_INFO("handleMeterValuesResponse...\n");
  14072. isQueueSendable = 1;
  14073. }
  14074. void handleStartTransactionResponse(char *payload, int gun_index)
  14075. {
  14076. mtrace();
  14077. //int transactionIdInt = 0;
  14078. FILE *outfile;
  14079. char data[100]={0};
  14080. DEBUG_INFO("handleStartTransactionResponse...\n");
  14081. json_object *StartTransaction;
  14082. StartTransaction = json_tokener_parse(payload);
  14083. if(!is_error(StartTransaction))
  14084. {
  14085. // Required data
  14086. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  14087. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  14088. // Optional data
  14089. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  14090. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  14091. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14092. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  14093. }
  14094. json_object_put(StartTransaction);
  14095. isQueueSendable = 1;
  14096. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  14097. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  14098. //-----------Start : write to the Queue TransactionId file -----------------//
  14099. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  14100. {}
  14101. else
  14102. {
  14103. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  14104. if(log == NULL)
  14105. {
  14106. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  14107. return ;
  14108. }
  14109. else
  14110. {
  14111. fclose(log);
  14112. }
  14113. }
  14114. // open file for writing
  14115. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  14116. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  14117. {
  14118. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  14119. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  14120. fputs(data, outfile);
  14121. fclose (outfile);
  14122. }
  14123. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14124. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14125. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  14126. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  14127. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14128. }
  14129. void handleStatusNotificationResponse(char *payload, int gun_index)
  14130. {
  14131. mtrace();
  14132. DEBUG_INFO("handleStatusNotificationResponse...\n");
  14133. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  14134. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14135. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  14136. }
  14137. void handleStopTransactionnResponse(char *payload, int gun_index)
  14138. {
  14139. mtrace();
  14140. DEBUG_INFO("handleStopTransactionnResponse...\n");
  14141. json_object *StopTransaction;
  14142. StopTransaction = json_tokener_parse(payload);
  14143. if(!is_error(StopTransaction))
  14144. {
  14145. // Optional data
  14146. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  14147. {
  14148. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  14149. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  14150. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  14151. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  14152. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  14153. }
  14154. }
  14155. json_object_put(StopTransaction);
  14156. isQueueSendable = 1;
  14157. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  14158. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  14159. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  14160. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  14161. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  14162. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  14163. }
  14164. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  14165. {
  14166. mtrace();
  14167. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  14168. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  14169. }
  14170. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  14171. {
  14172. mtrace();
  14173. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  14174. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  14175. }
  14176. void handleSignCertificateResponse(char *payload, int gun_index)
  14177. {
  14178. mtrace();
  14179. DEBUG_INFO("handleSignCertificateResponse...\n");
  14180. json_object *SignCertificate;
  14181. SignCertificate = json_tokener_parse(payload);
  14182. if(!is_error(SignCertificate))
  14183. {
  14184. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  14185. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  14186. }
  14187. json_object_put(SignCertificate);
  14188. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  14189. }
  14190. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14191. {
  14192. mtrace();
  14193. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  14194. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  14195. }
  14196. //==========================================
  14197. // Handle Error routine
  14198. //==========================================
  14199. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14200. {
  14201. mtrace();
  14202. #ifdef SystemLogMessage
  14203. DEBUG_INFO("errorCode: %s\n", errorCode);
  14204. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14205. DEBUG_INFO("errorDetails: %s\n", payload);
  14206. #endif
  14207. }
  14208. //===============================================
  14209. // Common routine
  14210. //===============================================
  14211. int initialConfigurationTable(void)
  14212. {
  14213. //clock_t start_t, end_t, total_t;
  14214. FILE *fp;
  14215. FILE *outfile;
  14216. char str[512]={0};
  14217. char sstr[256]={0};
  14218. int c = 0;
  14219. char *loc;
  14220. int confVersion = 15;
  14221. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14222. //start_t = clock();
  14223. //printf("Starting of the program, start_t = %ld\n", start_t);
  14224. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14225. // Check configuration file size is correct
  14226. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  14227. {
  14228. struct stat st;
  14229. stat("/Storage/OCPP/OCPPConfiguration", &st);
  14230. if(st.st_size < 3100)
  14231. {
  14232. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14233. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14234. }
  14235. }
  14236. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14237. {
  14238. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14239. if(outfile == NULL)
  14240. {
  14241. DEBUG_INFO("Error opening file\n");
  14242. return FALSE;
  14243. }
  14244. /*Core Profile*/
  14245. //AllowOfflineTxForUnknownId
  14246. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14250. //AuthorizationCacheEnabled
  14251. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14255. //AuthorizeRemoteTxRequests
  14256. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14260. //BlinkRepeat
  14261. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14265. //ClockAlignedDataInterval
  14266. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14270. //ConnectionTimeOut
  14271. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14275. //GetConfigurationMaxKeys
  14276. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14280. // HeartbeatInterval
  14281. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14285. // LightIntensity
  14286. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14290. // LocalAuthorizeOffline
  14291. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14295. // LocalPreAuthorize
  14296. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14300. // MaxEnergyOnInvalidId
  14301. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14305. // MeterValuesAlignedData
  14306. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14308. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14309. 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" );
  14310. else
  14311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14313. // MeterValuesAlignedDataMaxLength
  14314. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14316. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14318. else
  14319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14321. // MeterValuesSampledData
  14322. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14325. 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" );
  14326. else
  14327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14329. // MeterValuesSampledDataMaxLength
  14330. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14332. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14334. else
  14335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14337. // MeterValueSampleInterval
  14338. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14342. // MinimumStatusDuration
  14343. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14346. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14348. // NumberOfConnectors
  14349. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14351. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14352. {
  14353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14354. }
  14355. else
  14356. {
  14357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14358. }
  14359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14360. // ResetRetries
  14361. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14365. // ConnectorPhaseRotation
  14366. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14370. // ConnectorPhaseRotationMaxLength
  14371. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14375. // StopTransactionOnEVSideDisconnect
  14376. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14380. // StopTransactionOnInvalidId
  14381. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14385. // StopTxnAlignedData
  14386. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14390. // StopTxnAlignedDataMaxLength
  14391. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14395. // StopTxnSampledData
  14396. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14400. else
  14401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14403. // StopTxnSampledDataMaxLength
  14404. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14407. {
  14408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14409. }
  14410. else
  14411. {
  14412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14413. }
  14414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14415. // SupportedFeatureProfiles
  14416. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14420. // SupportedFeatureProfilesMaxLength
  14421. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14425. // TransactionMessageAttempts
  14426. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14429. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14431. // TransactionMessageRetryInterval
  14432. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14435. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14437. // UnlockConnectorOnEVSideDisconnect
  14438. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14442. // WebSocketPingInterval
  14443. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14447. // QueueOffLineMeterValues
  14448. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14452. // AuthorizationKey
  14453. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14457. // SecurityProfile
  14458. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14462. // DefaultPrice
  14463. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14466. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14467. // CustomDisplayCostAndPrice
  14468. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14472. // CustomIdleFeeAfterStop
  14473. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14477. // TimeOffset
  14478. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14481. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14482. // NextTimeOffsetTransitionDateTime
  14483. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14487. // TimeOffsetNextTransition
  14488. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14492. // SystemUptimeSec
  14493. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14497. // FreeVend
  14498. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14502. // FreeVendIdtag
  14503. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14507. // OcppServer
  14508. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14510. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14512. // MaintainServer
  14513. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14515. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14517. // StatusNotificationPeriodically
  14518. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14522. // StatusNotificationInterval
  14523. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14527. // PreAuthAmount
  14528. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14532. // isEnableLocalPowerSharing
  14533. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14537. // PowerSharingServerIP
  14538. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14540. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14542. // EVCCID_PREFIX
  14543. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14547. // Configuration Version
  14548. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14552. //* Local Auth List Management Profile*/
  14553. #if 0
  14554. //For OCTT Test Case
  14555. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14558. #endif
  14559. #if 1
  14560. //LocalAuthListEnabled
  14561. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14565. #endif
  14566. //LocalAuthListMaxLength
  14567. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14571. //SendLocalListMaxLength
  14572. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14576. //ReserveConnectorZeroSupported
  14577. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14581. //* Smart Charging Profile */
  14582. //ChargeProfileMaxStackLevel
  14583. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14587. // ChargingScheduleAllowedChargingRateUnit
  14588. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14592. // ChargingScheduleMaxPeriods
  14593. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14597. // ConnectorSwitch3to1PhaseSupported
  14598. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14602. // MaxChargingProfilesInstalled
  14603. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14607. fclose(outfile);
  14608. }
  14609. else
  14610. {
  14611. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14612. char keystr[60]={0};
  14613. char readonlystr[10]={0};
  14614. char valuestr[256]={0};
  14615. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14616. if(fp == NULL) {
  14617. DEBUG_INFO("Error opening file");
  14618. return FALSE;
  14619. }
  14620. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14621. {
  14622. //DEBUG_INFO("Get Configuration \n");
  14623. if(strlen(str) > 0)
  14624. {
  14625. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14626. //*************************key*********************************/
  14627. if(strstr(str, "key") != NULL)
  14628. {
  14629. loc = strstr(str, "key");
  14630. c = 0;
  14631. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14632. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14633. {
  14634. sstr[c] = loc[strlen("key")+3+c];
  14635. c++;
  14636. }
  14637. sstr[c] = '\0';
  14638. strcpy(keystr,sstr);
  14639. }
  14640. //*************************readonly*********************************/
  14641. if(strstr(str, "readonly") != NULL)
  14642. {
  14643. loc = strstr(str, "readonly");
  14644. c = 0;
  14645. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14646. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14647. {
  14648. sstr[c] = loc[strlen("readonly")+2+c];
  14649. c++;
  14650. }
  14651. sstr[c] = '\0';
  14652. strcpy(readonlystr,sstr);
  14653. }
  14654. //*************************value*********************************/
  14655. if(strstr(str, "value") != NULL)
  14656. {
  14657. loc = strstr(str, "value");
  14658. c = 0;
  14659. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14660. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14661. {
  14662. sstr[c] = loc[strlen("value")+3+c];
  14663. c++;
  14664. }
  14665. sstr[c] = '\0';
  14666. strcpy(valuestr,sstr);
  14667. }
  14668. // DEBUG_INFO("keystr=%s\n",keystr);
  14669. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14670. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14671. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14672. {
  14673. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14674. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14676. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14677. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14678. }
  14679. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14680. {
  14681. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14682. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14684. }
  14685. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14686. {
  14687. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14689. }
  14690. if(strcmp(keystr, "BlinkRepeat") == 0)
  14691. {
  14692. //Charger.BlinkRepeat = Integer.parseInt(value);
  14693. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14695. }
  14696. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14697. {
  14698. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14700. }
  14701. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14702. {
  14703. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14705. }
  14706. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14707. {
  14708. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14710. }
  14711. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14712. {
  14713. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14715. HeartBeatWaitTime = atoi(valuestr);
  14716. }
  14717. if(strcmp(keystr, "LightIntensity") == 0)
  14718. {
  14719. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14721. }
  14722. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14723. {
  14724. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14726. }
  14727. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14728. {
  14729. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14731. }
  14732. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14733. {
  14734. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14736. }
  14737. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14738. {
  14739. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14741. }
  14742. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14743. {
  14744. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14746. }
  14747. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14748. {
  14749. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14751. }
  14752. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14753. {
  14754. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14756. }
  14757. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14758. {
  14759. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14761. }
  14762. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14763. {
  14764. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14766. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14767. }
  14768. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14769. {
  14770. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14772. }
  14773. if(strcmp(keystr, "ResetRetries") == 0)
  14774. {
  14775. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14777. }
  14778. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14779. {
  14780. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14782. }
  14783. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14784. {
  14785. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14787. }
  14788. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14789. {
  14790. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14792. }
  14793. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14794. {
  14795. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14797. }
  14798. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14799. {
  14800. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14802. }
  14803. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14804. {
  14805. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14807. }
  14808. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14809. {
  14810. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14812. }
  14813. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14814. {
  14815. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14817. }
  14818. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14819. {
  14820. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14822. }
  14823. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14824. {
  14825. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14827. }
  14828. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14829. {
  14830. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14832. TransactionMessageAttemptsValue = atoi(valuestr);
  14833. }
  14834. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14835. {
  14836. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14838. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14839. }
  14840. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14841. {
  14842. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14844. }
  14845. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14846. {
  14847. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14849. }
  14850. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14851. {
  14852. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14854. }
  14855. if(strcmp(keystr, "AuthorizationKey") == 0)
  14856. {
  14857. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14858. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14860. }
  14861. if(strcmp(keystr, "SecurityProfile") == 0)
  14862. {
  14863. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14865. }
  14866. if(strcmp(keystr, "DefaultPrice") == 0)
  14867. {
  14868. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14870. }
  14871. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14872. {
  14873. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14874. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14875. }
  14876. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14877. {
  14878. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14879. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14880. }
  14881. if(strcmp(keystr, "TimeOffset") == 0)
  14882. {
  14883. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14885. }
  14886. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14887. {
  14888. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14890. }
  14891. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14892. {
  14893. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14895. }
  14896. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14897. {
  14898. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14900. }
  14901. if(strcmp(keystr, "FreeVend") == 0)
  14902. {
  14903. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14905. }
  14906. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14907. {
  14908. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14910. }
  14911. if(strcmp(keystr, "OcppServer") == 0)
  14912. {
  14913. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14914. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14915. }
  14916. if(strcmp(keystr, "MaintainServer") == 0)
  14917. {
  14918. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14919. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14920. }
  14921. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14922. {
  14923. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14925. }
  14926. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14927. {
  14928. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14930. }
  14931. if(strcmp(keystr, "PreAuthAmount") == 0)
  14932. {
  14933. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  14935. }
  14936. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14937. {
  14938. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14940. }
  14941. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14942. {
  14943. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14944. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14945. }
  14946. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14947. {
  14948. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14950. }
  14951. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14952. {
  14953. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14955. }
  14956. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14957. {
  14958. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14960. }
  14961. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14962. {
  14963. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14965. }
  14966. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14967. {
  14968. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14970. }
  14971. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14972. {
  14973. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14975. }
  14976. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14977. {
  14978. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14980. }
  14981. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14982. {
  14983. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14985. }
  14986. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14987. {
  14988. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14990. }
  14991. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14992. {
  14993. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14995. }
  14996. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14997. {
  14998. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  15000. }
  15001. }
  15002. }
  15003. fclose(fp);
  15004. }
  15005. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  15006. {
  15007. return PASS;
  15008. }
  15009. else
  15010. {
  15011. return FAIL;
  15012. }
  15013. }
  15014. void StoreConfigurationTable(void)
  15015. {
  15016. FILE *outfile;
  15017. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15018. if(outfile == NULL)
  15019. {
  15020. DEBUG_INFO("Error opening file");
  15021. return ;
  15022. }
  15023. /*Core Profile*/
  15024. //AllowOfflineTxForUnknownId
  15025. /*
  15026. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15027. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  15028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  15030. */
  15031. //DEBUG_INFO("data=%s\n",data);
  15032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15033. //AuthorizationCacheEnabled
  15034. /*
  15035. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15038. */
  15039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15040. //AuthorizeRemoteTxRequests
  15041. /*
  15042. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  15043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  15045. */
  15046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15047. //BlinkRepeat
  15048. /*
  15049. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15052. */
  15053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15054. //ClockAlignedDataInterval
  15055. /*
  15056. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15059. */
  15060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15061. //ConnectionTimeOut
  15062. /*
  15063. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15066. */
  15067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15068. //GetConfigurationMaxKeys
  15069. /*
  15070. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  15073. */
  15074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15075. // HeartbeatInterval
  15076. /*
  15077. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  15080. */
  15081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15082. // LightIntensity
  15083. /*
  15084. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15087. */
  15088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15089. // LocalAuthorizeOffline
  15090. /*
  15091. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  15092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15094. */
  15095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15096. // LocalPreAuthorize
  15097. /*
  15098. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  15099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15101. */
  15102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15103. // MaxEnergyOnInvalidId
  15104. /*
  15105. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15108. */
  15109. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  15110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15111. // MeterValuesAlignedData
  15112. /*
  15113. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15116. */
  15117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15118. // MeterValuesAlignedDataMaxLength
  15119. /*
  15120. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  15123. */
  15124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15125. // MeterValuesSampledData
  15126. /*
  15127. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  15130. */
  15131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15132. // MeterValuesSampledDataMaxLength
  15133. /*
  15134. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  15137. */
  15138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15139. // MeterValueSampleInterval
  15140. /*
  15141. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  15144. */
  15145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15146. // MinimumStatusDuration
  15147. /*
  15148. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  15151. */
  15152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15153. // NumberOfConnectors
  15154. /*
  15155. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15157. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15158. {
  15159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15160. }
  15161. else
  15162. {
  15163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15164. }
  15165. */
  15166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15167. // ResetRetries
  15168. /*
  15169. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15172. */
  15173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15174. // ConnectorPhaseRotation
  15175. /*
  15176. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15179. */
  15180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15181. // ConnectorPhaseRotationMaxLength
  15182. /*
  15183. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15186. */
  15187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15188. // StopTransactionOnEVSideDisconnect
  15189. /*
  15190. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  15191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15193. */
  15194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15195. // StopTransactionOnInvalidId
  15196. /*
  15197. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  15198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15200. */
  15201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15202. // StopTxnAlignedData
  15203. /*
  15204. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  15207. */
  15208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15209. // StopTxnAlignedDataMaxLength
  15210. /*
  15211. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15214. */
  15215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15216. // StopTxnSampledData
  15217. /*
  15218. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  15221. */
  15222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15223. // StopTxnSampledDataMaxLength
  15224. /*
  15225. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  15228. */
  15229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15230. // SupportedFeatureProfiles
  15231. /*
  15232. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15235. */
  15236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15237. // SupportedFeatureProfilesMaxLength
  15238. /*
  15239. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15242. */
  15243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15244. // TransactionMessageAttempts
  15245. /*
  15246. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15249. */
  15250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15251. // TransactionMessageRetryInterval
  15252. /*
  15253. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15256. */
  15257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15258. // UnlockConnectorOnEVSideDisconnect
  15259. /*
  15260. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15263. */
  15264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15265. // WebSocketPingInterval
  15266. /*
  15267. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15270. */
  15271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15272. // QueueOffLineMeterValues
  15273. /*
  15274. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15277. */
  15278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15279. // AuthorizationKey
  15280. /*
  15281. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15284. */
  15285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15286. // SecurityProfile
  15287. /*
  15288. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15291. */
  15292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15293. // DefaultPrice
  15294. /*
  15295. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15298. */
  15299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15300. // CustomDisplayCostAndPrice
  15301. /*
  15302. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15305. */
  15306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15307. // CustomIdleFeeAfterStop
  15308. /*
  15309. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15312. */
  15313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15314. // TimeOffset
  15315. /*
  15316. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15319. */
  15320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15321. // NextTimeOffsetTransitionDateTime
  15322. /*
  15323. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15326. */
  15327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15328. // TimeOffsetNextTransition
  15329. /*
  15330. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15333. */
  15334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15335. // SystemUptimeSec
  15336. /*
  15337. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15340. */
  15341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15342. // FreeVend
  15343. /*
  15344. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15347. */
  15348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15349. // FreeVendIdtag
  15350. /*
  15351. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15354. */
  15355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15356. // OcppServer
  15357. /*
  15358. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15361. */
  15362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15363. // MaintainServer
  15364. /*
  15365. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15368. */
  15369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15370. // StatusNotificationPeriodically
  15371. /*
  15372. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15375. */
  15376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15377. // StatusNotificationInterval
  15378. /*
  15379. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15382. */
  15383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15384. // PreAuthAmount
  15385. /*
  15386. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15389. */
  15390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15391. // isEnableLocalPowerSharing
  15392. /*
  15393. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15396. */
  15397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15398. // PowerSharingServerIP
  15399. /*
  15400. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15403. */
  15404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15405. // EVCCID_PREFIX
  15406. /*
  15407. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15410. */
  15411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15412. // ConfigurationVersion
  15413. /*
  15414. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15417. */
  15418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15419. //* Local Auth List Management Profile*/
  15420. //LocalAuthListEnabled
  15421. /*
  15422. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15425. */
  15426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15427. //LocalAuthListMaxLength
  15428. /*
  15429. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15432. */
  15433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15434. //SendLocalListMaxLength
  15435. /*
  15436. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15439. */
  15440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15441. //ReserveConnectorZeroSupported
  15442. /*
  15443. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15446. */
  15447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15448. //* Smart Charging Profile */
  15449. //ChargeProfileMaxStackLevel
  15450. /*
  15451. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15454. */
  15455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15456. // ChargingScheduleAllowedChargingRateUnit
  15457. /*
  15458. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15461. */
  15462. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15463. // ChargingScheduleMaxPeriods
  15464. /*
  15465. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15468. */
  15469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15470. // ConnectorSwitch3to1PhaseSupported
  15471. /*
  15472. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15475. */
  15476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15477. // MaxChargingProfilesInstalled
  15478. /*
  15479. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15482. */
  15483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15484. fclose(outfile);
  15485. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15486. }
  15487. void getKeyValue(char *keyReq)
  15488. {
  15489. int isEmpty = FALSE;
  15490. int isKnowKey = FALSE;
  15491. DEBUG_INFO("keyReq = %s\n", keyReq);
  15492. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15493. isEmpty = TRUE;
  15494. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15495. {
  15496. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15498. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15499. {
  15500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15501. }
  15502. else
  15503. {
  15504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15505. }
  15506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15507. isKnowKey = TRUE;
  15508. }
  15509. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15510. {
  15511. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15513. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15514. {
  15515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15516. }
  15517. else
  15518. {
  15519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15520. }
  15521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15522. isKnowKey = TRUE;
  15523. }
  15524. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15525. {
  15526. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15528. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15529. {
  15530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15531. }
  15532. else
  15533. {
  15534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15535. }
  15536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15537. isKnowKey = TRUE;
  15538. }
  15539. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15540. {
  15541. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15543. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15544. {
  15545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15546. }
  15547. else
  15548. {
  15549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15550. }
  15551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15552. isKnowKey = TRUE;
  15553. }
  15554. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15555. {
  15556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15559. {
  15560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15561. }
  15562. else
  15563. {
  15564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15565. }
  15566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15567. isKnowKey = TRUE;
  15568. }
  15569. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15570. {
  15571. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15574. {
  15575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15576. }
  15577. else
  15578. {
  15579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15580. }
  15581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15582. isKnowKey = TRUE;
  15583. }
  15584. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15585. {
  15586. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15589. {
  15590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15591. }
  15592. else
  15593. {
  15594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15595. }
  15596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15597. isKnowKey = TRUE;
  15598. }
  15599. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15600. {
  15601. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15603. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15604. {
  15605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15606. }
  15607. else
  15608. {
  15609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15610. }
  15611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15612. isKnowKey = TRUE;
  15613. }
  15614. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15615. {
  15616. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15618. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15619. {
  15620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15621. }
  15622. else
  15623. {
  15624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15625. }
  15626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15627. isKnowKey = TRUE;
  15628. }
  15629. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15630. {
  15631. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15634. {
  15635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15636. }
  15637. else
  15638. {
  15639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15640. }
  15641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15642. isKnowKey = TRUE;
  15643. }
  15644. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15645. {
  15646. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15649. {
  15650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15651. }
  15652. else
  15653. {
  15654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15655. }
  15656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15657. isKnowKey = TRUE;
  15658. }
  15659. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15660. {
  15661. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15664. {
  15665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15666. }
  15667. else
  15668. {
  15669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15670. }
  15671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15672. isKnowKey = TRUE;
  15673. }
  15674. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15675. {
  15676. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15678. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15679. {
  15680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15681. }
  15682. else
  15683. {
  15684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15685. }
  15686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15687. isKnowKey = TRUE;
  15688. }
  15689. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15690. {
  15691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15694. {
  15695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15696. }
  15697. else
  15698. {
  15699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15700. }
  15701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15702. isKnowKey = TRUE;
  15703. }
  15704. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15705. {
  15706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15709. {
  15710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15711. }
  15712. else
  15713. {
  15714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15715. }
  15716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15717. isKnowKey = TRUE;
  15718. }
  15719. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15720. {
  15721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15724. {
  15725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15726. }
  15727. else
  15728. {
  15729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15730. }
  15731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15732. isKnowKey = TRUE;
  15733. }
  15734. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15735. {
  15736. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15739. {
  15740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15741. }
  15742. else
  15743. {
  15744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15745. }
  15746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15747. isKnowKey = TRUE;
  15748. }
  15749. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15750. {
  15751. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15753. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15754. {
  15755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15756. }
  15757. else
  15758. {
  15759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15760. }
  15761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15762. isKnowKey = TRUE;
  15763. }
  15764. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15765. {
  15766. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15768. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15769. {
  15770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15771. }
  15772. else
  15773. {
  15774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15775. }
  15776. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15778. isKnowKey = TRUE;
  15779. }
  15780. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15781. {
  15782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15784. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15785. {
  15786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15787. }
  15788. else
  15789. {
  15790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15791. }
  15792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15793. isKnowKey = TRUE;
  15794. }
  15795. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15796. {
  15797. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15800. {
  15801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15802. }
  15803. else
  15804. {
  15805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15806. }
  15807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15808. isKnowKey = TRUE;
  15809. }
  15810. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15811. {
  15812. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15815. {
  15816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15817. }
  15818. else
  15819. {
  15820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15821. }
  15822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15823. isKnowKey = TRUE;
  15824. }
  15825. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15826. {
  15827. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15829. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15830. {
  15831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15832. }
  15833. else
  15834. {
  15835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15836. }
  15837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15838. isKnowKey = TRUE;
  15839. }
  15840. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15841. {
  15842. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15844. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15845. {
  15846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15847. }
  15848. else
  15849. {
  15850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15851. }
  15852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15853. isKnowKey = TRUE;
  15854. }
  15855. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15856. {
  15857. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15860. {
  15861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15862. }
  15863. else
  15864. {
  15865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15866. }
  15867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15868. isKnowKey = TRUE;
  15869. }
  15870. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15871. {
  15872. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15875. {
  15876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15877. }
  15878. else
  15879. {
  15880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15881. }
  15882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15883. isKnowKey = TRUE;
  15884. }
  15885. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15886. {
  15887. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15890. {
  15891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15892. }
  15893. else
  15894. {
  15895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15896. }
  15897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15898. isKnowKey = TRUE;
  15899. }
  15900. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15901. {
  15902. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15905. {
  15906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15907. }
  15908. else
  15909. {
  15910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15911. }
  15912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15913. isKnowKey = TRUE;
  15914. }
  15915. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15916. {
  15917. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15919. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15920. {
  15921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15922. }
  15923. else
  15924. {
  15925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15926. }
  15927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15928. isKnowKey = TRUE;
  15929. }
  15930. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15931. {
  15932. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15935. {
  15936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15937. }
  15938. else
  15939. {
  15940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15941. }
  15942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15943. isKnowKey = TRUE;
  15944. }
  15945. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15946. {
  15947. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15950. {
  15951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15952. }
  15953. else
  15954. {
  15955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15956. }
  15957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15958. isKnowKey = TRUE;
  15959. }
  15960. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15961. {
  15962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15965. {
  15966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15967. }
  15968. else
  15969. {
  15970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15971. }
  15972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15973. isKnowKey = TRUE;
  15974. }
  15975. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15976. {
  15977. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15980. {
  15981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15982. }
  15983. else
  15984. {
  15985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15986. }
  15987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15988. isKnowKey = TRUE;
  15989. }
  15990. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15991. {
  15992. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15995. {
  15996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15997. }
  15998. else
  15999. {
  16000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  16001. }
  16002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  16003. isKnowKey = TRUE;
  16004. }
  16005. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  16006. {
  16007. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  16008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  16009. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16010. {
  16011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  16012. }
  16013. else
  16014. {
  16015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  16016. }
  16017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  16018. isKnowKey = TRUE;
  16019. }
  16020. /*
  16021. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  16022. {
  16023. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  16024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  16025. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  16026. {
  16027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  16028. }
  16029. else
  16030. {
  16031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  16032. }
  16033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  16034. isKnowKey = TRUE;
  16035. }*/
  16036. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  16037. {
  16038. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  16039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  16040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16041. {
  16042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  16043. }
  16044. else
  16045. {
  16046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  16047. }
  16048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  16049. isKnowKey = TRUE;
  16050. }
  16051. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  16052. {
  16053. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  16054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  16055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  16056. {
  16057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  16058. }
  16059. else
  16060. {
  16061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  16062. }
  16063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  16064. isKnowKey = TRUE;
  16065. }
  16066. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  16067. {
  16068. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  16069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  16070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16071. {
  16072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  16073. }
  16074. else
  16075. {
  16076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  16077. }
  16078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  16079. isKnowKey = TRUE;
  16080. }
  16081. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  16082. {
  16083. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  16084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  16085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16086. {
  16087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  16088. }
  16089. else
  16090. {
  16091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  16092. }
  16093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  16094. isKnowKey = TRUE;
  16095. }
  16096. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  16097. {
  16098. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  16099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  16100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16101. {
  16102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  16103. }
  16104. else
  16105. {
  16106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  16107. }
  16108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  16109. isKnowKey = TRUE;
  16110. }
  16111. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  16112. {
  16113. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  16114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  16115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16116. {
  16117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  16118. }
  16119. else
  16120. {
  16121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  16122. }
  16123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  16124. isKnowKey = TRUE;
  16125. }
  16126. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  16127. {
  16128. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  16129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  16130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  16131. {
  16132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  16133. }
  16134. else
  16135. {
  16136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  16137. }
  16138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  16139. isKnowKey = TRUE;
  16140. }
  16141. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  16142. {
  16143. struct sysinfo s_info;
  16144. int error = sysinfo(&s_info);
  16145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  16146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  16147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  16148. {
  16149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  16150. }
  16151. else
  16152. {
  16153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  16154. }
  16155. if(error != 0)
  16156. {
  16157. DEBUG_WARN("System uptime get error: %d\n", error);
  16158. }
  16159. else
  16160. {
  16161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  16162. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  16163. }
  16164. isKnowKey = TRUE;
  16165. }
  16166. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  16167. {
  16168. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  16169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  16170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16171. {
  16172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  16173. }
  16174. else
  16175. {
  16176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  16177. }
  16178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  16179. isKnowKey = TRUE;
  16180. }
  16181. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  16182. {
  16183. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  16184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  16185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16186. {
  16187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  16188. }
  16189. else
  16190. {
  16191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  16192. }
  16193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16194. isKnowKey = TRUE;
  16195. }
  16196. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  16197. {
  16198. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  16199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  16200. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16201. {
  16202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  16203. }
  16204. else
  16205. {
  16206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  16207. }
  16208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16209. isKnowKey = TRUE;
  16210. }
  16211. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  16212. {
  16213. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  16214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  16215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16216. {
  16217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  16218. }
  16219. else
  16220. {
  16221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  16222. }
  16223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16224. isKnowKey = TRUE;
  16225. }
  16226. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  16227. {
  16228. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  16229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  16230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16231. {
  16232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  16233. }
  16234. else
  16235. {
  16236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  16237. }
  16238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  16239. isKnowKey = TRUE;
  16240. }
  16241. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  16242. {
  16243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  16244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  16245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16246. {
  16247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  16248. }
  16249. else
  16250. {
  16251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  16252. }
  16253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  16254. isKnowKey = TRUE;
  16255. }
  16256. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  16257. {
  16258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  16259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  16260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  16261. {
  16262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  16263. }
  16264. else
  16265. {
  16266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  16267. }
  16268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  16269. isKnowKey = TRUE;
  16270. }
  16271. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  16272. {
  16273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  16274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  16275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16276. {
  16277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  16278. }
  16279. else
  16280. {
  16281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  16282. }
  16283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  16284. isKnowKey = TRUE;
  16285. }
  16286. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  16287. {
  16288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  16289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  16290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16291. {
  16292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  16293. }
  16294. else
  16295. {
  16296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  16297. }
  16298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  16299. isKnowKey = TRUE;
  16300. }
  16301. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  16302. {
  16303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  16304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  16305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16306. {
  16307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  16308. }
  16309. else
  16310. {
  16311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  16312. }
  16313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  16314. isKnowKey = TRUE;
  16315. }
  16316. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16317. {
  16318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16321. {
  16322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16323. }
  16324. else
  16325. {
  16326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16327. }
  16328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16329. isKnowKey = TRUE;
  16330. }
  16331. #if 1
  16332. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16333. {
  16334. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16336. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16337. {
  16338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16339. }
  16340. else
  16341. {
  16342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16343. }
  16344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16345. isKnowKey = TRUE;
  16346. }
  16347. #endif
  16348. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16349. {
  16350. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16352. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16353. {
  16354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16355. }
  16356. else
  16357. {
  16358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16359. }
  16360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16361. isKnowKey = TRUE;
  16362. }
  16363. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16364. {
  16365. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16367. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16368. {
  16369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16370. }
  16371. else
  16372. {
  16373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16374. }
  16375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16376. isKnowKey = TRUE;
  16377. }
  16378. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16379. {
  16380. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16382. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16383. {
  16384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16385. }
  16386. else
  16387. {
  16388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16389. }
  16390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16391. isKnowKey = TRUE;
  16392. }
  16393. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16394. {
  16395. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16397. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16398. {
  16399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16400. }
  16401. else
  16402. {
  16403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16404. }
  16405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16406. isKnowKey = TRUE;
  16407. }
  16408. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16409. {
  16410. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16412. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16413. {
  16414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16415. }
  16416. else
  16417. {
  16418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16419. }
  16420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16421. isKnowKey = TRUE;
  16422. }
  16423. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16424. {
  16425. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16427. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16428. {
  16429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16430. }
  16431. else
  16432. {
  16433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16434. }
  16435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16436. isKnowKey = TRUE;
  16437. }
  16438. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16439. {
  16440. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16442. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16443. {
  16444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16445. }
  16446. else
  16447. {
  16448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16449. }
  16450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16451. isKnowKey = TRUE;
  16452. }
  16453. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16454. {
  16455. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16457. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16458. {
  16459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16460. }
  16461. else
  16462. {
  16463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16464. }
  16465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16466. isKnowKey = TRUE;
  16467. }
  16468. //=========================================================
  16469. if(!isEmpty && !isKnowKey)
  16470. {
  16471. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16472. strcpy(unknownkey[UnknownKeynum], keyReq);
  16473. UnknownKeynum = UnknownKeynum + 1;
  16474. }
  16475. }
  16476. void processUnkownKey(void)
  16477. {
  16478. DEBUG_INFO("processUnkownKey...\n");
  16479. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16480. for(int index=0; index < UnknownKeynum; index++)
  16481. {
  16482. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16483. {
  16484. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16485. }
  16486. }
  16487. }
  16488. int setKeyValue(char *key, char *value)
  16489. {
  16490. int isSuccess = NotSupported;
  16491. int check_ascii=0;
  16492. char str[501]={0};
  16493. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16494. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16495. {
  16496. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16497. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16498. {
  16499. strcpy(str, (const char*)value);
  16500. for(int i = 0; str[i]; i++){
  16501. str[i] = tolower(str[i]);
  16502. }
  16503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16504. isSuccess = ConfigurationStatus_Accepted;
  16505. }
  16506. else
  16507. {
  16508. isSuccess = ConfigurationStatus_Rejected;
  16509. }
  16510. }
  16511. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16512. {
  16513. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16515. {
  16516. strcpy(str, (const char*)value);
  16517. for(int i = 0; str[i]; i++){
  16518. str[i] = tolower(str[i]);
  16519. }
  16520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16521. isSuccess = ConfigurationStatus_Accepted;
  16522. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16523. }
  16524. else
  16525. {
  16526. isSuccess = ConfigurationStatus_Rejected;
  16527. }
  16528. }
  16529. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16530. {
  16531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16532. {
  16533. strcpy(str, (const char*)value);
  16534. for(int i = 0; str[i]; i++)
  16535. {
  16536. str[i] = tolower(str[i]);
  16537. }
  16538. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16540. isSuccess = ConfigurationStatus_Accepted;
  16541. }
  16542. else
  16543. {
  16544. isSuccess = ConfigurationStatus_Rejected;
  16545. }
  16546. }
  16547. if(strcmp(key, "BlinkRepeat") == 0)
  16548. {
  16549. //Charger.BlinkRepeat = Integer.parseInt(value);
  16550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16551. {
  16552. check_ascii = value[0];
  16553. if( (check_ascii < 48) || (check_ascii > 57) )
  16554. {
  16555. isSuccess = ConfigurationStatus_Rejected;
  16556. }
  16557. else
  16558. {
  16559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16560. isSuccess = ConfigurationStatus_Accepted;
  16561. }
  16562. }
  16563. else
  16564. {
  16565. isSuccess = ConfigurationStatus_Rejected;
  16566. }
  16567. }
  16568. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16569. {
  16570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16571. {
  16572. check_ascii = value[0];
  16573. if( (check_ascii < 48) || (check_ascii > 57) )
  16574. {
  16575. isSuccess = ConfigurationStatus_Rejected;
  16576. }
  16577. else
  16578. {
  16579. if((atoi(value) == 0) || (atoi(value) >= 5))
  16580. {
  16581. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16583. isSuccess = ConfigurationStatus_Accepted;
  16584. }
  16585. else
  16586. isSuccess = ConfigurationStatus_Rejected;
  16587. }
  16588. }
  16589. else
  16590. {
  16591. isSuccess = ConfigurationStatus_Rejected;
  16592. }
  16593. }
  16594. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16595. {
  16596. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16597. {
  16598. check_ascii = value[0];
  16599. if( (check_ascii < 48) || (check_ascii > 57) )
  16600. {
  16601. isSuccess = ConfigurationStatus_Rejected;
  16602. }
  16603. else
  16604. {
  16605. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16607. isSuccess = ConfigurationStatus_Accepted;
  16608. }
  16609. }
  16610. else
  16611. {
  16612. isSuccess = ConfigurationStatus_Rejected;
  16613. }
  16614. }
  16615. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16616. {
  16617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16618. {
  16619. check_ascii = value[0];
  16620. if( (check_ascii < 48) || (check_ascii > 57) )
  16621. {
  16622. isSuccess = ConfigurationStatus_Rejected;
  16623. }
  16624. else
  16625. {
  16626. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16628. isSuccess = ConfigurationStatus_Accepted;
  16629. }
  16630. }
  16631. else
  16632. {
  16633. isSuccess = ConfigurationStatus_Rejected;
  16634. }
  16635. }
  16636. if(strcmp(key, "HeartbeatInterval") == 0)
  16637. {
  16638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16639. {
  16640. check_ascii = value[0];
  16641. if( (check_ascii < 48) || (check_ascii > 57) )
  16642. {
  16643. isSuccess = ConfigurationStatus_Rejected;
  16644. }
  16645. else
  16646. {
  16647. if((atoi(value) == 0) || (atoi(value) >= 10))
  16648. {
  16649. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16651. HeartBeatWaitTime = atoi(value);
  16652. isSuccess = ConfigurationStatus_Accepted;
  16653. }
  16654. else
  16655. {
  16656. isSuccess = ConfigurationStatus_Rejected;
  16657. }
  16658. }
  16659. }
  16660. else
  16661. {
  16662. isSuccess = ConfigurationStatus_Rejected;
  16663. }
  16664. }
  16665. if(strcmp(key, "LightIntensity") == 0)
  16666. {
  16667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16668. {
  16669. check_ascii = value[0];
  16670. if( (check_ascii < 48) || (check_ascii > 57) )
  16671. {
  16672. isSuccess = ConfigurationStatus_Rejected;
  16673. }
  16674. else
  16675. {
  16676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16677. isSuccess = ConfigurationStatus_Accepted;
  16678. }
  16679. }
  16680. else
  16681. {
  16682. isSuccess = ConfigurationStatus_Rejected;
  16683. }
  16684. }
  16685. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16686. {
  16687. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16688. {
  16689. strcpy(str, (const char*)value);
  16690. for(int i = 0; str[i]; i++)
  16691. {
  16692. str[i] = tolower(str[i]);
  16693. }
  16694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16695. isSuccess = ConfigurationStatus_Accepted;
  16696. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16697. }
  16698. else
  16699. {
  16700. isSuccess = ConfigurationStatus_Rejected;
  16701. }
  16702. }
  16703. if(strcmp(key, "LocalPreAuthorize") == 0)
  16704. {
  16705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16706. {
  16707. strcpy(str, (const char*)value);
  16708. for(int i = 0; str[i]; i++)
  16709. {
  16710. str[i] = tolower(str[i]);
  16711. }
  16712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16713. isSuccess = ConfigurationStatus_Accepted;
  16714. }
  16715. else
  16716. {
  16717. isSuccess = ConfigurationStatus_Rejected;
  16718. }
  16719. }
  16720. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16721. {
  16722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16723. {
  16724. check_ascii = value[0];
  16725. if( (check_ascii < 48) || (check_ascii > 57) )
  16726. {
  16727. isSuccess = ConfigurationStatus_Rejected;
  16728. }
  16729. else
  16730. {
  16731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16732. isSuccess = ConfigurationStatus_Accepted;
  16733. }
  16734. }
  16735. else
  16736. {
  16737. isSuccess = ConfigurationStatus_Rejected;
  16738. }
  16739. }
  16740. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16741. {
  16742. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16743. {
  16744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16745. isSuccess = ConfigurationStatus_Accepted;
  16746. }
  16747. else
  16748. {
  16749. isSuccess = ConfigurationStatus_Rejected;
  16750. }
  16751. }
  16752. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16753. {
  16754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16755. {
  16756. check_ascii = value[0];
  16757. if( (check_ascii < 48) || (check_ascii > 57) )
  16758. {
  16759. isSuccess = ConfigurationStatus_Rejected;
  16760. }
  16761. else
  16762. {
  16763. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16765. isSuccess = ConfigurationStatus_Accepted;
  16766. }
  16767. }
  16768. else
  16769. {
  16770. isSuccess = ConfigurationStatus_Rejected;
  16771. }
  16772. }
  16773. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16774. {
  16775. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16776. {
  16777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16778. isSuccess = ConfigurationStatus_Accepted;
  16779. }
  16780. else
  16781. {
  16782. isSuccess = ConfigurationStatus_Rejected;
  16783. }
  16784. }
  16785. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16786. {
  16787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16788. {
  16789. check_ascii = value[0];
  16790. if( (check_ascii < 48) || (check_ascii > 57) )
  16791. {
  16792. isSuccess = ConfigurationStatus_Rejected;
  16793. }
  16794. else
  16795. {
  16796. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16798. isSuccess = ConfigurationStatus_Accepted;
  16799. }
  16800. }
  16801. else
  16802. {
  16803. isSuccess = ConfigurationStatus_Rejected;
  16804. }
  16805. }
  16806. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16807. {
  16808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16809. {
  16810. check_ascii = value[0];
  16811. if( (check_ascii < 48) || (check_ascii > 57) )
  16812. {
  16813. isSuccess = ConfigurationStatus_Rejected;
  16814. }
  16815. else
  16816. {
  16817. if((atoi(value) == 0) || (atoi(value) >= 3))
  16818. {
  16819. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16821. isSuccess = ConfigurationStatus_Accepted;
  16822. }
  16823. else
  16824. {
  16825. isSuccess = ConfigurationStatus_Rejected;
  16826. }
  16827. }
  16828. }
  16829. else
  16830. {
  16831. isSuccess = ConfigurationStatus_Rejected;
  16832. }
  16833. }
  16834. if(strcmp(key, "MinimumStatusDuration") == 0)
  16835. {
  16836. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16837. {
  16838. check_ascii = value[0];
  16839. if( (check_ascii < 48) || (check_ascii > 57) )
  16840. {
  16841. isSuccess = ConfigurationStatus_Rejected;
  16842. }
  16843. else
  16844. {
  16845. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16846. {
  16847. isSuccess = ConfigurationStatus_Rejected;
  16848. }
  16849. else
  16850. {
  16851. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16853. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16854. isSuccess = ConfigurationStatus_Accepted;
  16855. }
  16856. }
  16857. }
  16858. else
  16859. {
  16860. isSuccess = ConfigurationStatus_Rejected;
  16861. }
  16862. }
  16863. if(strcmp(key, "NumberOfConnectors") == 0)
  16864. {
  16865. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16866. {
  16867. check_ascii = value[0];
  16868. if( (check_ascii < 48) || (check_ascii > 57) )
  16869. {
  16870. isSuccess = ConfigurationStatus_Rejected;
  16871. }
  16872. else
  16873. {
  16874. //Charger.ResetRetries = Integer.parseInt(value);
  16875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16876. isSuccess = ConfigurationStatus_Accepted;
  16877. }
  16878. }
  16879. else
  16880. {
  16881. isSuccess = ConfigurationStatus_Rejected;
  16882. }
  16883. }
  16884. if(strcmp(key, "ResetRetries") == 0)
  16885. {
  16886. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16887. {
  16888. check_ascii = value[0];
  16889. if( (check_ascii < 48) || (check_ascii > 57) )
  16890. {
  16891. isSuccess = ConfigurationStatus_Rejected;
  16892. }
  16893. else
  16894. {
  16895. //Charger.ResetRetries = Integer.parseInt(value);
  16896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16897. isSuccess = ConfigurationStatus_Accepted;
  16898. }
  16899. }
  16900. else
  16901. {
  16902. isSuccess = ConfigurationStatus_Rejected;
  16903. }
  16904. }
  16905. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16906. {
  16907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16908. {
  16909. strcpy(str, (const char*)value);
  16910. for(int i = 0; str[i]; i++)
  16911. {
  16912. str[i] = tolower(str[i]);
  16913. }
  16914. if(strcmp(str, "notapplicable")== 0)
  16915. {
  16916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16917. isSuccess = ConfigurationStatus_Accepted;
  16918. }
  16919. else if(strcmp(str, "unknown")== 0)
  16920. {
  16921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16922. isSuccess = ConfigurationStatus_Accepted;
  16923. }
  16924. else if(strcmp(str, "rst")== 0)
  16925. {
  16926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16927. isSuccess = ConfigurationStatus_Accepted;
  16928. }
  16929. else if(strcmp(str, "rts")== 0)
  16930. {
  16931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16932. isSuccess = ConfigurationStatus_Accepted;
  16933. }
  16934. else if(strcmp(str, "srt")== 0)
  16935. {
  16936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16937. isSuccess = ConfigurationStatus_Accepted;
  16938. }
  16939. else if(strcmp(str, "str")== 0)
  16940. {
  16941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16942. isSuccess = ConfigurationStatus_Accepted;
  16943. }
  16944. else if(strcmp(str, "trs")== 0)
  16945. {
  16946. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16947. isSuccess = ConfigurationStatus_Accepted;
  16948. }
  16949. else if(strcmp(str, "tsr")== 0)
  16950. {
  16951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16952. isSuccess = ConfigurationStatus_Accepted;
  16953. }
  16954. else
  16955. {
  16956. isSuccess = ConfigurationStatus_Rejected;
  16957. }
  16958. }
  16959. else
  16960. {
  16961. isSuccess = ConfigurationStatus_Rejected;
  16962. }
  16963. }
  16964. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16965. {
  16966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16967. {
  16968. check_ascii = value[0];
  16969. if( (check_ascii < 48) || (check_ascii > 57) )
  16970. {
  16971. isSuccess = ConfigurationStatus_Rejected;
  16972. }
  16973. else
  16974. {
  16975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16976. isSuccess = ConfigurationStatus_Accepted;
  16977. }
  16978. }
  16979. else
  16980. {
  16981. isSuccess = ConfigurationStatus_Rejected;
  16982. }
  16983. }
  16984. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16985. {
  16986. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16987. {
  16988. strcpy(str, (const char*)value);
  16989. for(int i = 0; str[i]; i++)
  16990. {
  16991. str[i] = tolower(str[i]);
  16992. }
  16993. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16995. isSuccess = ConfigurationStatus_Accepted;
  16996. }
  16997. else
  16998. {
  16999. isSuccess = ConfigurationStatus_Rejected;
  17000. }
  17001. }
  17002. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  17003. {
  17004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17005. {
  17006. strcpy(str, (const char*)value);
  17007. for(int i = 0; str[i]; i++)
  17008. {
  17009. str[i] = tolower(str[i]);
  17010. }
  17011. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  17012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17013. isSuccess = ConfigurationStatus_Accepted;
  17014. }
  17015. else
  17016. {
  17017. isSuccess = ConfigurationStatus_Rejected;
  17018. }
  17019. }
  17020. if(strcmp(key, "StopTxnAlignedData") == 0)
  17021. {
  17022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17023. {
  17024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  17025. isSuccess = ConfigurationStatus_Accepted;
  17026. }
  17027. else
  17028. {
  17029. isSuccess = ConfigurationStatus_Rejected;
  17030. }
  17031. }
  17032. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  17033. {
  17034. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17035. {
  17036. check_ascii = value[0];
  17037. if( (check_ascii < 48) || (check_ascii > 57) )
  17038. {
  17039. isSuccess = ConfigurationStatus_Rejected;
  17040. }
  17041. else
  17042. {
  17043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  17044. isSuccess = ConfigurationStatus_Accepted;
  17045. }
  17046. }
  17047. else
  17048. {
  17049. isSuccess = ConfigurationStatus_Rejected;
  17050. }
  17051. }
  17052. if(strcmp(key, "StopTxnSampledData") == 0)
  17053. {
  17054. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17055. {
  17056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  17057. isSuccess = ConfigurationStatus_Accepted;
  17058. }
  17059. else
  17060. {
  17061. isSuccess = ConfigurationStatus_Rejected;
  17062. }
  17063. }
  17064. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  17065. {
  17066. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17067. {
  17068. check_ascii = value[0];
  17069. if( (check_ascii < 48) || (check_ascii > 57) )
  17070. {
  17071. isSuccess = ConfigurationStatus_Rejected;
  17072. }
  17073. else
  17074. {
  17075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  17076. isSuccess = ConfigurationStatus_Accepted;
  17077. }
  17078. }
  17079. else
  17080. {
  17081. isSuccess = ConfigurationStatus_Rejected;
  17082. }
  17083. }
  17084. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  17085. {
  17086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17087. {
  17088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  17089. isSuccess = ConfigurationStatus_Accepted;
  17090. }
  17091. else
  17092. {
  17093. isSuccess = ConfigurationStatus_Rejected;
  17094. }
  17095. }
  17096. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  17097. {
  17098. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17099. {
  17100. check_ascii = value[0];
  17101. if( (check_ascii < 48) || (check_ascii > 57) )
  17102. {
  17103. isSuccess = ConfigurationStatus_Rejected;
  17104. }
  17105. else
  17106. {
  17107. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  17108. isSuccess = ConfigurationStatus_Accepted;
  17109. }
  17110. }
  17111. else
  17112. {
  17113. isSuccess = ConfigurationStatus_Rejected;
  17114. }
  17115. }
  17116. if(strcmp(key, "TransactionMessageAttempts") == 0)
  17117. {
  17118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17119. {
  17120. check_ascii = value[0];
  17121. if( (check_ascii < 48) || (check_ascii > 57) )
  17122. {
  17123. isSuccess = ConfigurationStatus_Rejected;
  17124. }
  17125. else
  17126. {
  17127. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  17128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  17129. TransactionMessageAttemptsValue = atoi(value);
  17130. isSuccess = ConfigurationStatus_Accepted;
  17131. }
  17132. }
  17133. else
  17134. {
  17135. isSuccess = ConfigurationStatus_Rejected;
  17136. }
  17137. }
  17138. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  17139. {
  17140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17141. {
  17142. check_ascii = value[0];
  17143. if( (check_ascii < 48) || (check_ascii > 57) )
  17144. {
  17145. isSuccess = ConfigurationStatus_Rejected;
  17146. }
  17147. else
  17148. {
  17149. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  17150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  17151. TransactionMessageRetryIntervalValue = atoi(value);
  17152. isSuccess = ConfigurationStatus_Accepted;
  17153. }
  17154. }
  17155. else
  17156. {
  17157. isSuccess = ConfigurationStatus_Rejected;
  17158. }
  17159. }
  17160. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  17161. {
  17162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17163. {
  17164. strcpy(str, (const char*)value);
  17165. for(int i = 0; str[i]; i++)
  17166. {
  17167. str[i] = tolower(str[i]);
  17168. }
  17169. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  17170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17171. isSuccess = ConfigurationStatus_Accepted;
  17172. }
  17173. else
  17174. {
  17175. isSuccess = ConfigurationStatus_Rejected;
  17176. }
  17177. }
  17178. if(strcmp(key, "WebSocketPingInterval") == 0)
  17179. {
  17180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17181. {
  17182. check_ascii = value[0];
  17183. if( (check_ascii < 48) || (check_ascii > 57) )
  17184. {
  17185. isSuccess = ConfigurationStatus_Rejected;
  17186. }
  17187. else
  17188. {
  17189. if((atoi(value) == 0) || (atoi(value) >= 10))
  17190. {
  17191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  17192. isSuccess = ConfigurationStatus_Accepted;
  17193. }
  17194. else
  17195. isSuccess = ConfigurationStatus_Rejected;
  17196. }
  17197. }
  17198. else
  17199. {
  17200. isSuccess = ConfigurationStatus_Rejected;
  17201. }
  17202. }
  17203. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  17204. {
  17205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17206. {
  17207. strcpy(str, (const char*)value);
  17208. for(int i = 0; str[i]; i++)
  17209. {
  17210. str[i] = tolower(str[i]);
  17211. }
  17212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17213. isSuccess = ConfigurationStatus_Accepted;
  17214. }
  17215. else
  17216. {
  17217. isSuccess = ConfigurationStatus_Rejected;
  17218. }
  17219. }
  17220. if(strcmp(key, "AuthorizationKey") == 0)
  17221. {
  17222. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  17223. {
  17224. strcpy(str, (const char*)value);
  17225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  17226. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17227. isSuccess = ConfigurationStatus_Accepted;
  17228. }
  17229. else
  17230. {
  17231. isSuccess = ConfigurationStatus_Rejected;
  17232. }
  17233. }
  17234. if(strcmp(key, "SecurityProfile") == 0)
  17235. {
  17236. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17237. {
  17238. check_ascii = value[0];
  17239. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  17240. {
  17241. isSuccess = ConfigurationStatus_Rejected;
  17242. }
  17243. else if(check_ascii == 0x33)
  17244. {
  17245. isSuccess = NotSupported;
  17246. }
  17247. else
  17248. {
  17249. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  17250. {
  17251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  17252. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  17253. isSuccess = ConfigurationStatus_Accepted;
  17254. }
  17255. else
  17256. isSuccess = ConfigurationStatus_Rejected;
  17257. }
  17258. }
  17259. else
  17260. {
  17261. isSuccess = ConfigurationStatus_Rejected;
  17262. }
  17263. }
  17264. if(strcmp(key, "DefaultPrice") == 0)
  17265. {
  17266. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  17267. {
  17268. strcpy(str, (const char*)value);
  17269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  17270. isSuccess = ConfigurationStatus_Accepted;
  17271. }
  17272. else
  17273. {
  17274. isSuccess = ConfigurationStatus_Rejected;
  17275. }
  17276. }
  17277. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  17278. {
  17279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17280. {
  17281. strcpy(str, (const char*)value);
  17282. for(int i = 0; str[i]; i++)
  17283. {
  17284. str[i] = tolower(str[i]);
  17285. }
  17286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17287. isSuccess = ConfigurationStatus_Accepted;
  17288. }
  17289. else
  17290. {
  17291. isSuccess = ConfigurationStatus_Rejected;
  17292. }
  17293. }
  17294. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  17295. {
  17296. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17297. {
  17298. strcpy(str, (const char*)value);
  17299. for(int i = 0; str[i]; i++)
  17300. {
  17301. str[i] = tolower(str[i]);
  17302. }
  17303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17304. isSuccess = ConfigurationStatus_Accepted;
  17305. }
  17306. else
  17307. {
  17308. isSuccess = ConfigurationStatus_Rejected;
  17309. }
  17310. }
  17311. if(strcmp(key, "TimeOffset") == 0)
  17312. {
  17313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17314. {
  17315. strcpy(str, (const char*)value);
  17316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  17317. isSuccess = ConfigurationStatus_Accepted;
  17318. }
  17319. else
  17320. {
  17321. isSuccess = ConfigurationStatus_Rejected;
  17322. }
  17323. }
  17324. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  17325. {
  17326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17327. {
  17328. strcpy(str, (const char*)value);
  17329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17330. isSuccess = ConfigurationStatus_Accepted;
  17331. }
  17332. else
  17333. {
  17334. isSuccess = ConfigurationStatus_Rejected;
  17335. }
  17336. }
  17337. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17338. {
  17339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17340. {
  17341. strcpy(str, (const char*)value);
  17342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17343. isSuccess = ConfigurationStatus_Accepted;
  17344. }
  17345. else
  17346. {
  17347. isSuccess = ConfigurationStatus_Rejected;
  17348. }
  17349. }
  17350. if(strcmp(key, "SystemUptimeSec") == 0)
  17351. {
  17352. isSuccess = NotSupported;
  17353. }
  17354. if(strcmp(key, "FreeVend") == 0)
  17355. {
  17356. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17357. {
  17358. strcpy(str, (const char*)value);
  17359. for(int i = 0; str[i]; i++)
  17360. {
  17361. str[i] = tolower(str[i]);
  17362. }
  17363. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17365. isSuccess = ConfigurationStatus_Accepted;
  17366. }
  17367. else
  17368. {
  17369. isSuccess = ConfigurationStatus_Rejected;
  17370. }
  17371. }
  17372. if(strcmp(key, "FreeVendIdtag") == 0)
  17373. {
  17374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17375. {
  17376. strcpy(str, (const char*)value);
  17377. if(strlen(str) <= 20)
  17378. {
  17379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17380. isSuccess = ConfigurationStatus_Accepted;
  17381. }
  17382. else
  17383. {
  17384. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17385. isSuccess = ConfigurationStatus_Rejected;
  17386. }
  17387. }
  17388. else
  17389. {
  17390. isSuccess = ConfigurationStatus_Rejected;
  17391. }
  17392. }
  17393. if(strcmp(key, "OcppServer") == 0)
  17394. {
  17395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17396. {
  17397. strcpy(str, (const char*)value);
  17398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17399. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17400. isSuccess = ConfigurationStatus_Accepted;
  17401. }
  17402. else
  17403. {
  17404. isSuccess = ConfigurationStatus_Rejected;
  17405. }
  17406. }
  17407. if(strcmp(key, "MaintainServer") == 0)
  17408. {
  17409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17410. {
  17411. strcpy(str, (const char*)value);
  17412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17413. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17414. isSuccess = ConfigurationStatus_Accepted;
  17415. }
  17416. else
  17417. {
  17418. isSuccess = ConfigurationStatus_Rejected;
  17419. }
  17420. }
  17421. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17422. {
  17423. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17424. {
  17425. strcpy(str, (const char*)value);
  17426. for(int i = 0; str[i]; i++)
  17427. {
  17428. str[i] = tolower(str[i]);
  17429. }
  17430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17431. isSuccess = ConfigurationStatus_Accepted;
  17432. }
  17433. else
  17434. {
  17435. isSuccess = ConfigurationStatus_Rejected;
  17436. }
  17437. }
  17438. if(strcmp(key, "StatusNotificationInterval") == 0)
  17439. {
  17440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17441. {
  17442. check_ascii = value[0];
  17443. if( (check_ascii < 48) || (check_ascii > 57) )
  17444. {
  17445. isSuccess = ConfigurationStatus_Rejected;
  17446. }
  17447. else
  17448. {
  17449. if((atoi(value) == 0) || (atoi(value) >= 10))
  17450. {
  17451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17452. isSuccess = ConfigurationStatus_Accepted;
  17453. }
  17454. else
  17455. isSuccess = ConfigurationStatus_Rejected;
  17456. }
  17457. }
  17458. else
  17459. {
  17460. isSuccess = ConfigurationStatus_Rejected;
  17461. }
  17462. }
  17463. if(strcmp(key, "PreAuthAmount") == 0)
  17464. {
  17465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17466. {
  17467. check_ascii = value[0];
  17468. if( (check_ascii < 48) || (check_ascii > 57) )
  17469. {
  17470. isSuccess = ConfigurationStatus_Rejected;
  17471. }
  17472. else
  17473. {
  17474. if(atof(value) >= 0)
  17475. {
  17476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17477. isSuccess = ConfigurationStatus_Accepted;
  17478. }
  17479. else
  17480. isSuccess = ConfigurationStatus_Rejected;
  17481. }
  17482. }
  17483. else
  17484. {
  17485. isSuccess = ConfigurationStatus_Rejected;
  17486. }
  17487. }
  17488. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17489. {
  17490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17491. {
  17492. check_ascii = value[0];
  17493. if( (check_ascii < 48) || (check_ascii > 57) )
  17494. {
  17495. isSuccess = ConfigurationStatus_Rejected;
  17496. }
  17497. else
  17498. {
  17499. if(atoi(value) >= 0)
  17500. {
  17501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  17502. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17503. isSuccess = ConfigurationStatus_Accepted;
  17504. }
  17505. else
  17506. isSuccess = ConfigurationStatus_Rejected;
  17507. }
  17508. }
  17509. else
  17510. {
  17511. isSuccess = ConfigurationStatus_Rejected;
  17512. }
  17513. }
  17514. if(strcmp(key, "PowerSharingServerIP") == 0)
  17515. {
  17516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17517. {
  17518. strcpy(str, (const char*)value);
  17519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17520. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17521. isSuccess = ConfigurationStatus_Accepted;
  17522. }
  17523. else
  17524. {
  17525. isSuccess = ConfigurationStatus_Rejected;
  17526. }
  17527. }
  17528. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17529. {
  17530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17531. {
  17532. strcpy(str, (const char*)value);
  17533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17534. isSuccess = ConfigurationStatus_Accepted;
  17535. }
  17536. else
  17537. {
  17538. isSuccess = ConfigurationStatus_Rejected;
  17539. }
  17540. }
  17541. #if 0
  17542. //For OCPP Test Case
  17543. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17544. {
  17545. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17546. {
  17547. strcpy(str, (const char*)value);
  17548. for(int i = 0; str[i]; i++)
  17549. {
  17550. str[i] = tolower(str[i]);
  17551. }
  17552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17553. isSuccess = ConfigurationStatus_Accepted;
  17554. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17555. }
  17556. else
  17557. {
  17558. isSuccess = ConfigurationStatus_Rejected;
  17559. }
  17560. }
  17561. #endif
  17562. #if 1
  17563. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17564. {
  17565. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17566. {
  17567. strcpy(str, (const char*)value);
  17568. for(int i = 0; str[i]; i++)
  17569. {
  17570. str[i] = tolower(str[i]);
  17571. }
  17572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17573. isSuccess = ConfigurationStatus_Accepted;
  17574. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17575. }
  17576. else
  17577. {
  17578. isSuccess = ConfigurationStatus_Rejected;
  17579. }
  17580. }
  17581. #endif
  17582. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17583. {
  17584. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17585. {
  17586. check_ascii = value[0];
  17587. if( (check_ascii < 48) || (check_ascii > 57) )
  17588. {
  17589. isSuccess = ConfigurationStatus_Rejected;
  17590. }
  17591. else
  17592. {
  17593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17594. isSuccess = ConfigurationStatus_Accepted;
  17595. }
  17596. }
  17597. else
  17598. {
  17599. isSuccess = ConfigurationStatus_Rejected;
  17600. }
  17601. }
  17602. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17603. {
  17604. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17605. {
  17606. check_ascii = value[0];
  17607. if( (check_ascii < 48) || (check_ascii > 57) )
  17608. {
  17609. isSuccess = ConfigurationStatus_Rejected;
  17610. }
  17611. else
  17612. {
  17613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17614. isSuccess = ConfigurationStatus_Accepted;
  17615. }
  17616. }
  17617. else
  17618. {
  17619. isSuccess = ConfigurationStatus_Rejected;
  17620. }
  17621. }
  17622. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17623. {
  17624. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17625. {
  17626. strcpy(str, (const char*)value);
  17627. for(int i = 0; str[i]; i++)
  17628. {
  17629. str[i] = tolower(str[i]);
  17630. }
  17631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17632. isSuccess = ConfigurationStatus_Accepted;
  17633. }
  17634. else
  17635. {
  17636. isSuccess = ConfigurationStatus_Rejected;
  17637. }
  17638. }
  17639. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17640. {
  17641. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17642. {
  17643. check_ascii = value[0];
  17644. if( (check_ascii < 48) || (check_ascii > 57) )
  17645. {
  17646. isSuccess = ConfigurationStatus_Rejected;
  17647. }
  17648. else
  17649. {
  17650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17651. isSuccess = ConfigurationStatus_Accepted;
  17652. }
  17653. }
  17654. else
  17655. {
  17656. isSuccess = ConfigurationStatus_Rejected;
  17657. }
  17658. }
  17659. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17660. {
  17661. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17662. {
  17663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17664. isSuccess = ConfigurationStatus_Accepted;
  17665. }
  17666. else
  17667. {
  17668. isSuccess = ConfigurationStatus_Rejected;
  17669. }
  17670. }
  17671. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17672. {
  17673. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17674. {
  17675. check_ascii = value[0];
  17676. if( (check_ascii < 48) || (check_ascii > 57) )
  17677. {
  17678. isSuccess = ConfigurationStatus_Rejected;
  17679. }
  17680. else
  17681. {
  17682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17683. isSuccess = ConfigurationStatus_Accepted;
  17684. }
  17685. }
  17686. else
  17687. {
  17688. isSuccess = ConfigurationStatus_Rejected;
  17689. }
  17690. }
  17691. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17692. {
  17693. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17694. {
  17695. strcpy(str, (const char*)value);
  17696. for(int i = 0; str[i]; i++)
  17697. {
  17698. str[i] = tolower(str[i]);
  17699. }
  17700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17701. isSuccess = ConfigurationStatus_Accepted;
  17702. }
  17703. else
  17704. {
  17705. isSuccess = ConfigurationStatus_Rejected;
  17706. }
  17707. }
  17708. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17709. {
  17710. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17711. {
  17712. check_ascii = value[0];
  17713. if( (check_ascii < 48) || (check_ascii > 57) )
  17714. {
  17715. isSuccess = ConfigurationStatus_Rejected;
  17716. }
  17717. else
  17718. {
  17719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17720. isSuccess = ConfigurationStatus_Accepted;
  17721. }
  17722. }
  17723. else
  17724. {
  17725. isSuccess = ConfigurationStatus_Rejected;
  17726. }
  17727. }
  17728. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17729. return isSuccess;
  17730. }
  17731. int TransactionMessageAttemptsGet(void)
  17732. {
  17733. return TransactionMessageAttemptsValue;
  17734. }
  17735. int FirstHeartBeatResponse(void)
  17736. {
  17737. return FirstHeartBeat;
  17738. }
  17739. int TransactionMessageRetryIntervalGet(void)
  17740. {
  17741. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17742. }
  17743. int ReadHttpStatus(int sock)
  17744. {
  17745. //char c;
  17746. char buff[1024]="",*ptr=buff+1;
  17747. int bytes_received, status;
  17748. DEBUG_INFO("Begin Response ..\n");
  17749. while((bytes_received = recv(sock, ptr, 1, 0))){
  17750. if(bytes_received==-1){
  17751. perror("ReadHttpStatus");
  17752. exit(1);
  17753. }
  17754. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17755. ptr++;
  17756. }
  17757. *ptr=0;
  17758. ptr=buff+1;
  17759. sscanf(ptr,"%*s %d ", &status);
  17760. DEBUG_INFO("%s\n",ptr);
  17761. DEBUG_INFO("status=%d\n",status);
  17762. DEBUG_INFO("End Response ..\n");
  17763. return (bytes_received>0)?status:0;
  17764. }
  17765. //the only filed that it parsed is 'Content-Length'
  17766. int ParseHeader(int sock)
  17767. {
  17768. //char c;
  17769. char buff[1024]="",*ptr=buff+4;
  17770. int bytes_received;
  17771. DEBUG_INFO("Begin HEADER ..\n");
  17772. while((bytes_received = recv(sock, ptr, 1, 0))){
  17773. if(bytes_received==-1){
  17774. perror("Parse Header");
  17775. exit(1);
  17776. }
  17777. if(
  17778. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17779. (ptr[-1]=='\r') && (*ptr=='\n' )
  17780. ) break;
  17781. ptr++;
  17782. }
  17783. *ptr=0;
  17784. ptr=buff+4;
  17785. //printf("%s",ptr);
  17786. if(bytes_received){
  17787. ptr=strstr(ptr,"Content-Length:");
  17788. if(ptr){
  17789. sscanf(ptr,"%*s %d",&bytes_received);
  17790. }else
  17791. bytes_received=-1; //unknown size
  17792. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17793. }
  17794. DEBUG_INFO("End HEADER ..\n");
  17795. return bytes_received ;
  17796. }
  17797. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17798. {
  17799. int result = TRUE;
  17800. char rmFileCmd[100]={0};
  17801. char FilePath[100]={0};
  17802. char ftpbuf[200];
  17803. int systemresult;
  17804. sprintf(FilePath,"/mnt/%s",filename);
  17805. system("ping 8.8.8.8 &");
  17806. if((access(FilePath,F_OK))!=-1)
  17807. {
  17808. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17809. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17810. system(rmFileCmd);
  17811. }
  17812. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17813. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17814. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17815. systemresult = system(ftpbuf);
  17816. if(systemresult != 0)
  17817. {
  17818. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17819. result = FALSE;
  17820. }
  17821. system("pkill ping");
  17822. return result;
  17823. }
  17824. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  17825. {
  17826. int result = TRUE;
  17827. char rmFileCmd[100]={0};
  17828. char FilePath[100]={0};
  17829. char ftpbuf[200];
  17830. int systemresult;
  17831. sprintf(FilePath,"/mnt/%s",filename);
  17832. system("ping 8.8.8.8 &");
  17833. if((access(FilePath,F_OK))!=-1)
  17834. {
  17835. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17836. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17837. system(rmFileCmd);
  17838. }
  17839. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17840. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  17841. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17842. systemresult = system(ftpbuf);
  17843. if(systemresult != 0)
  17844. {
  17845. DEBUG_WARN("scp error!\n");
  17846. result = FALSE;
  17847. }
  17848. system("pkill ping");
  17849. return result;
  17850. }
  17851. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17852. {
  17853. int result = TRUE;
  17854. char rmFileCmd[100]={0};
  17855. char FilePath[100]={0};
  17856. char ftpbuf[200];
  17857. int systemresult;
  17858. sprintf(FilePath,"/mnt/%s",filename);
  17859. system("ping 8.8.8.8 &");
  17860. if((access(FilePath,F_OK))!=-1)
  17861. {
  17862. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17863. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17864. system(rmFileCmd);
  17865. }
  17866. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17867. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17868. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17869. systemresult = system(ftpbuf);
  17870. if(systemresult != 0)
  17871. {
  17872. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17873. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17874. systemresult = system(ftpbuf);
  17875. if(systemresult != 0)
  17876. {
  17877. DEBUG_WARN("FTP download fail!\n");
  17878. result = FALSE;
  17879. }
  17880. }
  17881. system("pkill ping");
  17882. return result;
  17883. }
  17884. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17885. {
  17886. char rmFileCmd[100]={0};
  17887. char FilePath[100]={0};
  17888. char buf[512];
  17889. int systemresult = 0;
  17890. //DEBUG_INFO("filename=%s\n",filename);
  17891. //DEBUG_INFO("url=%s\n",url);
  17892. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17893. if((access(FilePath,F_OK))!=-1)
  17894. {
  17895. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17896. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17897. system(rmFileCmd);
  17898. }
  17899. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17900. if(fp == NULL)
  17901. {
  17902. DEBUG_INFO("log is NULL\n");
  17903. return FALSE;
  17904. }
  17905. else
  17906. {
  17907. fprintf(fp, "%s\n", url);
  17908. fprintf(fp, "%s\n", filename);
  17909. fclose(fp);
  17910. }
  17911. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17912. if(phpFP == NULL)
  17913. {
  17914. DEBUG_INFO("PHP upload fail.\n");
  17915. return FALSE;
  17916. }
  17917. else
  17918. {
  17919. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17920. {
  17921. if(strstr(buf, "result") != NULL)
  17922. {
  17923. sscanf(buf, "result: %d", &systemresult);
  17924. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17925. }
  17926. }
  17927. pclose(phpFP);
  17928. }
  17929. if(systemresult != 1)
  17930. {
  17931. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17932. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17933. if(phpFP == NULL)
  17934. {
  17935. DEBUG_WARN("PHP PUT upload fail.\n");
  17936. return FALSE;
  17937. }
  17938. else
  17939. {
  17940. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17941. {
  17942. if(strstr(buf, "result") != NULL)
  17943. {
  17944. sscanf(buf, "result: %d", &systemresult);
  17945. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17946. }
  17947. }
  17948. pclose(phpFP);
  17949. }
  17950. }
  17951. if(systemresult != 1)
  17952. {
  17953. DEBUG_WARN("PHP PUT upload fail.\n");
  17954. return FALSE;
  17955. }
  17956. return TRUE;
  17957. }
  17958. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17959. {
  17960. int result = FALSE;
  17961. char ftpbuf[200];
  17962. int systemresult;
  17963. /*
  17964. // Domaind name transfer to IP address
  17965. struct hostent* server;
  17966. char *IPbuffer;
  17967. server = gethostbyname(location);
  17968. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17969. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17970. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17971. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17972. systemresult = system(ftpbuf);
  17973. if(systemresult != 0)
  17974. {
  17975. DEBUG_INFO("ftpput error!\n");
  17976. }
  17977. else
  17978. {
  17979. result = TRUE;
  17980. DEBUG_INFO("ftpput OK!\n");
  17981. }
  17982. return result;
  17983. }
  17984. int GetOcppServerURL()
  17985. {
  17986. int result = FALSE;
  17987. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17988. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17989. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17990. struct yuarel url;
  17991. char urlStr[512];
  17992. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17993. {
  17994. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17995. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17996. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17997. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17998. if(yuarel_parse(&url, urlStr) != -1)
  17999. {
  18000. sprintf(OcppProtocol, "%s", url.scheme);
  18001. sprintf(OcppHost, "%s", url.host);
  18002. if(url.path == NULL)
  18003. OcppTempPath[0] = '\0';
  18004. else
  18005. {
  18006. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  18007. {
  18008. sprintf(OcppTempPath, "%s/", url.path);
  18009. }
  18010. else
  18011. {
  18012. sprintf(OcppTempPath, "%s", url.path);
  18013. }
  18014. }
  18015. if(url.port == 0)
  18016. {
  18017. if(strcmp(OcppProtocol, "wss") == 0)
  18018. OcppPort = 443;
  18019. else
  18020. OcppPort = 80;
  18021. }
  18022. else
  18023. OcppPort = url.port;
  18024. result = TRUE;
  18025. }
  18026. }
  18027. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  18028. {
  18029. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  18030. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18031. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  18032. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  18033. if(yuarel_parse(&url, urlStr) != -1)
  18034. {
  18035. sprintf(OcppProtocol, "%s", url.scheme);
  18036. sprintf(OcppHost, "%s", url.host);
  18037. if(url.path == NULL)
  18038. OcppTempPath[0] = '\0';
  18039. else
  18040. sprintf(OcppTempPath, "%s", url.path);
  18041. if(url.port == 0)
  18042. {
  18043. if(strcmp(OcppProtocol, "wss") == 0)
  18044. OcppPort = 443;
  18045. else
  18046. OcppPort = 80;
  18047. }
  18048. else
  18049. OcppPort = url.port;
  18050. result = TRUE;
  18051. }
  18052. }
  18053. else
  18054. {
  18055. strcpy(OcppHost,"");
  18056. }
  18057. return result;
  18058. }
  18059. int GetOcppPath()
  18060. {
  18061. int result = FALSE;
  18062. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18063. {
  18064. if(OcppTempPath == NULL)
  18065. {
  18066. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18067. }
  18068. else
  18069. {
  18070. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18071. }
  18072. result = TRUE;
  18073. goto End;
  18074. }
  18075. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  18076. {
  18077. if(OcppTempPath == NULL)
  18078. {
  18079. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  18080. }
  18081. else
  18082. {
  18083. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  18084. }
  18085. result = TRUE;
  18086. goto End;
  18087. }
  18088. else
  18089. {
  18090. strcpy(OcppPath,"");
  18091. }
  18092. End:
  18093. return result;
  18094. }
  18095. int GetOcppPort()
  18096. {
  18097. return OcppPort;
  18098. }
  18099. int GetOcppConnStatus(void)
  18100. {
  18101. return ShmOCPP16Data->OcppConnStatus;
  18102. }
  18103. void SetOcppConnStatus(uint8_t status)
  18104. {
  18105. ShmOCPP16Data->OcppConnStatus = status;
  18106. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18107. }
  18108. int GetHeartBeatWithNOResponse(void)
  18109. {
  18110. return HeartBeatWithNOResponse;
  18111. }
  18112. void SetHeartBeatWithNOResponse(void)
  18113. {
  18114. HeartBeatWithNOResponse = 0;
  18115. }
  18116. void GetStartTransactionIdTag(int gun_index)
  18117. {
  18118. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  18119. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18120. }
  18121. int GetStartTransactionId(int gun_index)
  18122. {
  18123. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18124. }
  18125. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  18126. {
  18127. char ch;
  18128. FILE *fptr1;
  18129. int temptransactionId;
  18130. char str[100]={0};
  18131. temptransactionId = 0;
  18132. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  18133. {
  18134. DEBUG_INFO("IdTag is empty.\n");
  18135. return temptransactionId;
  18136. }
  18137. /*------ Read the file ----------------*/
  18138. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  18139. if (!fptr1)
  18140. {
  18141. DEBUG_INFO("QueueTransactionId file open error.\n");
  18142. //printf(" File not found or unable to open the input file!!\n");
  18143. return temptransactionId;
  18144. }
  18145. ch=fgetc(fptr1);
  18146. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  18147. rewind(fptr1);
  18148. if(ch!=EOF)
  18149. {
  18150. // printf("%c",ch);
  18151. while (fgets(str, 100, fptr1) != NULL)
  18152. {
  18153. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18154. if(str[0]=='\0')
  18155. {
  18156. break;
  18157. }
  18158. char *revbuf[8] = {0}; // Variable store string split
  18159. int num = 0;// Quantity after string split
  18160. DEBUG_INFO("Transaction queue data= %s\n", str);
  18161. splitstring(str,",",revbuf,&num); // String split
  18162. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  18163. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  18164. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  18165. DEBUG_INFO("------------------------------\n");
  18166. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  18167. {
  18168. if(isStopTransaction)
  18169. {
  18170. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  18171. {
  18172. temptransactionId = atoi(revbuf[2]);
  18173. //break;
  18174. }
  18175. }
  18176. else
  18177. {
  18178. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  18179. {
  18180. temptransactionId = atoi(revbuf[2]);
  18181. //break;
  18182. }
  18183. }
  18184. }
  18185. }
  18186. }
  18187. else
  18188. DEBUG_INFO("EOF\n");
  18189. fclose(fptr1);
  18190. /*------- End of reading ---------------*/
  18191. return temptransactionId;
  18192. }
  18193. void SetTransactionIdZero(int transactionId)
  18194. {
  18195. char ch;
  18196. FILE *fptr1, *fptr2;
  18197. int temptransactionId = 0;
  18198. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  18199. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  18200. if (!fptr1)
  18201. {
  18202. //printf(" File not found or unable to open the input file!!\n");
  18203. return ;
  18204. }
  18205. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  18206. if (!fptr2)
  18207. {
  18208. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  18209. fclose(fptr1);
  18210. return ;
  18211. }
  18212. ch=fgetc(fptr1);
  18213. rewind(fptr1);
  18214. if(ch!=EOF)
  18215. {
  18216. // copy all contents to the temporary file except the specific line
  18217. while (fgets(str, 100, fptr1) != NULL)
  18218. {
  18219. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18220. if(str[0]=='\0')
  18221. {
  18222. break;
  18223. }
  18224. char *revbuf[8] = {0};
  18225. int num = 0;
  18226. strcpy(strtemp, str);
  18227. splitstring(str,",",revbuf,&num);
  18228. if(revbuf[2][0] != '\0')
  18229. {
  18230. temptransactionId = atoi(revbuf[2]);
  18231. if(transactionId != temptransactionId)
  18232. {
  18233. fprintf(fptr2, "%s\n", strtemp);
  18234. }
  18235. }
  18236. }
  18237. }
  18238. fclose(fptr1);
  18239. fclose(fptr2);
  18240. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  18241. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  18242. /*------ Read the file ----------------*/
  18243. }
  18244. int InternetDisconnect(void)
  18245. {
  18246. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  18247. }
  18248. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18249. void storeTempStopTransaction(int gun_index)
  18250. {
  18251. char guid[37]={0};
  18252. int tempIndex = 0;
  18253. char TempStopTransaction[256];
  18254. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18255. DEBUG_INFO("storeTempStopTransaction...\n");
  18256. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  18257. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  18258. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  18259. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18260. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18261. {
  18262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18263. {
  18264. tempIndex = ((gun_index==2) ? 1: 0);
  18265. }
  18266. else
  18267. {
  18268. tempIndex = gun_index;
  18269. }
  18270. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18271. {
  18272. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18273. {
  18274. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  18275. }
  18276. }// END OF CHAdeMO_QUANTITY
  18277. }
  18278. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18279. {
  18280. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18281. {
  18282. tempIndex = ((gun_index==2) ? 1: 0);
  18283. }
  18284. else
  18285. {
  18286. tempIndex = gun_index;
  18287. }
  18288. for (int index = 0; index < CCS_QUANTITY; index++)
  18289. {
  18290. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18291. {
  18292. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  18293. }
  18294. }// END OF CCS_QUANTITY
  18295. }
  18296. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18297. {
  18298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18299. {
  18300. tempIndex = ((gun_index==2) ? 1: 0);
  18301. }
  18302. else
  18303. {
  18304. tempIndex = gun_index;
  18305. }
  18306. for (int index = 0; index < GB_QUANTITY; index++)
  18307. {
  18308. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18309. {
  18310. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18311. }
  18312. }// END OF GB_QUANTITY
  18313. }
  18314. else if(gunType[gun_index] == GUN_TYPE_DO)
  18315. {
  18316. tempIndex = gun_index;
  18317. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18318. {
  18319. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18320. {
  18321. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18322. }
  18323. }
  18324. }
  18325. else
  18326. {
  18327. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18328. {
  18329. tempIndex = 2;
  18330. }
  18331. else
  18332. {
  18333. tempIndex = gun_index;
  18334. }
  18335. for (int index = 0; index < AC_QUANTITY; index++)
  18336. {
  18337. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18338. {
  18339. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18340. }
  18341. }// END OF AC_QUANTITY
  18342. }
  18343. //Stop Transaction Time
  18344. struct timeval tmnow;
  18345. struct tm *tm;
  18346. char buf[28];//, usec_buf[6];
  18347. gettimeofday(&tmnow, NULL);
  18348. time_t t;
  18349. t = time(NULL);
  18350. /*UTC time and date*/
  18351. tm = gmtime(&t);
  18352. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18353. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  18354. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  18355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  18356. random_uuid(guid);
  18357. /***********************************transactionData******************************************************/
  18358. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18360. //=================================
  18361. //1. Transaction_Begin
  18362. //=================================
  18363. //============================== Energy.Active.Import.Interval ===========================================
  18364. //=================================
  18365. //2. Transaction_End
  18366. //=================================
  18367. //2.1====================================== Current.Import L1 ==============================================
  18368. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18369. {
  18370. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  18371. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18372. {
  18373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18374. {
  18375. tempIndex = ((gun_index==2) ? 1: 0);
  18376. }
  18377. else
  18378. {
  18379. tempIndex = gun_index;
  18380. }
  18381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18382. {
  18383. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18384. {
  18385. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18386. }
  18387. }// End of for CHAdeMO_QUANTITY
  18388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18389. }
  18390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18391. {
  18392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18393. {
  18394. tempIndex = ((gun_index==2) ? 1: 0);
  18395. }
  18396. else
  18397. {
  18398. tempIndex = gun_index;
  18399. }
  18400. for (int index = 0; index < CCS_QUANTITY; index++)
  18401. {
  18402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18403. {
  18404. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18405. }
  18406. }// End of for CCS_QUANTITY
  18407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18408. }
  18409. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18410. {
  18411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18412. {
  18413. tempIndex = ((gun_index==2) ? 1: 0);
  18414. }
  18415. else
  18416. {
  18417. tempIndex = gun_index;
  18418. }
  18419. for (int index = 0; index < GB_QUANTITY; index++)
  18420. {
  18421. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18422. {
  18423. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18424. }
  18425. }// End of for GB_QUANTITY
  18426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18427. }
  18428. else if(gunType[gun_index] == GUN_TYPE_DO)
  18429. {
  18430. tempIndex = gun_index;
  18431. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18432. {
  18433. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18434. {
  18435. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18436. }
  18437. }
  18438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18439. }
  18440. else
  18441. {
  18442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18443. {
  18444. tempIndex = 2;
  18445. }
  18446. else
  18447. {
  18448. tempIndex = gun_index;
  18449. }
  18450. for (int index = 0; index < AC_QUANTITY; index++)
  18451. {
  18452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18453. {
  18454. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18455. }
  18456. }// End of for AC_QUANTITY
  18457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18458. }
  18459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18462. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18465. }
  18466. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18467. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18468. {
  18469. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18470. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18471. {
  18472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18473. {
  18474. tempIndex = ((gun_index==2) ? 1: 0);
  18475. }
  18476. else
  18477. {
  18478. tempIndex = gun_index;
  18479. }
  18480. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18481. {
  18482. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18483. {
  18484. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18485. }
  18486. }// END OF CHAdeMO_QUANTITY
  18487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18488. }
  18489. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18490. {
  18491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18492. {
  18493. tempIndex = ((gun_index==2) ? 1: 0);
  18494. }
  18495. else
  18496. {
  18497. tempIndex = gun_index;
  18498. }
  18499. for (int index = 0; index < CCS_QUANTITY; index++)
  18500. {
  18501. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18502. {
  18503. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18504. }
  18505. }// END OF CCS_QUANTITY
  18506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18507. }
  18508. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18509. {
  18510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18511. {
  18512. tempIndex = ((gun_index==2) ? 1: 0);
  18513. }
  18514. else
  18515. {
  18516. tempIndex = gun_index;
  18517. }
  18518. for (int index = 0; index < GB_QUANTITY; index++)
  18519. {
  18520. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18521. {
  18522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18523. }
  18524. }// END OF GB_QUANTITY
  18525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18526. }
  18527. else if(gunType[gun_index] == GUN_TYPE_DO)
  18528. {
  18529. tempIndex = gun_index;
  18530. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18531. {
  18532. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18533. {
  18534. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18535. }
  18536. }
  18537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18538. }
  18539. else
  18540. {
  18541. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18542. {
  18543. tempIndex = 2;
  18544. }
  18545. else
  18546. {
  18547. tempIndex = gun_index;
  18548. }
  18549. for (int index = 0; index < AC_QUANTITY; index++)
  18550. {
  18551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18552. {
  18553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18554. }
  18555. }// END OF AC_QUANTITY
  18556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18557. }
  18558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18561. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18564. }
  18565. //2.3====================================== Power.Active.Import =========================================
  18566. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18567. {
  18568. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18569. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18570. {
  18571. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18572. {
  18573. tempIndex = ((gun_index==2) ? 1: 0);
  18574. }
  18575. else
  18576. {
  18577. tempIndex = gun_index;
  18578. }
  18579. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18580. {
  18581. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18582. {
  18583. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18584. }
  18585. } // End for CHAdeMO_QUANTITY
  18586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18587. }
  18588. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18589. {
  18590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18591. {
  18592. tempIndex = ((gun_index==2) ? 1: 0);
  18593. }
  18594. else
  18595. {
  18596. tempIndex = gun_index;
  18597. }
  18598. for (int index = 0; index < CCS_QUANTITY; index++)
  18599. {
  18600. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18601. {
  18602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18603. }
  18604. } // END for CCS_QUANTITY
  18605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18606. }
  18607. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18608. {
  18609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18610. {
  18611. tempIndex = ((gun_index==2) ? 1: 0);
  18612. }
  18613. else
  18614. {
  18615. tempIndex = gun_index;
  18616. }
  18617. for (int index = 0; index < GB_QUANTITY; index++)
  18618. {
  18619. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18620. {
  18621. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18622. }
  18623. }// END for GB_QUANTITY
  18624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18625. }
  18626. else if(gunType[gun_index] == GUN_TYPE_DO)
  18627. {
  18628. tempIndex = gun_index;
  18629. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18630. {
  18631. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18632. {
  18633. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18634. }
  18635. }
  18636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18637. }
  18638. else
  18639. {
  18640. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18641. {
  18642. tempIndex = 2;
  18643. }
  18644. else
  18645. {
  18646. tempIndex = gun_index;
  18647. }
  18648. for (int index = 0; index < AC_QUANTITY; index++)
  18649. {
  18650. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18651. {
  18652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18653. }
  18654. } // END for AC_QUANTITY
  18655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18656. }
  18657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18660. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18663. }
  18664. //2.4====================================== Voltage L1 ====================================================
  18665. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18666. {
  18667. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18668. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18669. {
  18670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18671. {
  18672. tempIndex = ((gun_index==2) ? 1: 0);
  18673. }
  18674. else
  18675. {
  18676. tempIndex = gun_index;
  18677. }
  18678. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18679. {
  18680. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18681. {
  18682. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18683. }
  18684. } // END OF FOR CHAdeMO_QUANTITY
  18685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18686. }
  18687. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18688. {
  18689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18690. {
  18691. tempIndex = ((gun_index==2) ? 1: 0);
  18692. }
  18693. else
  18694. {
  18695. tempIndex = gun_index;
  18696. }
  18697. for (int index = 0; index < CCS_QUANTITY; index++)
  18698. {
  18699. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18700. {
  18701. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18702. }
  18703. } // END OF FOR CCS_QUANTITY
  18704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18705. }
  18706. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18707. {
  18708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18709. {
  18710. tempIndex = ((gun_index==2) ? 1: 0);
  18711. }
  18712. else
  18713. {
  18714. tempIndex = gun_index;
  18715. }
  18716. for (int index = 0; index < GB_QUANTITY; index++)
  18717. {
  18718. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18719. {
  18720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18721. }
  18722. } // END OF FOR GB_QUANTITY
  18723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18724. }
  18725. else if(gunType[gun_index] == GUN_TYPE_DO)
  18726. {
  18727. tempIndex = gun_index;
  18728. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18729. {
  18730. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18731. {
  18732. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18733. }
  18734. }
  18735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18736. }
  18737. else
  18738. {
  18739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18740. {
  18741. tempIndex = 2;
  18742. }
  18743. else
  18744. {
  18745. tempIndex = gun_index;
  18746. }
  18747. for (int index = 0; index < AC_QUANTITY; index++)
  18748. {
  18749. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18750. {
  18751. 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
  18752. }
  18753. } // END OF FOR AC_QUANTITY
  18754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18755. }
  18756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18758. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18759. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18762. }
  18763. //2.5============================================== End SoC =========================================================
  18764. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18765. {
  18766. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18767. 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))
  18768. {
  18769. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18770. {
  18771. tempIndex = ((gun_index==2) ? 1: 0);
  18772. }
  18773. else
  18774. {
  18775. tempIndex = gun_index;
  18776. }
  18777. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18778. {
  18779. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18780. {
  18781. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18782. {
  18783. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18784. }
  18785. }
  18786. }
  18787. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18788. {
  18789. for (int index = 0; index < CCS_QUANTITY; index++)
  18790. {
  18791. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18792. {
  18793. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18794. }
  18795. }
  18796. }
  18797. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18798. {
  18799. for (int index = 0; index < GB_QUANTITY; index++)
  18800. {
  18801. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18802. {
  18803. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18804. }
  18805. }
  18806. }
  18807. else if(gunType[gun_index] == GUN_TYPE_DO)
  18808. {
  18809. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18810. {
  18811. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18812. {
  18813. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18814. }
  18815. }
  18816. }
  18817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18823. } // END FOR DC CASE
  18824. }
  18825. //2.6====================================== Current.Import L2 ==============================================
  18826. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18827. {
  18828. // AC 3 phase L2 current
  18829. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18830. {
  18831. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18832. {
  18833. tempIndex = 2;
  18834. }
  18835. else
  18836. {
  18837. tempIndex = gun_index;
  18838. }
  18839. for (int index = 0; index < AC_QUANTITY; index++)
  18840. {
  18841. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18842. {
  18843. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18844. }
  18845. }// End of for AC_QUANTITY
  18846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18847. }
  18848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18851. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18852. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18853. }
  18854. //2.7====================================== Current.Import L3 ==============================================
  18855. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18856. {
  18857. // AC 3 phase L3 current
  18858. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18859. {
  18860. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18861. {
  18862. tempIndex = 2;
  18863. }
  18864. else
  18865. {
  18866. tempIndex = gun_index;
  18867. }
  18868. for (int index = 0; index < AC_QUANTITY; index++)
  18869. {
  18870. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18871. {
  18872. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18873. }
  18874. }// End of for AC_QUANTITY
  18875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18876. }
  18877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18882. }
  18883. //2.9====================================== Voltage L2 ====================================================
  18884. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18885. {
  18886. // AC 3 phase L2 volatge
  18887. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18888. {
  18889. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18890. {
  18891. tempIndex = 2;
  18892. }
  18893. else
  18894. {
  18895. tempIndex = gun_index;
  18896. }
  18897. for (int index = 0; index < AC_QUANTITY; index++)
  18898. {
  18899. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18900. {
  18901. 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
  18902. }
  18903. } // END OF FOR AC_QUANTITY
  18904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18905. }
  18906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18907. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18908. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18911. }
  18912. //2.10====================================== Voltage L3 ====================================================
  18913. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18914. {
  18915. // AC 3 phase L3 volatge
  18916. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18917. {
  18918. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18919. {
  18920. tempIndex = 2;
  18921. }
  18922. else
  18923. {
  18924. tempIndex = gun_index;
  18925. }
  18926. for (int index = 0; index < AC_QUANTITY; index++)
  18927. {
  18928. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18929. {
  18930. 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
  18931. }
  18932. } // END OF FOR AC_QUANTITY
  18933. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18934. }
  18935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18940. }
  18941. //====================== Start SoC ================================
  18942. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18943. {
  18944. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18945. 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))
  18946. {
  18947. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18948. {
  18949. tempIndex = ((gun_index==2) ? 1: 0);
  18950. }
  18951. else
  18952. {
  18953. tempIndex = gun_index;
  18954. }
  18955. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18956. {
  18957. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18958. {
  18959. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18960. {
  18961. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18962. }
  18963. }
  18964. }
  18965. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18966. {
  18967. for (int index = 0; index < CCS_QUANTITY; index++)
  18968. {
  18969. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18970. {
  18971. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18972. }
  18973. }
  18974. }
  18975. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18976. {
  18977. for (int index = 0; index < GB_QUANTITY; index++)
  18978. {
  18979. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18980. {
  18981. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18982. }
  18983. }
  18984. }
  18985. else if(gunType[gun_index] == GUN_TYPE_DO)
  18986. {
  18987. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18988. {
  18989. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18990. {
  18991. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18992. }
  18993. }
  18994. }
  18995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18999. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  19000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  19001. } // END FOR DC CASE
  19002. }
  19003. //======================================== Message create ==============================================
  19004. json_object *StopTransaction = json_object_new_object();
  19005. json_object *transactionDatas = json_object_new_array();
  19006. json_object *sampledValues = json_object_new_array();
  19007. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19008. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19009. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19010. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19011. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19012. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19013. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  19014. {
  19015. json_object *transactionData = json_object_new_object();
  19016. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  19017. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  19018. {
  19019. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  19020. {
  19021. json_object *sampledValue = json_object_new_object();
  19022. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  19023. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  19024. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  19025. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  19026. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  19027. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  19028. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  19029. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  19030. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  19031. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  19032. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  19033. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  19034. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  19035. json_object_array_add(sampledValues, sampledValue);
  19036. }
  19037. }
  19038. json_object_object_add(transactionData, "sampledValue", sampledValues);
  19039. json_object_array_add(transactionDatas, transactionData);
  19040. }
  19041. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19042. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19043. ,MESSAGE_TYPE_CALL
  19044. ,guid
  19045. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19046. json_object_put(StopTransaction);
  19047. // Check File "TempStopTransaction" Exist
  19048. if((access(TempStopTransaction,F_OK))!=-1)
  19049. {
  19050. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19051. fclose(fopen(TempStopTransaction, "w"));
  19052. }
  19053. else
  19054. {
  19055. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19056. FILE *log = fopen(TempStopTransaction, "w+");
  19057. if(log == NULL)
  19058. {
  19059. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19060. return ;
  19061. }
  19062. else
  19063. {
  19064. fclose(log);
  19065. }
  19066. }
  19067. //Add TempStopTransaction | Update TempStopTransaction
  19068. // open file for writing
  19069. FILE *outfile;
  19070. outfile = fopen (TempStopTransaction, "a");
  19071. //DEBUG_INFO("data = %s\n", queuedata);
  19072. fputs(queuedata, outfile);
  19073. fputs("\n", outfile);
  19074. fclose (outfile);
  19075. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19076. OCPP_updatePeriodEnergy(gun_index);
  19077. }
  19078. void checkTempStopTransaction(int gun_index)
  19079. {
  19080. FILE *fptr1;
  19081. char ch;
  19082. char str[QUEUE_MESSAGE_LENGTH]={0};
  19083. char guid[37]={0};
  19084. char tempdata[65]={0};
  19085. char connectorStr[2]={0};
  19086. char TempStopTransaction[256];
  19087. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19088. fptr1 = fopen(TempStopTransaction, "r");
  19089. //TempStopTransaction格式: 槍號,StopTransaction封包
  19090. if (!fptr1)
  19091. {
  19092. //printf(" File not found or unable to open the input file!!\n");
  19093. return ;
  19094. }
  19095. ch=fgetc(fptr1);
  19096. //printf(" Now the content of the file %s is : \n",fname);
  19097. rewind(fptr1);
  19098. if(ch!=EOF)
  19099. {
  19100. // copy all contents to the temporary file except the specific line
  19101. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19102. {
  19103. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19104. if(str[0]=='\0')
  19105. {
  19106. break;
  19107. }
  19108. //TempStopTransaction格式: 槍號,StopTransaction封包
  19109. strncpy(connectorStr, str, 1);
  19110. if(atoi(connectorStr) != (gun_index+1))
  19111. {
  19112. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19113. fclose(fptr1);
  19114. return ;
  19115. }
  19116. //random_uuid(guid);
  19117. strncpy(guid, str+6, 36); //copy guid
  19118. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19119. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19120. {
  19121. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19122. }
  19123. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19124. OCPP_insert_transaction_msg(NO, str);
  19125. memset(str,0,ARRAY_SIZE(str));
  19126. }
  19127. }
  19128. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19129. fclose(fptr1);
  19130. remove(TempStopTransaction); // remove the original file
  19131. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19132. }
  19133. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19134. {
  19135. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19136. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19137. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19138. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19139. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19140. }
  19141. int GetWebSocketPingInterval(void)
  19142. {
  19143. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19144. }
  19145. int GetServerSign(void)
  19146. {
  19147. return server_sign;
  19148. }
  19149. uint8_t GetOcppSecurityProfile()
  19150. {
  19151. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19152. }
  19153. void GetOcppChargerBoxId(uint8_t *data)
  19154. {
  19155. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19156. }
  19157. void GetOcppSecurityPassword(uint8_t *data)
  19158. {
  19159. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19160. }
  19161. void SetOcppVersion(uint8_t *version)
  19162. {
  19163. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19164. DEBUG_INFO("ocpp version: %s\n", version);
  19165. if(strstr((char*)version, "ocpp1.6") != NULL)
  19166. {
  19167. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19168. }
  19169. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19170. {
  19171. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19172. system("pkill OcppBackend");
  19173. }
  19174. }
  19175. void SetServerSign(int value)
  19176. {
  19177. server_sign = value;
  19178. }
  19179. int GetBootNotificationInterval(void)
  19180. {
  19181. return BootNotificationInterval;
  19182. }
  19183. int GetInternetConn(void)
  19184. {
  19185. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19186. }
  19187. int GetBackendConnectionTimeout(void)
  19188. {
  19189. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19190. }
  19191. int isConnectorInitMode(int gun_index)
  19192. {
  19193. int tempIndex = 0;
  19194. int result = TRUE;
  19195. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19196. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19197. {
  19198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19199. {
  19200. tempIndex = ((gun_index==2) ? 1: 0);
  19201. }
  19202. else
  19203. {
  19204. tempIndex = gun_index;
  19205. }
  19206. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19207. {
  19208. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19209. {
  19210. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19211. } //end of the same index
  19212. }//end of for CHAdeMO_QUANTITY
  19213. }
  19214. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19215. {
  19216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19217. {
  19218. tempIndex = ((gun_index==2) ? 1: 0);
  19219. }
  19220. else
  19221. {
  19222. tempIndex = gun_index;
  19223. }
  19224. for (int index = 0; index < CCS_QUANTITY; index++)
  19225. {
  19226. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19227. {
  19228. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19229. } //end of the same index
  19230. } // end of for CCS_QUANTITY
  19231. }
  19232. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19233. {
  19234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19235. {
  19236. tempIndex = ((gun_index==2) ? 1: 0);
  19237. }
  19238. else
  19239. {
  19240. tempIndex = gun_index;
  19241. }
  19242. for (int index = 0; index < GB_QUANTITY; index++)
  19243. {
  19244. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19245. {
  19246. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19247. } //end of the same index
  19248. } // end of for GB_QUANTITY
  19249. }
  19250. else if(gunType[gun_index] == GUN_TYPE_DO)
  19251. {
  19252. tempIndex = gun_index;
  19253. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19254. {
  19255. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19256. {
  19257. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19258. } //end of the same index
  19259. }
  19260. }
  19261. else
  19262. {
  19263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19264. {
  19265. tempIndex = 2;
  19266. }
  19267. else
  19268. {
  19269. tempIndex = gun_index;
  19270. }
  19271. for (int index = 0; index < AC_QUANTITY; index++)
  19272. {
  19273. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19274. {
  19275. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19276. }//end of the same index
  19277. }//end of for AC_QUANTITY
  19278. }
  19279. return result;
  19280. }
  19281. void refreshProcDogTimer()
  19282. {
  19283. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  19284. }
  19285. void InitialSystemValue(void)
  19286. {
  19287. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  19288. locallistVersion=0;
  19289. BootNotificationInterval = 0;
  19290. authorizeRetryTimes = 0;
  19291. GunStatusInterval = 10;
  19292. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  19293. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19294. //Hear Beat
  19295. HeartBeatWithNOResponse = 0;
  19296. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  19297. FirstHeartBeat = 0;
  19298. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19299. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19300. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19301. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19302. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19303. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19304. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19305. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19306. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19307. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19308. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19309. //Status && ConnectorPlugIn Setting
  19310. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19311. {
  19312. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19313. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19314. }
  19315. for (int index = 0; index < CCS_QUANTITY; index++)
  19316. {
  19317. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19318. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19319. }
  19320. for (int index = 0; index < GB_QUANTITY; index++)
  19321. {
  19322. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19323. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19324. }
  19325. for (int index = 0; index < AC_QUANTITY; index++)
  19326. {
  19327. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19328. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19329. }
  19330. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19331. {
  19332. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19333. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19334. }
  19335. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19336. {
  19337. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19338. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19339. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19340. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19341. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19342. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  19343. }
  19344. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19345. refreshStartTimer(&clientTime.Heartbeat);
  19346. sleep(1);
  19347. }
  19348. void LWS_Send(char *str)
  19349. {
  19350. //=====================================================
  19351. // Check InternetConn 0: disconnected, 1: connected
  19352. //====================================================
  19353. if(GetOcppConnStatus() == 0)
  19354. {
  19355. DEBUG_INFO("offline now !!!\n");
  19356. return;
  19357. }
  19358. // Only disable isWebsocketSendable operation initiated by charger
  19359. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19360. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19361. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19362. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19363. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19364. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19365. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19366. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19367. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19368. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19369. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19370. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19371. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19372. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19373. {
  19374. isWebsocketSendable = 0;
  19375. }
  19376. pthread_mutex_lock(&lock_send);
  19377. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19378. sprintf((char *)SendBuffer, "%s", str);
  19379. SendBufLen = strlen(str);
  19380. pthread_mutex_unlock(&lock_send);
  19381. lws_callback_on_writable(wsi_client);
  19382. //lws_service(context, 0);
  19383. //sleep(1);
  19384. }
  19385. void LWS_SendNow(char *str)
  19386. {
  19387. //=====================================================
  19388. // Check InternetConn 0: disconnected, 1: connected
  19389. //====================================================
  19390. if(GetOcppConnStatus() == 0)
  19391. {
  19392. DEBUG_INFO("offline now !!!\n");
  19393. return;
  19394. }
  19395. // Only disable isWebsocketSendable operation initiated by charger
  19396. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19397. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19398. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19399. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19400. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19401. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19402. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19403. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19404. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19405. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19406. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19407. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19408. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19409. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19410. {
  19411. isWebsocketSendable = 0;
  19412. }
  19413. pthread_mutex_lock(&lock_send);
  19414. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19415. sprintf((char *)SendBuffer, "%s", str);
  19416. SendBufLen = strlen(str);
  19417. pthread_mutex_unlock(&lock_send);
  19418. lws_callback_on_writable(wsi_client);
  19419. lws_service(context, 0);
  19420. //sleep(1);
  19421. }